#include <bits/stdc++.h>
using namespace std;
char buf[1 << 21], *p1 = buf, *p2 = buf;
template <typename T>
inline void read(T &x) {
  static char ch;
  bool f = 1;
  for (x = 0,
      ch = (p1 == p2 &&
                    (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
                ? EOF
                : *p1++);
       !isdigit(ch);
       ch = (p1 == p2 &&
                     (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
                 ? EOF
                 : *p1++))
    if (ch == '-') f = 0;
  for (; isdigit(ch);
       x = (x << 1) + (x << 3) + (ch ^ 48),
       ch = (p1 == p2 &&
                     (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
                 ? EOF
                 : *p1++))
    ;
  x = f ? x : -x;
}
template <typename T>
void print(T x) {
  if (x < 0) x = -x, putchar('-');
  if (x > 9) print(x / 10);
  putchar(x % 10 + 48);
}
template <typename T>
inline void print(T x, char ap) {
  print(x);
  if (ap) putchar(ap);
}
template <typename T>
inline void chkmax(T &x, const T &y) {
  x = x < y ? y : x;
}
template <typename T>
inline void chkmin(T &x, const T &y) {
  x = x < y ? x : y;
}
int n, m, k, a[20001], ad[80001], dat[80001], f[20001], s[20001];
void build(int q, int l, int r) {
  ad[q] = 0;
  if (l == r) return (void)(dat[q] = f[l]);
  int mid = l + r >> 1;
  build(q << 1, l, mid), build(q << 1 | 1, mid + 1, r),
      dat[q] = max(dat[q << 1], dat[q << 1 | 1]);
}
inline void spread(int q, int l, int r, int mid) {
  if (ad[q]) {
    ad[q << 1] += ad[q], ad[q << 1 | 1] += ad[q];
    dat[q << 1] += ad[q], dat[q << 1 | 1] += ad[q];
    ad[q] = 0;
  }
}
void change(int q, int l1, int r1, int l, int r, int k) {
  if (l <= l1 && r1 <= r) return (void)(dat[q] += k, ad[q] += k);
  int mid = l1 + r1 >> 1;
  spread(q, l1, r1, mid);
  if (l <= mid) change(q << 1, l1, mid, l, r, k);
  if (r > mid) change(q << 1 | 1, mid + 1, r1, l, r, k);
  dat[q] = max(dat[q << 1], dat[q << 1 | 1]);
}
int main() {
  read(n), read(m), read(k);
  for (register int i = 1; i <= n; ++i) {
    for (register int j = 1; j <= m; ++j) read(a[j]), s[j] = s[j - 1] + a[j];
    for (register int j = 1; j <= m - k + 1; ++j)
      change(1, 1, m - k + 1, j, j, s[j + k - 1] - s[j - 1]);
    for (register int j = 1; j <= k; ++j)
      change(1, 1, m - k + 1, max(j - k + 1, 1), min(j, m - k + 1), -a[j]);
    for (register int j = 1; j <= m - k + 1; ++j)
      f[j] = s[j + k - 1] - s[j - 1] + (i > 1 ? dat[1] : 0),
      change(1, 1, m - k + 1, max(j - k + 1, 1), min(j, m - k + 1), a[j]),
      change(1, 1, m - k + 1, max(j + k - k + 1, 1), min(j + k, m - k + 1),
             -a[j + k]);
    build(1, 1, m - k + 1);
  }
  print(dat[1], '\n');
  return 0;
}
