#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 100;
long long a[MAXN];
long long pre[MAXN];
long long dp[MAXN][20];
int main() {
  int n, m, k;
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    pre[i] = pre[i - 1] + a[i];
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (j <= i) {
        dp[i][j] =
            max(pre[i] - pre[i - j], pre[i] - pre[i - j] + dp[i - j][m]) - k;
      }
      ans = max(dp[i][j], ans);
    }
  }
  cout << ans << endl;
  return 0;
}
