#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int n, m, k;
int a[N];
long long solve(int L, int R) {
  long long res = 0LL;
  if (L == R) return max(res, (long long)a[L] - k);
  int mid = (L + R) / 2;
  res = max(res, solve(L, mid));
  res = max(res, solve(mid + 1, R));
  long long l[m], r[m];
  for (int i = 0; i < m; i++) l[i] = r[i] = 0;
  long long sum = 0LL;
  for (int i = mid; i >= L; i--) {
    sum += a[i];
    int len = (mid - i + 1) % m;
    if (len == 0) sum -= k;
    l[len] = max(l[len], sum);
  }
  sum = 0LL;
  for (int i = mid + 1; i <= R; i++) {
    sum += a[i];
    int len = (i - mid) % m;
    if (len == 0) sum -= k;
    r[len] = max(r[len], sum);
  }
  for (int i = 0; i < m; i++)
    for (int j = 0; j < m; j++) {
      long long curr = 0LL;
      curr += l[i];
      curr += r[j];
      if (i + j > 0) curr -= k;
      if (i + j > m) curr -= k;
      res = max(res, curr);
    }
  return res;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  cout << solve(1, n) << endl;
  return 0;
}
