#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 228;
const long long big = 1e18;
long long a[N], pr[N], tex[N];
int n, m, k;
long long ans = 0ll;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= (int)n; i++) cin >> a[i];
  pr[0] = 0;
  for (int i = 1; i <= (int)n; i++) pr[i] = pr[i - 1] + a[i];
  for (int i = 0; i < (int)m; i++) tex[i] = -big;
  tex[0] = -k;
  for (int i = 1; i <= (int)n; i++) {
    tex[i % m] = max(tex[i % m], -pr[i]);
    for (int j = 0; j < (int)m; j++)
      if (tex[j] != -big) ans = max(ans, pr[i] + tex[j]);
    tex[i % m] -= 0ll + k;
  }
  cout << ans;
  return 0;
}
