#include <bits/stdc++.h>
using namespace std;
const int MAXN = 51111;
const int INF = 0x3f3f3f3f;
const double eps = 1e-4;
const int maxn = 20010;
const double PI = 3.14159265;
int a[52][20010];
int pre[52][20010];
int dp[52][20010];
struct seg {
  int l, r;
  int lazy;
  int va;
  int len() { return r - l + 1; }
} tree[maxn << 2];
void pushup(int rt) {
  tree[rt].va = max(tree[rt << 1].va, tree[rt << 1 | 1].va);
}
void pushdown(int rt) {
  if (tree[rt].lazy) {
    tree[rt << 1].lazy += tree[rt].lazy;
    tree[rt << 1 | 1].lazy += tree[rt].lazy;
    tree[rt << 1].va += tree[rt].lazy;
    tree[rt << 1 | 1].va += tree[rt].lazy;
    tree[rt].lazy = 0;
  }
}
void build(int rt, int l, int r) {
  tree[rt].l = l;
  tree[rt].r = r;
  tree[rt].lazy = 0;
  tree[rt].va = 0;
  if (l == r) return;
  int mid = (l + r) >> 1;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
}
void update(int rt, int L, int R, int val) {
  if (tree[rt].l >= L && tree[rt].r <= R) {
    tree[rt].va += val;
    tree[rt].lazy += val;
    return;
  }
  pushdown(rt);
  int mid = (tree[rt].l + tree[rt].r) >> 1;
  if (mid >= L) update(rt << 1, L, R, val);
  if (mid < R) update(rt << 1 | 1, L, R, val);
  pushup(rt);
}
int main() {
  int n, m, k;
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      scanf("%d", &a[i][j]);
      pre[i][j] = pre[i][j - 1] + a[i][j];
    }
  for (int i = 1; i <= m - k + 1; i++)
    dp[1][i] = (pre[1][i + k - 1] - pre[1][i - 1]) +
               (pre[2][i + k - 1] - pre[2][i - 1]);
  for (int i = 2; i <= n; i++) {
    build(1, 1, m);
    for (int j = 1; j <= m - k + 1; j++) update(1, j, j, dp[i - 1][j]);
    for (int j = 1; j <= k; j++) update(1, 1, j, -a[i][j]);
    for (int j = 1; j <= m - k + 1; j++) {
      dp[i][j] = tree[1].va + (pre[i + 1][j + k - 1] - pre[i + 1][j - 1]) +
                 (pre[i][j + k - 1] - pre[i][j - 1]);
      if (j != m - k + 1) {
        update(1, max(1, j - k + 1), j, a[i][j]);
        update(1, j + 1, j + k, -a[i][j + k]);
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= m - k + 1; i++) ans = max(ans, dp[n][i]);
  printf("%d\n", ans);
  return 0;
}
