#include <bits/stdc++.h>
using namespace std;
int a[322222];
long long f[322222][11];
int get_mod(int x, int m) {
  return (x >= 0) ? (x % m) : ((m - abs(x) % m) % m);
}
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    for (int j = 0; j < m; j++) f[i][j] = f[0][j] = -(long long)(1e17);
  }
  long long res = 0;
  if (m != 1) {
    f[1][1] = a[1] - k;
    res = max(f[1][1], res);
  } else {
    f[1][0] = a[1] - k;
    res = max(f[1][0], res);
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < m; j++) {
      int prev_mod = get_mod(j - 1, m);
      int tmp = 0;
      if (prev_mod == 0) tmp = 1;
      if (f[i - 1][prev_mod] != -(long long)(1e17))
        f[i][j] = max(f[i - 1][prev_mod] + a[i] - k * tmp, f[i][j]);
      if (m == 1 && j == 0) f[i][j] = max((long long)a[i] - k, f[i][j]);
      if (m != 1 && j == 1) f[i][j] = max(f[i][j], (long long)a[i] - k);
      res = max(res, f[i][j]);
    }
  }
  cout << res << endl;
  return 0;
}
