#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(0);
  long long n, m, k;
  cin >> n >> m >> k;
  vector<long long> v(n);
  vector<long long> dp(n);
  for (long long i = 0; i < n; i++) {
    cin >> v[i];
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    dp[i] = 0;
    long long sum = 0;
    for (int j = i; j >= 0 && i - j + 1 <= m; j--) {
      sum += v[j];
      dp[i] = max(dp[i], sum - k);
      if (j) {
        dp[i] = max(dp[j - 1] + sum - k, dp[i]);
      }
    }
    ans = max(ans, dp[i]);
  }
  cout << ans << '\n';
  return 0;
}
