#include <bits/stdc++.h>
using namespace std;
const int Max_K = 15;
const int Max_N = 300005;
long long N, M, K, A[Max_N], cur[Max_K], ans[Max_K];
int main() {
  scanf("%lld%lld%lld", &N, &M, &K);
  for (int i = 0; i < N; i++) scanf("%lld", &A[i]);
  for (int j = 1; j < M; j++) cur[j] = -K;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) cur[j] += A[i];
    cur[i % M] -= K;
    cur[i % M] = max(cur[i % M], A[i] - K);
    for (int j = 0; j < M; j++) ans[j] = max(ans[j], cur[j]);
  }
  for (int j = 1; j < M; j++) ans[j] = max(ans[j], ans[j - 1]);
  printf("%lld\n", ans[M - 1]);
  return 0;
}
