#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5;
int N, M;
long long K, arr[MAXN + 10], psum[MAXN + 10], ans;
long long sum(int l, int r) { return psum[r] - psum[l - 1]; }
int main() {
  int i, j;
  scanf("%d%d%lld", &N, &M, &K);
  for (i = 1; i <= N; i++) scanf("%lld", &arr[i]);
  for (i = 1; i <= N; i++) psum[i] = psum[i - 1] + arr[i];
  for (i = 1; i <= min(M, N); i++) {
    int nxt = i;
    long long val = 0;
    for (j = 1; j <= N; j++) {
      val = max(val, sum(j, nxt) - K);
      ans = max(ans, val);
      if (j == nxt) {
        val += sum(nxt + 1, nxt + M) - K;
        nxt += M;
      }
      if (nxt > N) break;
    }
  }
  printf("%lld", ans);
}
