#include <bits/stdc++.h>
using namespace std;
int a[300300];
long long s[300300];
long long mx[11];
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];
  for (int i = 1; i <= n; i++) s[i] -= (long long)k * (i / m);
  for (int i = 0; i < m; i++) mx[i] = -(1LL << 62);
  long long ans = 0;
  for (int i = n; i >= 1; i--) {
    mx[i % m] = max(mx[i % m], s[i]);
    for (int j = 0; j < m; j++) {
      if ((i + j) / m != (i - 1) / m)
        ans = max(ans, mx[(i + j) % m] - s[i - 1]);
      else
        ans = max(ans, mx[(i + j) % m] - s[i - 1] - k);
    }
  }
  cout << ans << endl;
  return 0;
}
