#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int MX = 1e6 + 5;
int a[MX];
long long dp[MX][11];
int main() {
  long long n, m, k;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  long long ans = 0;
  dp[0][0] = 0;
  for (long long i = 1; i <= n; i++) {
    for (int j = 2; j <= min(i, m); j++) {
      dp[i][j] = dp[i - 1][j - 1] + (long long)a[i];
      ans = max(ans, dp[i][j]);
    }
    dp[i][1] = dp[i - 1][0] + (long long)a[i] - k;
    dp[i][1] = max(dp[i - 1][m] + (long long)a[i] - k, dp[i][1]);
    ans = max(ans, dp[i][1]);
  }
  cout << ans;
  return 0;
}
