#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
mt19937 rnd(time(nullptr));
vector<long long> inputs;
long long k;
long long get_suff(long long begin, long long end) {
  long long maxx = 0;
  long long now = 0;
  for (long long i = end - 1; i >= begin; --i) {
    now += inputs[i];
    maxx = max(now, maxx);
  }
  return max(maxx - k, 0LL);
}
long long get_preff(long long begin, long long end) {
  long long maxx = 0;
  long long now = 0;
  for (long long i = begin; i < end; ++i) {
    now += inputs[i];
    maxx = max(now, maxx);
  }
  return max(maxx - k, 0LL);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long n, temp_m;
  cin >> n >> temp_m >> k;
  long long m = temp_m;
  inputs.resize(n);
  for (long long i = 0; i < n; ++i) {
    cin >> inputs[i];
  }
  if (m >= n) {
    long long max_ans = 0;
    for (long long beg = 0; beg < n; ++beg) {
      for (long long end = beg; end < n; ++end) {
        long long now = 0;
        for (long long i = beg; i <= end; ++i) {
          now += inputs[i];
        }
        now -= k * ((end - beg) / m + 1);
        max_ans = max(max_ans, now);
      }
    }
    cout << max_ans;
    return 0;
  }
  vector<vector<long long>> keks(m);
  vector<vector<pair<long long, long long>>> from_and_to(m);
  keks[0].assign((n + m - 1) / m, -k);
  from_and_to[0].resize((n + m - 1) / m);
  for (long long i = 0; i < n; ++i) {
    keks[0][i / m] += inputs[i];
  }
  for (long long i = 0; i < from_and_to[0].size(); ++i) {
    from_and_to[0][i] = {get_preff(i * m, min((i + 1) * m, n)),
                         get_suff(i * m, min((i + 1) * m, n))};
  }
  for (long long shift = 1; shift < m; ++shift) {
    keks[shift].assign(((shift != 0) + (n - shift + m - 1) / m), -k);
    from_and_to[shift].resize((shift != 0) + (n - shift + m - 1) / m);
    for (long long i = 0; i < shift; ++i) {
      keks[shift][0] += inputs[i];
    }
    from_and_to[shift][0] = {get_preff(0, shift), get_suff(0, shift)};
    for (long long i = shift; i < n; ++i) {
      keks[shift][(i - shift) / m + 1] += inputs[i];
    }
    for (long long i = 1; i < from_and_to[shift].size(); ++i) {
      from_and_to[shift][i] = {
          get_preff((i - 1) * m + shift, min((i)*m + shift, n)),
          get_suff((i - 1) * m + shift, min((i)*m + shift, n))};
    }
  }
  long long max_ans = 0;
  for (long long shift = 0; shift < m; ++shift) {
    long long now_val = from_and_to[shift][0].second;
    max_ans = max(max_ans, now_val);
    for (long long i = 1; i < keks[shift].size(); ++i) {
      if (now_val + keks[shift][i] < 0) {
        now_val += from_and_to[shift][i].first;
        max_ans = max(max_ans, now_val);
        now_val = from_and_to[shift][i].second;
      } else {
        max_ans = max(max_ans, now_val + from_and_to[shift][i].first);
        now_val += keks[shift][i];
        max_ans = max(max_ans, now_val);
      }
    }
    max_ans = max(max_ans, now_val);
  }
  cout << max_ans;
}
