#include <bits/stdc++.h>
using namespace std;
template <class t>
inline t read(t &x) {
  char c = getchar();
  bool f = 0;
  x = 0;
  while (!isdigit(c)) f |= c == '-', c = getchar();
  while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  if (f) x = -x;
  return x;
}
template <class t, class... A>
inline void read(t &x, A &...a) {
  read(x);
  read(a...);
}
template <class t>
inline void write(t x) {
  if (x < 0)
    putchar('-'), write(-x);
  else {
    if (x > 9) write(x / 10);
    putchar('0' + x % 10);
  }
}
const long long N = 3e5 + 500;
long long n, m, k, a[N], ans;
signed main() {
  read(n, m, k);
  for (long long i = 1; i <= n; i++) read(a[i]);
  while (n % m) n++;
  for (long long l = 1; l <= m; l++) {
    for (long long i = l, pre = 0; i <= n; i += m) {
      long long sum = 0, ma = 0;
      for (long long j = 0; j < m; j++) ma = max(ma, sum = sum + a[j + i]);
      ma -= k;
      sum -= k;
      ans = max(ans, pre + ma);
      pre = max(0ll, pre + sum);
    }
  }
  write(ans);
}
