#include <bits/stdc++.h>
using namespace std;
long long n, m, k, a[300005], ans;
vector<long long> v[10];
long long f(long long i) {
  long long sum = 0, ret = 0, sez = v[i].size();
  for (int j = 0; j < sez; j++) {
    if (j % (m + 1) == 0)
      sum = max(v[i][j], sum + v[i][j]);
    else
      sum += v[i][j];
    ret = max(ret, sum);
  }
  return ret;
}
int main() {
  ans = 0;
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) {
    for (int j = i; j < n; j++) {
      if (j % m == i) v[i].push_back(-k);
      v[i].push_back(a[j]);
    }
  }
  for (int i = 0; i < m; i++) {
    ans = max(ans, f(i));
  }
  cout << ans << "\n";
}
