#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
const int maxn = 300003, INF = 1e9 + 1;
int n, m, k, a[maxn];
ll res = 0, dp[maxn][11];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m >> k;
  for (int i = (1); i <= (n); ++i) cin >> a[i];
  for (int i = (0); i <= (n); ++i)
    for (int j = (0); j <= (10); ++j) dp[i][j] = -INF;
  for (int i = (0); i <= (n); ++i) dp[i][10] = 0;
  for (int i = (1); i <= (n); ++i) {
    dp[i][1] = max(1ll * a[i], dp[i - 1][m] + a[i]) - k;
    for (int j = (2); j <= (m); ++j) dp[i][j] = dp[i - 1][j - 1] + a[i];
    for (int j = (1); j <= (m); ++j) res = max(res, dp[i][j]);
  }
  cout << res;
}
