#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
struct segt {
  long long lz, val;
};
segt tree[53][32773 << 1];
int a[53][32773], pre[53][32773];
long long value[32773];
int N, M, K;
void build(int l, int r, int index, int dim) {
  if (l > r) return;
  if (l == r) {
    tree[dim][index].val = value[l];
    return;
  }
  build(l, ((l + r) >> 1), (index << 1), dim);
  build(((l + r) >> 1) + 1, r, (index << 1 | 1), dim);
  tree[dim][index].val =
      max(tree[dim][(index << 1)].val, tree[dim][(index << 1 | 1)].val);
}
void pushdown(int l, int r, int index, int dim) {
  if (l > r) return;
  if (tree[dim][index].lz != 0) {
    if (l != r) {
      tree[dim][(index << 1)].val += tree[dim][index].lz;
      tree[dim][(index << 1 | 1)].val += tree[dim][index].lz;
      tree[dim][(index << 1)].lz += tree[dim][index].lz;
      tree[dim][(index << 1 | 1)].lz += tree[dim][index].lz;
    }
    tree[dim][index].lz = 0;
  }
}
void update(int start, int end, int l, int r, int index, int val, int dim) {
  if (start > end || l > r || start > r || l > end) return;
  pushdown(l, r, index, dim);
  if (start <= l && r <= end) {
    tree[dim][index].val += val;
    tree[dim][index].lz += val;
    return;
  }
  if (end <= ((l + r) >> 1)) {
    update(start, end, l, ((l + r) >> 1), (index << 1), val, dim);
  } else if (start >= ((l + r) >> 1) + 1) {
    update(start, end, ((l + r) >> 1) + 1, r, (index << 1 | 1), val, dim);
  } else {
    update(start, end, l, ((l + r) >> 1), (index << 1), val, dim);
    update(start, end, ((l + r) >> 1) + 1, r, (index << 1 | 1), val, dim);
  }
  tree[dim][index].val =
      max(tree[dim][(index << 1)].val, tree[dim][(index << 1 | 1)].val);
}
int main() {
  int i, j;
  scanf("%d%d%d", &N, &M, &K);
  for (i = 0; i < N; ++i) {
    for (j = 1; j <= M; ++j) {
      scanf("%d", &a[i][j]);
      pre[i][j] = pre[i][j - 1] + a[i][j];
    }
  }
  for (i = 1; i <= M; ++i) {
    value[i] = pre[0][i] + pre[1][i];
    if (i >= K) {
      value[i] -= pre[0][i - K] + pre[1][i - K];
    }
  }
  build(1, M, 1, 1);
  for (i = 2; i <= N; ++i) {
    for (j = 1; j <= M; ++j) {
      update(j, min(j + K - 1, M), 1, M, 1, -a[i - 1][j], i - 1);
      if (j > K) {
        update(j - K, j - 1, 1, M, 1, a[i - 1][j - K], i - 1);
      }
      value[j] = pre[i][j] + pre[i - 1][j];
      if (j >= K) value[j] -= pre[i][j - K] + pre[i - 1][j - K];
      value[j] += tree[i - 1][1].val;
    }
    build(1, M, 1, i);
  }
  printf("%I64d\n", tree[N][1].val);
  return 0;
}
