#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r, mx, tag;
} t[80010];
int n, m, k, a[55][20010], sum[55][20010], dp[55][20010], p, ans;
void Build(const int& x, const int& l, const int& r) {
  t[x].l = l, t[x].r = r, t[x].tag = 0;
  if (l == r) return (void)(t[x].mx = dp[p][l]);
  int mid = l + r >> 1;
  Build(x << 1, l, mid), Build(x << 1 | 1, mid + 1, r),
      (t[x].mx = max(t[x << 1].mx, t[x << 1 | 1].mx));
}
void Change(const int& x, const int& l, const int& r, const int& v) {
  if (t[x].l == l && t[x].r == r) return (void)(t[x].tag += v, t[x].mx += v);
  (t[x].tag ? t[x << 1].tag += t[x].tag, t[x << 1].mx += t[x].tag,
   t[x << 1 | 1].tag += t[x].tag, t[x << 1 | 1].mx += t[x].tag,
   t[x].tag = 0 : 0);
  int mid = t[x].l + t[x].r >> 1;
  r <= mid
      ? Change(x << 1, l, r, v)
      : (l > mid
             ? Change(x << 1 | 1, l, r, v)
             : (Change(x << 1, l, mid, v), Change(x << 1 | 1, mid + 1, r, v))),
      (t[x].mx = max(t[x << 1].mx, t[x << 1 | 1].mx));
}
int main() {
  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]), sum[i][j] = sum[i][j - 1] + a[i][j];
  for (int i = 1; i <= m - k + 1; ++i)
    dp[1][i] =
        sum[1][i + k - 1] - sum[1][i - 1] + sum[2][i + k - 1] - sum[2][i - 1],
    ans = max(ans, dp[1][i]);
  p = 1;
  for (int i = 2; i <= n; ++i, ++p) {
    Build(1, 1, m - k + 1);
    for (int j = 1; j < k; ++j) Change(1, 1, min(j, m - k + 1), -a[i][j]);
    for (int j = 1; j <= m - k + 1; ++j) {
      Change(1, j, min(m - k + 1, j + k - 1), -a[i][j + k - 1]);
      if (j != 1) Change(1, max(1, j - k), j - 1, a[i][j - 1]);
      i != n ? dp[i][j] = t[1].mx + sum[i][j + k - 1] - sum[i][j - 1] +
                          sum[i + 1][j + k - 1] - sum[i + 1][j - 1]
             : ans = max(ans, t[1].mx + sum[i][j + k - 1] - sum[i][j - 1]);
    }
  }
  printf("%d", ans);
  return 0;
}
