#include <bits/stdc++.h>
using namespace std;
long long Sum[300010], Add[10];
long long K, Ans = 0LL;
int N, M;
int main() {
  memset(Add, 0x3f, sizeof(Add));
  scanf("%d%d%I64d", &N, &M, &K);
  for (register int i = 1; i <= N; ++i) {
    scanf("%I64d", &Sum[i]);
    Sum[i] += Sum[i - 1];
  }
  for (register int i = 1; i <= N; ++i) Sum[i] -= (long long)(i / M) * K;
  Add[0] = 0;
  for (register int i = 1; i <= N; ++i) {
    Add[i % M] = min(Add[i % M], Sum[i]);
    for (register int j = 0; j < M; ++j) {
      long long Mul = ((long long)i % M - (long long)j) / M;
      if (Mul * M < ((long long)i % M - (long long)j)) ++Mul;
      Ans = max(Ans, Sum[i] - Add[j] - K * Mul);
    }
  }
  printf("%I64d\n", Ans);
  return 0;
}
