#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 9;
long long a[maxn];
long long dp[maxn][11];
int main() {
  long long n, m, k;
  while (scanf("%lld%lld%lld", &n, &m, &k) != EOF) {
    for (int i = 1; i <= n; i++) {
      scanf("%lld", &a[i]);
    }
    memset(dp, -0x3f3f3f3f3f3f3f3f, sizeof(dp));
    long long ans = -0x3f3f3f3f3f3f3f3f;
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j < m; j++) {
        if (j == 0) {
          dp[i][j] = max(dp[i - 1][m - 1] + a[i] - k, a[i] - k);
        } else {
          dp[i][j] = dp[i - 1][j - 1] + a[i];
        }
        ans = max(ans, dp[i][j]);
      }
    }
    if (ans <= 0)
      printf("0\n");
    else
      printf("%lld\n", ans);
  }
  return 0;
}
