#include <bits/stdc++.h>
using namespace std;
static char buf[256000001];
void* operator new(size_t s) {
  static size_t i = sizeof buf;
  assert(s < i);
  return (void*)&buf[i -= s];
}
void operator delete(void*) {}
template <class T>
struct ptr {
  unsigned ind;
  ptr(T* p = 0) : ind(p ? unsigned((char*)p - buf) : 0) {
    assert(ind < sizeof buf);
  }
  T& operator*() const { return *(T*)(buf + ind); }
  T* operator->() const { return &**this; }
  T& operator[](long long a) const { return (&**this)[a]; }
  explicit operator bool() const { return ind; }
};
const long long inf = 1e18;
struct Node {
  ptr<Node> l = 0, r = 0;
  int lo, hi, madd = 0;
  long long mset = -inf;
  long long val = inf;
  Node(int lo, int hi) : lo(lo), hi(hi) {}
  Node(vector<long long>& v, int lo, int hi) : lo(lo), hi(hi) {
    if (lo + 1 < hi) {
      int mid = lo + (hi - lo) / 2;
      l = new Node(v, lo, mid);
      r = new Node(v, mid, hi);
      val = min(l->val, r->val);
    } else
      val = v[lo];
  }
  long long query(int L, int R) {
    if (R <= lo || hi <= L) return inf;
    if (L <= lo && hi <= R) return val;
    push();
    return min(l->query(L, R), r->query(L, R));
  }
  void set(int L, int R, long long x) {
    if (R <= lo || hi <= L) return;
    if (L <= lo && hi <= R)
      mset = val = x, madd = 0;
    else {
      push(), l->set(L, R, x), r->set(L, R, x);
      val = min(l->val, r->val);
    }
  }
  void add(int L, int R, long long x) {
    if (R <= lo || hi <= L) return;
    if (L <= lo && hi <= R) {
      if (mset != -inf)
        mset += x;
      else
        madd += x;
      val += x;
    } else {
      push(), l->add(L, R, x), r->add(L, R, x);
      val = min(l->val, r->val);
    }
  }
  void push() {
    if (!l) {
      long long mid = lo + (hi - lo) / 2;
      l = new Node(lo, mid);
      r = new Node(mid, hi);
    }
    if (mset != -inf)
      l->set(lo, hi, mset), r->set(lo, hi, mset), mset = -inf;
    else if (madd)
      l->add(lo, hi, madd), r->add(lo, hi, madd), madd = 0;
  }
};
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin.exceptions(cin.failbit);
  int n, m, k;
  cin >> n >> m >> k;
  vector<long long> a(n + 1);
  for (long long i = (1); i < (n + 1); ++i) cin >> a[i];
  for (long long i = (1); i < (n + 1); ++i) a[i] += a[i - 1];
  long long ans = 0;
  for (int rem = 0; rem < m; ++rem) {
    ptr<Node> tr = new Node(a, 0, (long long)(a).size());
    for (long long pos = rem + 1; pos <= n; pos += m) {
      long long bst = tr->query(pos, pos + 1) - tr->query(0, pos);
      ans = max(ans, bst);
      tr->add(0, pos, k);
    }
  }
  cout << max(0LL, ans - k) << endl;
}
