#include <bits/stdc++.h>
using namespace std;
const int maxn = 300000 + 10;
long long num[maxn], dp[maxn][15];
void Solve() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n; i++) scanf("%lld", &num[i]);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (j == 1)
        dp[i][j] = max(dp[i - 1][m] + num[i] - k, num[i] - k);
      else {
        if (i < j) break;
        dp[i][j] = dp[i - 1][j - 1] + num[i];
      }
      ans = max(ans, dp[i][j]);
    }
  }
  printf("%lld\n", ans);
}
int main() {
  Solve();
  return 0;
}
