#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e18, M = 1e9 + 7;
const long long int N = 1;
void solve() {
  long long int n, m, k;
  cin >> n >> m >> k;
  vector<long long int> v(n);
  for (long long int i = 0; i < n; ++i) cin >> v[i];
  vector<long long int> dp(n);
  long long int sum = 0, ans = 0;
  for (long long int i = 0; i < n; ++i) {
    dp[i] = v[i] - k;
    sum = v[i];
    for (long long int j = i - 1; j >= 0 && i - j <= m; --j) {
      dp[i] = max(dp[i], dp[j] + sum - k);
      sum += v[j];
    }
    if (i < m) dp[i] = max(dp[i], sum - k);
    dp[i] = max(dp[i], 0ll);
    ans = max(ans, dp[i]);
  }
  cout << ans;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
