#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MAXN = 3e5 + 100;
ll v[MAXN];
ll dp[MAXN];
ll n, k, m;
int main() {
  cin >> n >> m >> k;
  for (ll i = 0; i < n; i++) {
    cin >> v[i];
  }
  ll rs = 0;
  for (ll i = 0; i < n; i++) {
    ll sm = 0;
    for (ll j = 0; j < m && i + j < n; j++) {
      sm += v[i + j];
      rs = max(dp[i] + sm - k, rs);
    }
    dp[i + m] = dp[i] + sm - k;
    if (dp[i + m] < 0) dp[i + m] = 0;
  }
  cout << rs << '\n';
  return 0;
}
