#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long f = 1, x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + (s - '0');
    s = getchar();
  }
  return x * f;
}
const int jzm = 1000000007;
int n, m, i, j, s, o, k;
int a[55][20005], sum[55][20005];
int dp[20005];
int tre[20005 << 2], lz[20005 << 2], M;
void maketree(int n) {
  M = 1;
  while (M < n + 1) M <<= 1;
  memset(tre, 0, sizeof(tre));
  memset(lz, 0, sizeof(lz));
  for (int i = n; i > 0; i--) {
    tre[i + M] = dp[i];
  }
  for (int i = M; i > 0; i--) {
    tre[i] = max(tre[i << 1], tre[i << 1 | 1]);
  }
  return;
}
void addtree(int l, int r, int y) {
  int s = M + l - 1, t = M + r + 1;
  while (s || t) {
    if (s < M) tre[s] = max(tre[s << 1], tre[s << 1 | 1]) + lz[s];
    if (t < M) tre[t] = max(tre[t << 1], tre[t << 1 | 1]) + lz[t];
    if ((s >> 1) ^ (t >> 1)) {
      if (!(s & 1)) tre[s ^ 1] += y, lz[s ^ 1] += y;
      if (t & 1) tre[t ^ 1] += y, lz[t ^ 1] += y;
    }
    s >>= 1;
    t >>= 1;
  }
  return;
}
int findall() { return tre[1] + lz[1]; }
int main() {
  n = read();
  m = read();
  k = read();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      a[i][j] = read();
      sum[i][j] = sum[i][j - 1] + a[i][j];
    }
  }
  for (int i = 1; i <= m - k + 1; i++) {
    dp[i] =
        sum[1][i + k - 1] - sum[1][i - 1] + sum[2][i + k - 1] - sum[2][i - 1];
  }
  for (int i = 2; i <= n; i++) {
    maketree(m - k + 1);
    for (int j = 1; j <= k; j++) {
      addtree(max(1, j - k + 1), min(j, m - k + 1), -a[i][j]);
    }
    dp[1] = findall() + sum[i][k] + sum[i + 1][k];
    for (int j = 2; j <= m - k + 1; j++) {
      addtree(max(1, j - k), j - 1, a[i][j - 1]);
      addtree(j, min(m - k + 1, j + k - 1), -a[i][j + k - 1]);
      dp[j] = findall() - sum[i][j - 1] - sum[i + 1][j - 1] +
              sum[i][j + k - 1] + sum[i + 1][j + k - 1];
    }
  }
  int ans = 0;
  for (int i = 1; i <= m - k + 1; i++) {
    ans = max(ans, dp[i]);
  }
  printf("%d\n", ans);
  return 0;
}
