#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 2e4 + 5;
int sum[55][N], a[55][N];
int lazy[N << 2], tree[N << 2];
int dp[55][N];
void pushdown(int root) {
  if (lazy[root]) {
    tree[root << 1] += lazy[root];
    tree[root << 1 | 1] += lazy[root];
    lazy[root << 1] += lazy[root];
    lazy[root << 1 | 1] += lazy[root];
    lazy[root] = 0;
  }
}
void update(int root, int l, int r, int L, int R, int val) {
  if (L <= l && r <= R) {
    tree[root] += val;
    lazy[root] += val;
    return;
  }
  pushdown(root);
  int mid = (l + r) >> 1;
  if (L <= mid) update(root << 1, l, mid, L, R, val);
  if (R > mid) update(root << 1 | 1, mid + 1, r, L, R, val);
  tree[root] = max(tree[root << 1], tree[root << 1 | 1]);
}
int getsum(int x1, int y1, int x2, int y2) {
  return sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1];
}
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]);
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i][j];
    }
  }
  for (int i = 1; i <= m; i++) {
    dp[1][i] = getsum(1, i, min(2, n), min(m, i + k - 1));
  }
  for (int i = 2; i <= n; i++) {
    memset(lazy, 0, sizeof lazy);
    memset(tree, 0, sizeof tree);
    for (int j = 1; j <= m; j++) {
      update(1, 1, m, j, j, dp[i - 1][j]);
    }
    for (int j = 1; j <= k; j++) {
      update(1, 1, m, 1, j, -a[i][j]);
    }
    for (int j = 1; j <= m; j++) {
      dp[i][j] = tree[1] + getsum(i, j, min(n, i + 1), min(m, j + k - 1));
      update(1, 1, m, max(j - k + 1, 1), j, a[i][j]);
      if (j + k <= m) {
        update(1, 1, m, j + 1, j + k, -a[i][j + k]);
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    ans = max(ans, dp[n][i]);
  }
  printf("%d\n", ans);
  return 0;
}
