#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const int maxn = 3e5 + 10;
const int maxm = 4.1e7 + 10;
const int mod = 1e7 + 7;
inline void read(int &x) {
  x = 0;
  char c;
  for (c = getchar(); c > '9' || c < '0'; c = getchar())
    ;
  for (; c >= '0' && c <= '9'; c = getchar())
    x = (x << 3) + (x << 1) + (c ^ 48);
}
int a[maxn];
long long dp[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  long long k, ans = 0;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    dp[i] = 0;
    long long tmp = 0;
    for (int j = 0; j < m && j < i; j++) {
      tmp += a[i - j];
      dp[i] = max(dp[i], tmp + max(0LL, dp[i - j - 1]) - k);
    }
    ans = max(ans, dp[i]);
  }
  cout << ans;
  return 0;
}
