#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
long long dp[maxn][12];
long long a[maxn];
int main() {
  long long n, m, k;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= 10; ++j) dp[i][j] = -1e18;
  dp[0][m - 1] = 0;
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= m - 1; ++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]);
    }
  }
  printf("%lld\n", ans);
  return 0;
}
