#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
long long a[N];
long long dp[N][20];
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  a[0] = 0;
  for (int i = 1; i <= m; i++) dp[0][i] = -1e10;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    for (int j = 1; j <= m; j++) {
      if (j == 1)
        dp[i][j] = max(a[i] - k, dp[i - 1][m] + a[i] - k);
      else
        dp[i][j] = dp[i - 1][j - 1] + a[i];
      ans = max(ans, dp[i][j]);
    }
  }
  printf("%I64d\n", ans);
  return 0;
}
