#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
const int mod = (int)1e9 + 7;
const int MAXN = (int)3e5 + 5;
long long n, m, k;
long long arr[MAXN];
long long dp[MAXN][11];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n >> m >> k;
  for (long long i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  long long ans = 0;
  dp[0][m] = -k;
  for (long long i = 1; i <= n; i++) {
    if (dp[i - 1][m] > 0) {
      dp[i][1] += dp[i - 1][m];
    }
    dp[i][1] += arr[i] - k;
    ans = max(ans, dp[i][1]);
    for (long long j = 2; j <= min(m, i); j++) {
      dp[i][j] = dp[i - 1][j - 1] + arr[i];
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << '\n';
}
