#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const int maxm = 15;
const long long INF = 1e18;
int n, m, k;
int a[maxn];
long long dp[maxn][maxm];
void ReadInput() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
}
void Solve() {
  fill_n(&dp[0][0], sizeof(dp) / sizeof(dp[0][0]), -INF);
  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((long long)a[i] - k, dp[i - 1][m] + a[i] - k);
      else
        dp[i][j] = dp[i - 1][j - 1] + a[i];
    }
  long long ans = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) ans = max(ans, dp[i][j]);
  cout << ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ReadInput();
  Solve();
}
