#include <bits/stdc++.h>
int main() {
  static long long dp[10], dq[10];
  int n, m, k, h, a;
  long long ans;
  scanf("%d%d%d", &n, &m, &k);
  dp[0] = 0;
  for (h = 1; h < m; h++) dp[h] = -0x3f3f3f3f3f3f3f3fLL;
  ans = 0;
  while (n--) {
    scanf("%d", &a);
    for (h = 0; h < m; h++)
      dq[(h + 1) % m] = dp[h] != -0x3f3f3f3f3f3f3f3fLL
                            ? dp[h] + a - (h == 0 ? k : 0)
                            : -0x3f3f3f3f3f3f3f3fLL;
    if (dq[0] < 0) dq[0] = 0;
    for (h = 0; h < m; h++)
      if (ans < (dp[h] = dq[h])) ans = dp[h];
  }
  printf("%lld\n", ans);
  return 0;
}
