#include <bits/stdc++.h>
using namespace std;
inline long long fpow(long long n, long long k, int p = 998244353) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
inline long long inv(long long a, long long p = 998244353) {
  return fpow(a, p - 2, p);
}
inline long long addmod(long long a, long long val, long long p = 998244353) {
  {
    if ((a = (a + val)) >= p) a -= p;
  }
  return a;
}
inline long long submod(long long a, long long val, long long p = 998244353) {
  {
    if ((a = (a - val)) < 0) a += p;
  }
  return a;
}
inline long long mult(long long a, long long b, long long p = 998244353) {
  return (long long)a * b % p;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m, k;
  cin >> n >> m >> k;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<long long> lstm(n, 0), lstmmax(n, 0);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long ctr = 1;
    long long sum = a[i], mxsum = a[i];
    while (ctr < m && i - ctr >= 0) {
      sum += a[i - ctr];
      mxsum = max(mxsum, sum);
      ctr++;
    }
    lstm[i] = sum;
    lstmmax[i] = mxsum;
  }
  vector<long long> dp(n);
  for (int i = 0; i < min(n, m); i++) {
    dp[i] = lstmmax[i] - k;
    ans = max(ans, dp[i]);
  }
  for (int i = m; i < n; i++) {
    dp[i] = lstmmax[i] - k;
    dp[i] = max(dp[i], dp[i - m] - k + lstm[i]);
    ans = max(ans, dp[i]);
  }
  cout << ans << "\n";
}
