#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  int64_t K;
  cin >> N >> M >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  int64_t ret = 0;
  for (int m = 0; m < M; m++) {
    vector<int64_t> B(N);
    for (int i = 0; i < N; i++) {
      B[i] = A[i];
      if (i % M == m) B[i] -= K;
    }
    if (!(m < N)) continue;
    int64_t x = B[m];
    int64_t best = x;
    for (int i = m + 1; i < N; i++) {
      if (i % M == m && x < 0)
        x = B[i];
      else
        x += B[i];
      best = max(x, best);
    }
    ret = max(best, ret);
  }
  cout << ret << endl;
  return 0;
}
