#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
const int INF = 1 << 30;
int a[MAXN];
long long dp[MAXN], sum[MAXN];
int n, m, k;
long long read() {
  long long s = 1, x = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') s = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = 10 * x + ch - '0';
    ch = getchar();
  }
  return x * s;
}
int main() {
  n = read();
  m = read();
  k = read();
  long long ans = -INF;
  for (int i = 1; i <= n; ++i) a[i] = read(), sum[i] = sum[i - 1] + a[i];
  for (int i = 1; i <= n; ++i) {
    for (int j = max(i - m + 1, 1); j <= i; ++j)
      dp[i] = max(dp[i], sum[i] - sum[j - 1] - k);
    if (i >= m) dp[i] = max(dp[i], dp[i - m] + sum[i] - sum[i - m] - k);
    ans = dp[i] > ans ? dp[i] : ans;
  }
  cout << ans << endl;
  return 0;
}
