#include <bits/stdc++.h>
const int M_MAX = 20003;
int a[53][M_MAX], s[53][M_MAX], dp[53][M_MAX], pre[53][M_MAX], suf[53][M_MAX];
const int T_MAX = 80003, init = -1044266559;
struct SegmentTree {
  int mx[T_MAX];
  SegmentTree() { memset(mx, -0x3f, sizeof mx); }
  void modify(int k, int l, int r, int x, int v) {
    mx[k] = std::max(mx[k], v);
    if (l == r) return;
    if (x <= ((l + r) >> 1))
      modify((k << 1), l, ((l + r) >> 1), x, v);
    else
      modify((k << 1 | 1), ((l + r) >> 1) + 1, r, x, v);
  }
  int query(int k, int l, int r, int x, int y) {
    if (x <= l && r <= y) return mx[k];
    int o = init;
    if (x <= ((l + r) >> 1))
      o = std::max(o, query((k << 1), l, ((l + r) >> 1), x, y));
    if (((l + r) >> 1) < y)
      o = std::max(o, query((k << 1 | 1), ((l + r) >> 1) + 1, r, x, y));
    return o;
  }
} segtree[53][2];
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  int lim = m - k + 1;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      scanf("%d", &a[i][j]), s[i][j] = s[i][j - 1] + a[i][j];
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= lim; ++j) {
      int l = std::max(0, j - k), r = std::min(lim + 1, j + k);
      dp[i][j] =
          std::max(std::max(pre[i - 1][l], suf[i - 1][r]),
                   std::max(segtree[i - 1][0].query(1, 1, lim, l + 1, j) +
                                s[i][j - 1],
                            segtree[i - 1][1].query(1, 1, lim, j, r - 1) -
                                s[i][j + k - 1])) +
          s[i][j + k - 1] - s[i][j - 1] + s[i + 1][j + k - 1] - s[i + 1][j - 1];
      segtree[i][0].modify(1, 1, lim, j, dp[i][j] - s[i + 1][j + k - 1]);
      segtree[i][1].modify(1, 1, lim, j, dp[i][j] + s[i + 1][j - 1]);
    }
    for (int j = 1; j <= lim; ++j)
      pre[i][j] = std::max(pre[i][j - 1], dp[i][j]);
    for (int j = lim; j; --j) suf[i][j] = std::max(suf[i][j + 1], dp[i][j]);
  }
  int ans = 0;
  for (int i = 1; i <= lim; ++i) ans = std::max(ans, dp[n][i]);
  printf("%d\n", ans);
  return 0;
}
