#include <bits/stdc++.h>
using namespace std;
const int N = 50010;
int tree[N * 4], upd[N * 4], dp[N], a[101][N], pre[101][N];
void build(int x, int l, int r) {
  if (l == r)
    tree[x] = dp[l];
  else {
    int mid = (l + r) >> 1;
    build(x * 2, l, mid);
    build(x * 2 + 1, mid + 1, r);
    upd[x] = 0;
    tree[x] = max(tree[x * 2], tree[x * 2 + 1]);
  }
}
void add(int x, int l, int r, int ll, int rr, int v) {
  if (ll > rr) return;
  if (ll <= 0) return;
  if (l == r) {
    tree[x] += v;
    return;
  }
  if (ll <= l && r <= rr) {
    upd[x] += v;
    tree[x] += v;
  } else {
    tree[x * 2] += upd[x];
    upd[x * 2] += upd[x];
    tree[x * 2 + 1] += upd[x];
    upd[x * 2 + 1] += upd[x];
    upd[x] = 0;
    int mid = (l + r) >> 1;
    if (ll <= mid) add(x * 2, l, mid, ll, rr, v);
    if (rr > mid) add(x * 2 + 1, mid + 1, r, ll, rr, v);
    tree[x] = max(tree[x * 2], tree[x * 2 + 1]);
  }
}
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  k--;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> pre[i][j];
      a[i][j] = pre[i][j];
      pre[i][j] += pre[i][j - 1];
    }
  for (int j = 1; j + k <= m; j++) {
    dp[j] = pre[1][j + k] - pre[1][j - 1] + pre[2][j + k] - pre[2][j - 1];
  }
  for (int i = 2; i <= n; i++) {
    build(1, 1, m - k);
    for (int j = 1; j <= k + 1; j++) add(1, 1, m - k, j + 1, m - k, a[i][j]);
    dp[1] = tree[1] + pre[i + 1][k + 1];
    for (int j = 2; j + k <= m; j++) {
      add(1, 1, m - k, 1, j - 1, a[i][j + k]);
      add(1, 1, m - k, j + k + 1, m - k, a[i][j + k]);
      add(1, 1, m - k, j, m - k, -a[i][j - 1]);
      add(1, 1, m - k, 1, j - k - 2, -a[i][j - 1]);
      dp[j] = tree[1] + pre[i + 1][j + k] - pre[i + 1][j - 1];
    }
  }
  build(1, 1, m - k);
  cout << tree[1] << endl;
}
