#include <bits/stdc++.h>
using namespace std;
int m, n, k, a[55][20005], sum[55][20005];
long long tree[80005], lazy[80005];
long long f[20005], ans = 0;
void build(int id, int l, int r) {
  if (l == r) {
    tree[id] = f[l];
    return;
  }
  int mi = (l + r) / 2;
  build(id * 2, l, mi);
  build(id * 2 + 1, mi + 1, r);
  tree[id] = max(tree[id * 2], tree[id * 2 + 1]);
}
void down(int id) {
  int t = lazy[id];
  lazy[id] = 0;
  tree[id * 2] += t;
  lazy[id * 2] += t;
  tree[id * 2 + 1] += t;
  lazy[id * 2 + 1] += t;
}
void upd(int id, int l, int r, int u, int v, int val) {
  if (r < u || l > v) return;
  if (u <= l && r <= v) {
    tree[id] += val;
    lazy[id] += val;
    return;
  }
  int mi = (l + r) / 2;
  down(id);
  upd(id * 2, l, mi, u, v, val);
  upd(id * 2 + 1, mi + 1, r, u, v, val);
  tree[id] = max(tree[id * 2], tree[id * 2 + 1]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      sum[i][j] = sum[i][j - 1] + a[i][j];
    }
  for (int j = k; j <= m; j++)
    f[j] = sum[1][j] - sum[1][j - k] + sum[2][j] - sum[2][j - k],
    ans = max(ans, f[j]);
  if (n == 1) {
    cout << ans;
    return 0;
  }
  for (int i = 2; i <= n; i++) {
    build(1, k, m);
    memset(lazy, 0, sizeof lazy);
    for (int j = 1; j <= m; j++) {
      upd(1, k, m, max(k, j), min(m, j + k - 1), -a[i][j]);
      if (j > k) {
        int p = j - k;
        upd(1, k, m, max(k, p), min(m, p + k - 1), a[i][p]);
      }
      if (j >= k) {
        f[j] = sum[i][j] - sum[i][j - k] + sum[i + 1][j] - sum[i + 1][j - k] +
               tree[1];
        if (i == n) ans = max(ans, f[j]);
      }
    }
  }
  cout << ans;
  return 0;
}
