#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 5, mod = 1e8, inf = 1e9 + 5;
long double pi = acos(-1);
long long n, m, k, dp[N][15], a[N];
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  long long maxans = 0;
  for (int i = 0; i <= m; i++) {
    dp[0][i] = -1e12;
  }
  for (int i = 1; i <= n; i++) {
    long long ans = 0;
    for (int j = 1; j <= m; j++) {
      if (j == 1) {
        dp[i][j] = max(a[i] - k, dp[i - 1][m] + a[i] - k);
      } else
        dp[i][j] = dp[i - 1][j - 1] + a[i];
      maxans = max(maxans, dp[i][j]);
    }
  }
  cout << maxans;
  return 0;
}
