#include <bits/stdc++.h>
using namespace std;
const int maxn = 300005;
long long s[maxn], f[maxn];
int n, m, k;
int a[maxn];
void Solve() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    s[i] = s[i - 1] + 1ll * a[i];
  }
  long long res = 0;
  for (int i = 1; i <= min(m - 1, n); ++i) res = max(res, s[i] - k);
  for (int i = 1; i <= n; ++i) {
    if (i >= m) f[i] = max(0ll, f[i - m] + s[i] - s[i - m] - k);
    for (int j = 0; j < m && i + j <= n; ++j)
      res = max(res, f[i] + s[i + j] - s[i] - (j > 0) * k);
  }
  cout << res;
}
int main() { Solve(); }
