#include <bits/stdc++.h>
using namespace std;
const int N = 40006;
int a[55][N], mx[N << 2], add[N << 2], now[N], dp[N];
void up(int rt) { mx[rt] = max(mx[rt << 1], mx[rt << 1 | 1]); }
void down(int rt) {
  if (add[rt]) {
    add[rt << 1] += add[rt];
    add[rt << 1 | 1] += add[rt];
    mx[rt << 1] += add[rt];
    mx[rt << 1 | 1] += add[rt];
    add[rt] = 0;
  }
}
void build(int l, int r, int rt) {
  add[rt] = 0;
  if (l == r) {
    mx[rt] = dp[l];
    return;
  }
  int m = l + r >> 1;
  build(l, m, rt << 1), build(m + 1, r, rt << 1 | 1);
  up(rt);
}
void edit(int L, int R, int c, int l, int r, int rt) {
  if (L > R) return;
  if (L <= l && r <= R) {
    add[rt] += c;
    mx[rt] += c;
    return;
  }
  down(rt);
  int m = (l + r) >> 1;
  if (L <= m) edit(L, R, c, l, m, rt << 1);
  if (m < R) edit(L, R, c, m + 1, r, rt << 1 | 1);
  up(rt);
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  int sum = 0;
  for (int i = 1; i < k; i++) sum += a[1][i] + a[2][i];
  for (int i = 1; i <= m; i++) {
    sum += a[1][i + k - 1] + a[2][i + k - 1];
    sum -= a[1][i - 1] + a[2][i - 1];
    dp[i] = sum;
  }
  for (int i = 2; i <= n; i++) {
    int sum = 0, sum2 = 0;
    for (int j = 1; j <= k; j++) sum += a[i][j], sum2 += a[i + 1][j] + a[i][j];
    for (int j = 1; j <= k; j++) {
      sum -= a[i][j - 1];
      dp[j] -= sum;
    }
    build(1, 40000, 1);
    now[1] = mx[1] + sum2;
    for (int j = 2; j <= m; j++) {
      sum2 += a[i + 1][j + k - 1] + a[i][j + k - 1];
      sum2 -= a[i + 1][j - 1] + a[i][j - 1];
      int l = j, r = j + k - 1;
      edit(max(1, l - (r - l) - 1), l - 1, a[i][j - 1], 1, 40000, 1);
      edit(l, r, -a[i][r], 1, 40000, 1);
      now[j] = mx[1] + sum2;
    }
    memcpy(dp, now, sizeof dp);
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) ans = max(ans, dp[i]);
  cout << ans << endl;
  return 0;
}
