#include <bits/stdc++.h>
using namespace std;
const int mxm = 12;
long long dp[mxm];
void solve() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  long long s = 0, ans = 0;
  for (int rem = 1; rem < m; ++rem) dp[rem] = (long long)1e15;
  for (int i = 1, x, q, r; i <= n; ++i) {
    scanf("%d", &x);
    q = i / m, r = i % m, s += x;
    for (int rem = 0; rem < m; ++rem)
      ans = max(ans, s - 1LL * q * k - dp[rem] - (r > rem) * k);
    dp[r] = min(dp[r], s - 1LL * q * k);
  }
  printf("%lld\n", ans);
}
int main() {
  int tc = 1;
  while (tc--) solve();
}
