#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma optimize("O3")
using namespace std;
int N = 1234567891, M = 31;
long long i, j, l, r, n, m, t, k, f, ma = 0, y3, mi = 2e9, y, x, z, x2, y2,
                                     a[500000], dp[500000], pr[500000];
long long ans;
long long b[400000];
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m >> k;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = (a[i] * m - k) + b[i - 1];
    a[i] += a[i - 1];
  }
  for (i = 0; i < m; i++) {
    long long mi = b[i];
    x = i;
    pr[i] = x;
    for (j = i + m; j <= n; j += m) {
      if (mi > b[j]) mi = b[j], x = j;
      pr[j] = x;
    }
  }
  for (i = 0; i < m; i++) {
    for (j = i; j <= n; j++) {
      ans = max(ans, a[j] - a[pr[j - i]] -
                         k * ((j - pr[j - i]) / m + 1ll -
                              ((j - pr[j - i]) % m == 0)));
    }
  }
  cout << ans;
}
