#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f *= -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = (x << 1) + (x << 3) + s - '0';
    s = getchar();
  }
  return x * f;
}
int n = read(), m = read(), k = read(), p;
long long a[55][20005], dp[55][20005], f[20005 * 3], lazy[20005 * 3], ans;
inline void change(int l, int r, long long d) {
  for (l = p + l - 1, r = p + r + 1; (l ^ 1) != r;) {
    if ((l & 1) ^ 1) lazy[l ^ 1] += d, f[l ^ 1] += d;
    if (r & 1) lazy[r ^ 1] += d, f[r ^ 1] += d;
    l >>= 1, r >>= 1;
    f[l] = max(f[l << 1], f[l << 1 | 1]) + lazy[l];
    f[r] = max(f[r << 1], f[r << 1 | 1]) + lazy[r];
  }
  for (; l > 0 && r > 0; l >>= 1, r >>= 1)
    f[l] = max(f[l << 1], f[l << 1 | 1]) + lazy[l],
    f[r] = max(f[r << 1], f[r << 1 | 1]) + lazy[r];
}
int main() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) a[i][j] = read() + a[i][j - 1];
  memset(dp, -0x7f7f7f7f, sizeof(dp));
  for (int i = 1; i <= m - k + 1; i++) dp[0][i] = 0;
  for (p = 1; p <= m - k + 2; p <<= 1)
    ;
  for (int i = 1; i <= m - k + 1; i++) {
    dp[1][i] = max(dp[1][i], a[1][i + k - 1] - a[1][i - 1] + a[2][i + k - 1] -
                                 a[2][i - 1]);
    f[p + i] = dp[1][i];
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= min(m - k + 1, k); j++)
      f[p + j] -= a[i][k] - a[i][j - 1];
    for (int j = p - 1; j > 0; j--)
      f[j] = max(f[j << 1], f[j << 1 | 1]), lazy[j] = 0;
    dp[i][1] = f[1] + a[i][k] + a[i + 1][k];
    for (int j = 2; j <= m - k + 1; j++) {
      change(max(1, j - k), j - 1, a[i][j - 1] - a[i][j - 2]),
          change(j, min(j + k - 1, m - k + 1),
                 a[i][j + k - 2] - a[i][j + k - 1]);
      dp[i][j] = f[1] + a[i][j + k - 1] - a[i][j - 1] + a[i + 1][j + k - 1] -
                 a[i + 1][j - 1];
    }
    for (int j = 1; j <= m - k + 2; j++) f[p + j] = dp[i][j], lazy[p + j] = 0;
  }
  for (int i = 1; i <= m - k + 1; i++) ans = max(ans, dp[n][i]);
  printf("%lld\n", ans);
  return 0;
}
