#include <bits/stdc++.h>
using namespace std;
namespace io {
const int l = 1 << 20;
char buf[l], *s, *t, c;
inline void gc() {
  if (s == t) {
    t = (s = buf) + fread(buf, 1, l, stdin);
    c = s == t ? EOF : *s++;
  } else
    c = *s++;
}
template <class IT>
inline void gi(IT &x) {
  x = 0;
  gc();
  while (c < '0' || c > '9') gc();
  while ('0' <= c && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    gc();
  }
}
char buf0[20];
int a;
template <class IT>
inline void pi(IT x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  do buf0[++a] = x % 10 + 48;
  while (x /= 10);
  while (a) putchar(buf0[a--]);
  putchar('\n');
}
};  // namespace io
using io::gi;
using io::pi;
template <class IT>
inline void cmax(IT &a, IT b) {
  if (a < b) a = b;
}
template <class IT>
inline void cmin(IT &a, IT b) {
  if (b < a) a = b;
}
const int N = 55, M = 20005;
int ss[N][M], s[M], d[M], pre[M], suc[M], tm1[M], tm2[M], q[M];
int main() {
  int n, m, b, k, i, j, S, t, l, r;
  scanf("%d%d%d", &n, &m, &k);
  b = m - k + 1;
  for (j = (1); j <= (n); ++j) {
    S = 0;
    for (i = (1); i <= (m); ++i) {
      scanf("%d", &t);
      ss[j][i] = (S += t);
    }
  }
  for (i = (1); i <= (m); ++i) s[i] = ss[1][i];
  for (i = (1); i <= (b); ++i) d[i] = s[i + k - 1] - s[i - 1];
  for (j = (2); j <= (n); ++j) {
    for (i = (1); i <= (m); ++i) s[i] = ss[j][i];
    for (i = (1); i <= (b); ++i) d[i] = d[i] - s[i - 1] + s[i + k - 1];
    for (i = (1); i <= (b); ++i) tm1[i] = d[i] + s[i - 1];
    for (i = (1); i <= (b); ++i) tm2[i] = d[i] - s[i + k - 1];
    for (i = (1); i <= (b); ++i) pre[i] = max(d[i], pre[i - 1]);
    for (i = (b); i >= (1); --i) suc[i] = max(d[i], suc[i + 1]);
    for (i = (1); i <= (b); ++i) d[i] = suc[i + k];
    for (i = (k + 1); i <= (b); ++i) cmax(d[i], pre[i - k]);
    l = 1;
    r = 0;
    for (i = (b); i >= (1); --i) {
      if (l <= r && q[l] == i + k) ++l;
      while (l <= r && tm1[q[r]] < tm1[i]) --r;
      q[++r] = i;
      cmax(d[i], tm1[q[l]] - s[i + k - 1]);
    }
    l = 1;
    r = 0;
    for (i = (1); i <= (b); ++i) {
      if (l <= r && q[l] == i - k) ++l;
      if (l <= r) cmax(d[i], tm2[q[l]] + s[i - 1]);
      while (l <= r && tm2[q[r]] < tm2[i]) --r;
      q[++r] = i;
    }
    for (i = (1); i <= (b); ++i) d[i] = d[i] - s[i - 1] + s[i + k - 1];
  }
  S = 0;
  for (i = (1); i <= (b); ++i) cmax(S, d[i]);
  printf("%d", S);
  return 0;
}
