#include <bits/stdc++.h>
using namespace std;
bool prime[100005];
void sieve() {
  memset(prime, true, sizeof(prime));
  for (long long p = 2; p * p < 100005; p++) {
    if (prime[p] == true) {
      for (long long i = p * p; i < 100005; i += p) prime[i] = false;
    }
  }
}
long long powmod(long long x, long long y, long long mod) {
  long long res = 1;
  x = x % mod;
  while (y > 0) {
    if (y & 1) {
      res = (res * x) % mod;
    }
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res;
}
signed main() {
  long long n, m, k;
  cin >> n >> m >> k;
  long long dp[n], a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    dp[i] = a[i] - k;
    long long sum = a[i];
    for (long long j = i - 1; j >= 0 && (i - j) <= m; j--) {
      dp[i] = max(dp[i], dp[j] - k + sum);
      sum += a[j];
    }
    if (i < m) {
      dp[i] = max(dp[i], sum - k);
    }
    dp[i] = max(dp[i], 0LL);
    ans = max(dp[i], ans);
  }
  cout << ans << endl;
  return 0;
}
