#include <bits/stdc++.h>
using namespace std;
const int M = 3 * 100010;
long long int a[M];
long long int dp[M][12];
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  memset(dp, 0, sizeof(dp));
  for (int j = 0; j < 12; j++) dp[0][j] = -1e18;
  dp[0][m - 1] = 0;
  long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < m; j++) {
      if (j == 0)
        dp[i][j] = max(a[i - 1] - k, dp[i - 1][m - 1] + a[i - 1] - k);
      else
        dp[i][j] = dp[i - 1][j - 1] + a[i - 1];
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
