#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  long long m, k;
  scanf("%d%lld%lld", &n, &m, &k);
  long long a[n], asum[n + 1];
  asum[0] = 0;
  for (int((i)) = (0); ((i)) < ((n)); ++((i))) {
    scanf("%lld", &a[i]);
    asum[i + 1] = asum[i] + a[i];
  }
  long long dp[m];
  for (int((i)) = (0); ((i)) < ((m)); ++((i))) dp[i] = 1e18;
  long long ans = 0;
  for (int((i)) = (0); ((i)) < ((n)); ++((i))) {
    dp[i % m] = min(dp[i % m] + k, asum[i] + k);
    for (int((j)) = (0); ((j)) < ((m)); ++((j)))
      ans = max(ans, asum[i + 1] - dp[j]);
  }
  printf("%lld\n", ans);
}
