#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e4 + 5;
int m, len;
int f[55][maxn], sum[55][maxn], a[55][maxn];
struct node {
  int l, r, mx1, mx2, mx3, lazy;
} tree[maxn * 8];
void pushup(int k) {
  int ls = k << 1, rs = k << 1 | 1;
  tree[k].mx1 = max(tree[ls].mx1, tree[rs].mx1);
  tree[k].mx2 = max(tree[ls].mx2, tree[rs].mx2);
  tree[k].mx3 = max(tree[ls].mx3, tree[rs].mx3);
}
void build(int k, int l, int r, int id) {
  tree[k].l = l;
  tree[k].r = r;
  tree[k].lazy = 0;
  if (l == r) {
    tree[k].mx1 = f[id][l];
    tree[k].mx2 = f[id][l] - sum[id + 1][min(m, l + len - 1)];
    tree[k].mx3 = f[id][l] + sum[id + 1][l - 1];
    return;
  }
  int mid = (l + r) >> 1;
  build(k << 1, l, mid, id);
  build(k << 1 | 1, mid + 1, r, id);
  pushup(k);
}
int query(int k, int l, int r, int op) {
  if (tree[k].l == l && tree[k].r == r) {
    if (op == 1)
      return tree[k].mx1;
    else if (op == 2)
      return tree[k].mx2;
    return tree[k].mx3;
  }
  int mid = (tree[k].l + tree[k].r) >> 1;
  if (mid >= r)
    return query(k << 1, l, r, op);
  else if (mid < l)
    return query(k << 1 | 1, l, r, op);
  else {
    return max(query(k << 1, l, mid, op), query(k << 1 | 1, mid + 1, r, op));
  }
}
int main() {
  int n;
  scanf("%d%d%d", &n, &m, &len);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &a[i][j]);
      sum[i][j] = sum[i][j - 1] + a[i][j];
    }
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    f[1][i] = sum[1][min(m, i + len - 1)] - sum[1][i - 1];
    f[1][i] += sum[2][min(m, i + len - 1)] - sum[2][i - 1];
    ans = max(ans, f[1][i]);
  }
  for (int i = 2; i <= n; i++) {
    build(1, 1, m, i - 1);
    for (int j = 1; j <= m; j++) {
      int tmp = sum[i][min(m, j + len - 1)] - sum[i][j - 1];
      tmp += sum[i + 1][min(m, j + len - 1)] - sum[i + 1][j - 1];
      if (j - len >= 1) f[i][j] = max(f[i][j], query(1, 1, j - len, 1) + tmp);
      if (j + len <= m) f[i][j] = max(f[i][j], query(1, j + len, m, 1) + tmp);
      f[i][j] = max(f[i][j],
                    query(1, max(j - len + 1, 1), j, 2) + tmp + sum[i][j - 1]);
      f[i][j] = max(f[i][j], query(1, j, min(m, j + len - 1), 3) + tmp -
                                 sum[i][min(m, j + len - 1)]);
      ans = max(ans, f[i][j]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
