#include <bits/stdc++.h>
using namespace std;
long long n, m, k, arr[300030], res = 0, f[20];
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < 20; i++) f[i] = 0;
  f[0] = -k;
  for (int i = 1; i <= n; i++) {
    arr[i] += arr[i - 1];
    for (int j = 0; j < m; j++) {
      if (j >= i % m) {
        res = max(res, arr[i] - f[j] - k * (i / m + 1));
      } else {
        res = max(res, arr[i] - f[j] - k * (i / m + 2));
      }
    }
    f[i % m] = min(f[i % m], arr[i] - k * (i / m + 1));
  }
  cout << res << endl;
  return 0;
}
