#include <bits/stdc++.h>
using namespace std;
long long dp[300005][15];
long long a[300005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  memset(dp, -0x3f3f3f3f, sizeof(dp));
  long long ans = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j < m; ++j) {
      if (j == 0)
        dp[i][j] = max(dp[i - 1][m - 1] + a[i] - k, a[i] - k);
      else
        dp[i][j] = dp[i - 1][j - 1] + a[i];
      ans = max(ans, dp[i][j]);
    }
  cout << ans << endl;
  return 0;
}
