#include <bits/stdc++.h>
using namespace std;
long long read() {
  char ch = getchar();
  long long x = 0, ff = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') ff = -ff;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * ff;
}
void write(long long aa) {
  if (aa < 0) putchar('-'), aa = -aa;
  if (aa > 9) write(aa / 10);
  putchar(aa % 10 + '0');
  return;
}
long long n, m, K;
long long a[55][20005], A[55][20005];
long long tt[1000005], lz[1000005], f[55][20005];
long long calc(long long aa, long long cc, long long dd) {
  if (aa == n) return a[n][dd] - a[n][cc - 1];
  return a[aa][dd] - a[aa][cc - 1] + a[aa + 1][dd] - a[aa + 1][cc - 1];
}
void bt(long long rt, long long ll, long long rr, long long kk) {
  lz[rt] = 0;
  if (ll == rr) {
    tt[rt] = f[kk][ll];
    return;
  }
  long long mid = (ll + rr) >> 1;
  bt(rt << 1, ll, mid, kk);
  bt(rt << 1 | 1, mid + 1, rr, kk);
  tt[rt] = max(tt[rt << 1], tt[rt << 1 | 1]);
  return;
}
void push(long long rt) {
  if (!lz[rt]) return;
  lz[rt << 1] += lz[rt];
  lz[rt << 1 | 1] += lz[rt];
  tt[rt << 1] += lz[rt];
  tt[rt << 1 | 1] += lz[rt];
  lz[rt] = 0;
  return;
}
void add(long long rt, long long ll, long long rr, long long L, long long R,
         long long kk) {
  if (rt == 1 && L < ll) L = ll;
  if (rt == 1 && R > rr) R = rr;
  if (L > R) return;
  if (ll == L && rr == R) {
    lz[rt] += kk;
    tt[rt] += kk;
    return;
  }
  long long mid = (ll + rr) >> 1;
  push(rt);
  if (R <= mid)
    add(rt << 1, ll, mid, L, R, kk);
  else if (L > mid)
    add(rt << 1 | 1, mid + 1, rr, L, R, kk);
  else
    add(rt << 1, ll, mid, L, mid, kk),
        add(rt << 1 | 1, mid + 1, rr, mid + 1, R, kk);
  tt[rt] = max(tt[rt << 1], tt[rt << 1 | 1]);
  return;
}
int main() {
  n = read(), m = read(), K = read();
  for (long long i = 1; i <= n; ++i)
    for (long long j = 1; j <= m; ++j)
      A[i][j] = read(), a[i][j] = A[i][j] + a[i][j - 1];
  for (long long i = 1; i <= n; ++i) {
    if (i > 1) bt(1, K, m, i - 1);
    if (i > 1)
      for (long long j = 1; j < K; ++j) add(1, K, m, j, j + K - 1, -A[i][j]);
    for (long long j = K; j <= m; ++j) {
      if (i > 1) add(1, K, m, j - K, j - 1, A[i][j - K]);
      if (i > 1) add(1, K, m, j, j + K - 1, -A[i][j]);
      f[i][j] = tt[1] + calc(i, j - K + 1, j);
    }
  }
  long long ans = 0;
  for (long long j = K; j <= m; ++j) ans = max(ans, f[n][j]);
  write(ans);
  return 0;
}
