#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
const long long inf = 1e18;
int n, m;
long long k;
long long a[N];
long long sum[N];
long long cal(int l, int r) {
  long long tmp = r - l + 1;
  if (tmp % m != 0)
    tmp = tmp / m + 1;
  else
    tmp = tmp / m;
  return k * tmp;
}
long long solve(int l, int r) {
  if (l == r) return a[l] - k;
  int mid = (l + r) >> 1;
  long long ans1 = solve(l, mid);
  long long ans2 = solve(mid + 1, r);
  long long ans = max(ans1, ans2);
  long long p[11];
  for (int i = 0; i < m; i++) {
    p[i] = -inf;
    int pp = mid - i;
    long long tmp = 0;
    while (pp >= l && pp >= 1) {
      tmp += k;
      p[i] = max(p[i], sum[mid] - sum[pp - 1] - tmp);
      pp -= m;
    }
  }
  long long an = -inf;
  for (int i = mid + 1; i <= r; i++) {
    long long tmp = cal(mid + 1, i);
    long long sm = sum[i] - sum[mid];
    for (int j = 0; j < m; j++) {
      int len = (i - mid - 1) % m + 1;
      long long po = tmp;
      if (len + j < m) po -= k;
      an = max(an, p[j] + sm - po);
    }
  }
  ans = max(ans, an);
  return ans;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
  }
  long long ans = solve(1, n);
  ans = max(0LL, ans);
  cout << ans << endl;
  return 0;
}
