#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
template <class T, class U>
inline void checkmin(T &x, U y) {
  if (y < x) x = y;
}
template <class T, class U>
inline void checkmax(T &x, U y) {
  if (y > x) x = y;
}
template <class T, class U>
inline bool ifmin(T &x, U y) {
  if (y < x) return x = y, true;
  return false;
}
template <class T, class U>
inline bool ifmax(T &x, U y) {
  if (y > x) return x = y, true;
  return false;
}
template <class T>
inline void sort(T &a) {
  sort(a.begin(), a.end());
}
template <class T>
inline void rsort(T &a) {
  sort(a.rbegin(), a.rend());
}
template <class T>
inline void reverse(T &a) {
  reverse(a.begin(), a.end());
}
template <class T, class U>
inline istream &operator>>(istream &str, pair<T, U> &p) {
  return str >> p.first >> p.second;
}
template <class T>
inline istream &operator>>(istream &str, vector<T> &a) {
  for (auto &i : a) str >> i;
  return str;
}
void read(int &x) {
  static char c;
  c = getchar();
  if (c == '-') {
    x = 0;
    while (c = getchar(), c >= '0') x = (x << 3) + (x << 1) + (c - '0');
    x = -x;
  } else {
    x = c - '0';
    while (c = getchar(), c >= '0') x = (x << 3) + (x << 1) + (c - '0');
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m, k;
  read(n);
  read(m), read(k);
  checkmin(m, n);
  vector<long long> mn(m, 3000000000000000007ll);
  long long sum = 0, ans = 0;
  mn[m - 1] = 0;
  for (int i = 0; i < n; i += m) {
    sum -= k;
    for (int i = m - 2; i >= 0; --i) checkmin(mn[i], mn[i + 1]);
    long long curr = 3000000000000000007ll;
    for (int j = i, t = 0; j < n && t < m; ++j, ++t) {
      int a;
      read(a);
      sum += a;
      checkmax(ans, sum - min(curr + k, mn[t]));
      checkmin(mn[t], sum);
      checkmin(curr, mn[t]);
    }
  }
  printf("%I64d", ans);
  return 0;
}
