#include <bits/stdc++.h>
using namespace std;
const int nsz = 3e5, msz = 10;
long long inf = 0x3f3f3f3f3f3f3f3f;
int n, m;
long long k, a[nsz + 5], pre[nsz + 5], del[msz + 5], ans;
int inline at(int id) { return (id - 1 + m) % m + 1; }
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  fill(del, del + sizeof(del) / sizeof(long long), inf);
  for (int i = 1; i <= n; ++i) {
    pre[i] = pre[i - 1] + a[i];
    del[at(i - 1)] = min(del[at(i - 1)], pre[i - 1]) + k;
    for (int j = 1; j <= m; ++j) {
      ans = max(ans, pre[i] - del[j]);
    }
  }
  cout << ans << '\n';
}
