#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  long long int max_ans = 0;
  for (int i = 0; i < m; ++i) {
    long long int ans = 0;
    int prev_ind = i - 1;
    if (prev_ind < 0) {
      prev_ind += m;
    }
    for (int j = i; j < n; ++j) {
      ans += a[j];
      if (j % m == i) {
        ans -= k;
      }
      max_ans = max(max_ans, ans);
      if (j % m == prev_ind) {
        ans = max(ans, (long long int)0);
      }
    }
  }
  cout << max_ans << "\n";
  return 0;
}
