import java.io.*; import java.util.*; public class Main { static int m; static long[] sums; static long[][] dp; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int k = sc.nextInt(); m = sc.nextInt(); sums = new long[n + 1]; for (int i = 1; i <= n; i++) { sums[i] = sums[i - 1] + sc.nextInt(); } dp = new long[n + 1][k + 1]; for (long[] arr : dp) { Arrays.fill(arr, Long.MAX_VALUE); } System.out.println(dfw(n, k)); } static long dfw(int idx, int group) { if (idx == 0 && group == 0) { return 0; } if (idx < group) { return Long.MIN_VALUE; } if (idx > group * m) { return Long.MIN_VALUE; } if (dp[idx][group] == Long.MAX_VALUE) { long max = 0; for (int i = idx - 1; i >= 0 && idx - i <= m; i--) { max = Math.max(max, dfw(i, group - 1) + Math.abs(sums[idx] - sums[i])); } dp[idx][group] = max; } return dp[idx][group]; } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }