#include <bits/stdc++.h>
using namespace std;
inline int gi() {
  int sum = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = (sum << 3) + (sum << 1) + ch - '0';
    ch = getchar();
  }
  return f * sum;
}
const int N = 120, M = 40010;
int a[N][M], n, m, k, o[M << 3], tag[M << 3], sum[N][M], f[N][M];
void pushup(int x) { o[x] = max(o[x << 1], o[x << 1 | 1]); }
void puttag(int x, int k) {
  o[x] += k;
  tag[x] += k;
}
void pushdown(int x) {
  puttag(x << 1, tag[x]);
  puttag(x << 1 | 1, tag[x]);
  tag[x] = 0;
}
void modify(int x, int l, int r, int posl, int posr, int k) {
  if (posl > posr) return;
  if (posl <= l && r <= posr) {
    puttag(x, k);
    return;
  }
  int mid = (l + r) >> 1;
  pushdown(x);
  if (posl <= mid) modify(x << 1, l, mid, posl, posr, k);
  if (mid < posr) modify(x << 1 | 1, mid + 1, r, posl, posr, k);
  pushup(x);
}
int main() {
  n = gi();
  m = gi();
  k = gi();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      a[i][j] = gi(), sum[i][j] = sum[i][j - 1] + a[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j + k - 1 <= m; j++)
      f[1][j] =
          sum[1][j + k - 1] - sum[1][j - 1] + sum[2][j + k - 1] - sum[2][j - 1];
  for (int i = 2; i <= n; i++) {
    memset(o, 0, sizeof(o));
    memset(tag, 0, sizeof(tag));
    for (int j = 1; j <= m; j++) modify(1, 1, m, j, j, f[i - 1][j]);
    for (int j = 1; j <= k; j++) modify(1, 1, m, 1, j, -a[i][j]);
    for (int j = 1; j + k - 1 <= m; j++) {
      f[i][j] = o[1] + sum[i][j + k - 1] - sum[i][j - 1] +
                sum[i + 1][j + k - 1] - sum[i + 1][j - 1];
      modify(1, 1, m, max(1, j - k + 1), j, a[i][j]);
      modify(1, 1, m, j + 1, min(m, j + k), -a[i][j + k]);
    }
  }
  int ans = 0;
  for (int j = 1; j <= m; j++) ans = max(ans, f[n][j]);
  printf("%d\n", ans);
  return 0;
}
