#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)2e4 + 100;
const int mod = (int)1e9 + 7;
int n, m, k, a[55][maxn], dp[55][maxn], pre[55][maxn];
int sum(int i, int l, int r) { return pre[i][r] - pre[i][l - 1]; }
int t[maxn << 2], lz[maxn << 2];
void pushup(int rt) { t[rt] = max(t[rt << 1], t[rt << 1 | 1]); }
void pushdown(int rt) {
  if (lz[rt] == 0) return;
  lz[rt << 1] += lz[rt];
  lz[rt << 1 | 1] += lz[rt];
  t[rt << 1] += lz[rt];
  t[rt << 1 | 1] += lz[rt];
  lz[rt] = 0;
}
void build(int l = 1, int r = m + 1, int rt = 1) {
  if (l == r) {
    t[rt] = lz[rt] = 0;
    return;
  }
  int mid = (l + r) >> 1;
  pushdown(rt);
  build(l, mid, rt << 1);
  build(mid + 1, r, rt << 1 | 1);
  pushup(rt);
}
void update(int ql, int qr, int val, int l = 1, int r = m + 1, int rt = 1) {
  if (ql <= l && r <= qr) {
    t[rt] += val;
    lz[rt] += val;
    return;
  }
  pushdown(rt);
  int mid = (l + r) >> 1;
  if (ql <= mid) update(ql, qr, val, l, mid, rt << 1);
  if (qr > mid) update(ql, qr, val, mid + 1, r, rt << 1 | 1);
  pushup(rt);
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (auto i = (1); i <= (n); ++i)
    for (auto j = (1); j <= (m); ++j)
      scanf("%d", &a[i][j]), pre[i][j] = pre[i][j - 1] + a[i][j];
  m = m - k + 1;
  for (auto i = (1); i <= (m); ++i)
    dp[1][i] = sum(1, i, i + k - 1) + sum(2, i, i + k - 1);
  for (auto i = (2); i <= (n); ++i) {
    build();
    for (auto j = (1); j <= (m); ++j) update(j, j, dp[i - 1][j]);
    for (auto j = (1); j <= (k); ++j) update(1, j, -a[i][j]);
    for (auto j = (1); j <= (m); ++j) {
      dp[i][j] = sum(i, j, j + k - 1) + sum(i + 1, j, j + k - 1) + t[1];
      update(max(1, j - k + 1), j, a[i][j]);
      update(j + 1, j + k, -a[i][j + k]);
    }
  }
  int ans = 0;
  for (auto i = (1); i <= (m); ++i) ans = max(ans, dp[n][i]);
  printf("%d\n", ans);
}
