#include <bits/stdc++.h>
using namespace std;
long long n, m, k, a[300105], q[300105], sum[300105], suM[300105];
int main() {
  cin >> n >> m >> k;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
  }
  for (long long i = n + 1; i <= n + m - 1; i++) {
    sum[i] = sum[i - 1];
  }
  for (long long i = m + 1; i <= n; i++) {
    suM[i] = max(suM[i - m] + sum[i - 1] - sum[i - m - 1] - k, (long long)0);
  }
  long long h = 1, t = 1;
  long long ans = 0;
  for (long long i = 1; i <= n + m - 1; i++) {
    while (h <= t && i - q[h] > m) h++;
    while (h <= t && sum[i] > sum[q[t]]) t--;
    q[++t] = i;
    if (i > m)
      ans = max(ans, (long long)sum[q[h]] - sum[i - m] - k + suM[i - m + 1]);
    else
      ans = max(ans, (long long)sum[q[h]] - k);
  }
  cout << ans;
  return 0;
}
