#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int s = 0, t = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') t = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
  return s * t;
}
const int N = 20005;
int n, m, K, a[N], s[N], f[51][N];
int tr[N << 2], d[N << 2];
void Pushup(int x) { tr[x] = max(tr[x << 1], tr[x << 1 | 1]); }
void Init(int x, int v) { tr[x] += v, d[x] += v; }
void Pushdown(int x) {
  if (!d[x]) return;
  Init(x << 1, d[x]), Init(x << 1 | 1, d[x]), d[x] = 0;
}
void Build(int x, int l, int r, int k) {
  d[x] = 0;
  if (l == r) {
    tr[x] = f[k][l];
    return;
  }
  int mid = (l + r) >> 1;
  Build(x << 1, l, mid, k), Build(x << 1 | 1, mid + 1, r, k), Pushup(x);
}
void Upd(int x, int l, int r, int ql, int qr, int v) {
  if (ql <= l && r <= qr) {
    Init(x, v);
    return;
  }
  int mid = (l + r) >> 1;
  Pushdown(x);
  if (ql <= mid) Upd(x << 1, l, mid, ql, qr, v);
  if (qr > mid) Upd(x << 1 | 1, mid + 1, r, ql, qr, v);
  Pushup(x);
}
void Upd(int i, int v) { Upd(1, 1, m, max(1, i - K + 1), i, v); }
int main() {
  n = read(), m = read(), K = read();
  for (int i = 1; i <= m; i++) s[i] = s[i - 1] + (a[i] = read());
  for (int i = 1; i <= m; i++) f[1][i] = s[min(m, i + K - 1)] - s[i - 1];
  for (int k = 2; k <= n; k++) {
    Build(1, 1, m, k - 1);
    for (int i = 1; i <= m; i++) s[i] = s[i - 1] + (a[i] = read());
    for (int i = K + 1; i <= m; i++) Upd(i, a[i]);
    for (int i = 1; i <= m; i++) {
      f[k][i] = tr[1] + s[min(m, i + K - 1)] - s[i - 1];
      Upd(i, a[i]);
      if (i + K <= m) Upd(i + K, -a[i + K]);
    }
  }
  Build(1, 1, m, n), printf("%d", tr[1]);
  return 0;
}
