#include <bits/stdc++.h>
long long dp[300005][15];
using namespace std;
int main(void) {
  long long n, m, k;
  vector<long long> v(300005);
  scanf("%lld %lld %lld", &n, &m, &k);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &v[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= m; j++) {
      dp[i][j] = -100000000000;
    }
  }
  dp[0][1] = v[0] - k;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j <= m; j++) {
      if (j == 1) {
        dp[i][j] = dp[i - 1][m] + v[i] - k;
        if (v[i] - k > dp[i][j]) dp[i][j] = v[i] - k;
      } else {
        dp[i][j] = dp[i - 1][j - 1] + v[i];
      }
    }
  }
  long long maxi = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= m; j++) {
      if (dp[i][j] > maxi) maxi = dp[i][j];
    }
  }
  printf("%lld\n", maxi);
  return 0;
}
