#include <bits/stdc++.h>
using namespace std;
long long a[300005];
long long f[300005];
int n, m, k;
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
    a[i] += a[i - 1];
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j >= 1 && j >= i - m + 1; j--) {
      f[i] = max(a[i] - a[j - 1] - k, f[i]);
    }
    if (i - m > 0) {
      f[i] = max(a[i] - a[i - m] + f[i - m] - k, f[i]);
    }
    ans = max(ans, f[i]);
  }
  printf("%I64d\n", ans);
  return 0;
}
