#include <bits/stdc++.h>
using namespace std;
const int N = int(3e5) + 99;
int n, m, k;
int a[N];
long long sum(int l, int r, vector<long long>& psum) {
  l = max(l, 0);
  return psum[r] - (l == 0 ? 0 : psum[l - 1]);
}
int main() {
  cin >> n >> m >> k;
  vector<long long> psum(n);
  vector<long long> bst(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    psum[i] = a[i] + (i == 0 ? 0 : psum[i - 1]);
  }
  long long res = 0;
  for (int len = 1; len <= m && len <= n; ++len)
    res = max(res, sum(0, len - 1, psum) - k);
  for (int i = 0; i < n; ++i) {
    if (i + 1 >= m) {
      long long nbst = sum(i - m + 1, i, psum) - k;
      if (i - m >= 0) nbst += bst[i - m];
      bst[i] = max(bst[i], nbst);
    }
    for (int len = 0; len <= m && i + len < n; ++len)
      res = max(res, bst[i] + sum(i + 1, i + len, psum) - k * (len > 0));
  }
  cout << res << endl;
  return 0;
}
