#include <bits/stdc++.h>
using namespace std;
long long n, m, k, arr[3 * 100005];
long long dp[3 * 100005][12][3];
long long solve(int idx, int cnt, int state, long long sum) {
  if (idx >= n) return 0;
  if (dp[idx][cnt][state] != -1) return dp[idx][cnt][state];
  long long fi = 0, se = 0;
  if (state == 0) {
    fi = solve(idx + 1, (cnt + 1) % m, 1, sum + arr[idx] - (cnt == 0) * k) +
         arr[idx] - (cnt == 0) * k;
    se = solve(idx + 1, 0, 0, 0);
  } else {
    fi = solve(idx + 1, (cnt + 1) % m, 1, sum + arr[idx] - (cnt == 0) * k) +
         arr[idx] - (cnt == 0) * k;
  }
  return dp[idx][cnt][state] = max(fi, se);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  cin >> n >> m >> k;
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < n; i++) cin >> arr[i];
  cout << solve(0, 0, 0, 0);
  return 0;
}
