#include <bits/stdc++.h>
using namespace std;
void fileio() {}
vector<vector<long long int>> g;
long long int n, m, k;
vector<long long int> dp, a;
long long int solve(long long int i) {
  if (i < 0) return 0;
  long long int &res = dp[i];
  if (res != -1) return res;
  long long int sum = a[i] - k;
  res = max(sum + solve(i - 1), (long long int)0);
  for (long long int j = 1; j < m; j++) {
    if (i - j < 0) break;
    sum += a[i - j];
    res = max(res, sum + solve(i - j - 1));
  }
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  fileio();
  cin >> n >> m >> k;
  dp = vector<long long int>(n + 1, -1);
  a = vector<long long int>(n, 0);
  for (long long int i = 0; i < n; i++) cin >> a[i];
  long long int ans = 0;
  for (long long int i = n - 1; i >= 0; i--) ans = max(ans, solve(i));
  cout << ans;
  cout << '\n';
  return 0;
}
