#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
long long n, m, k;
long long a[N], dp[N];
int main() {
  while (~scanf("%lld%lld%lld", &n, &m, &k)) {
    for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), dp[i] = 0LL;
    long long ans = 0LL;
    for (int i = n; i >= 1; i--) {
      long long sum = 0LL;
      for (int j = i; j <= min(i + m - 1, n); j++) {
        sum += a[j];
        dp[i] = max(dp[i], sum - k);
      }
      dp[i] = max(dp[i], dp[min(i + m, n + 1)] + sum - k);
      ans = max(ans, dp[i]);
    }
    printf("%lld\n", ans);
  }
  return 0;
}
