#include <bits/stdc++.h>
using namespace std;
long long n, m, k, a[300005], ans;
int main() {
  ans = 0;
  cin >> n >> m >> k;
  vector<vector<long long> > dp(n + 1, vector<long long>(11, -1e12));
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i <= n; i++) dp[i][10] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (j == 1)
        dp[i][j] = max(a[i - 1], dp[i - 1][m] + a[i - 1]) - k;
      else
        dp[i][j] = dp[i - 1][j - 1] + a[i - 1];
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << "\n";
}
