#include <bits/stdc++.h>
using namespace std;
const int maxn = 20050;
int a[55][maxn];
int f[55][maxn], lmax[55][maxn], rmax[55][maxn];
int get(int i, int l, int r) { return a[i][r] - a[i][l - 1]; }
int mi[maxn << 2], add[maxn << 2];
void push_down(int rt) {
  if (!add[rt]) return;
  mi[rt << 1] += add[rt];
  mi[rt << 1 | 1] += add[rt];
  add[rt << 1] += add[rt];
  add[rt << 1 | 1] += add[rt];
  add[rt] = 0;
  mi[rt] = max(mi[rt << 1], mi[rt << 1 | 1]);
}
void update(int rt, int l, int r, int L, int R, int v) {
  if (L <= l && R >= r) {
    mi[rt] += v;
    add[rt] += v;
    return;
  }
  push_down(rt);
  int mid = l + r >> 1;
  if (L <= mid) update(rt << 1, l, mid, L, R, v);
  if (R > mid) update(rt << 1 | 1, mid + 1, r, L, R, v);
  mi[rt] = max(mi[rt << 1], mi[rt << 1 | 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]);
      a[i][j] += a[i][j - 1];
    }
  }
  for (int j = 1; j <= m - k + 1; j++) {
    f[1][j] = get(1, j, j + k - 1) + get(2, j, j + k - 1);
  }
  int mm = m - k + 1;
  for (int i = 2; i <= n; i++) {
    memset(mi, 0, sizeof(mi));
    memset(add, 0, sizeof(add));
    for (int j = 1; j <= mm; j++) update(1, 1, mm, j, j, f[i - 1][j]);
    for (int j = 1; j <= k; j++) update(1, 1, mm, 1, j, -get(i, j, j));
    for (int j = 1; j <= mm; j++) {
      f[i][j] =
          max(f[i][j], mi[1] + get(i, j, j + k - 1) + get(i + 1, j, j + k - 1));
      update(1, 1, mm, max(1, j - k + 1), j, get(i, j, j));
      update(1, 1, mm, j + 1, j + k, -get(i, j + k, j + k));
    }
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) ans = max(ans, f[n][i]);
  printf("%d\n", ans);
}
