#include <bits/stdc++.h>
using namespace std;
using ll = long long;
long long constexpr N = 300009;
long long n, m, k, a[N];
long long retsum(vector<long long>& b) {
  long long mx = -(numeric_limits<long long>::max() / 100);
  long long sum = 0;
  for (long long i = 0; i < b.size(); ++i) {
    sum += b[i];
    mx = max(mx, sum);
    if (sum < 0) sum = 0;
  }
  return mx - k;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> k;
  for (long long i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  long long ans = 0;
  for (long long s = 0; s < m; ++s) {
    vector<long long> b;
    for (long long i = 1; i <= n; ++i) {
      if (i % m == s) b.push_back(-k);
      b.push_back(a[i]);
    }
    ans = max(ans, retsum(b));
  }
  cout << ans << '\n';
}
