#include <bits/stdc++.h>
using namespace std;
const long long N = 5e5 + 10;
long long n, m, k, a[N];
long long pre[N];
struct mmin {
  long long n = 1e18, cnt = 0;
  void init(long long ns) { n = ns, cnt = 0; }
  void next() {
    cnt++;
    cnt %= m;
    if (cnt == 0) n += k;
  }
} mn[1000];
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m >> k;
  n++;
  a[0] = 0;
  for (long long i = 2; i <= n; i++) cin >> a[i];
  long long ans = 0;
  for (long long i = 1; i <= n; i++) pre[i] = pre[i - 1] + a[i];
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j <= m - 1; j++) ans = max(ans, pre[i] - mn[j].n);
    for (long long j = m; j >= 1; j--) {
      mn[j - 1].next();
      mn[j] = mn[j - 1];
    }
    mn[0].init(min(mn[m].n, pre[i] + k));
  }
  cout << ans << endl;
}
