#include <bits/stdc++.h>
using namespace std;
const int maxm = int(2e4 + 2);
int n, m, k;
long long a[52][maxm], lazy[4 * maxm], it[4 * maxm], dp[52][maxm];
long long sum(int i, int l, int r) { return l > r ? 0 : a[i][r] - a[i][l - 1]; }
long long update(int l, int r, int i, int j, long long val, int id) {
  if (l > j || r < i) return it[id];
  if (l >= i && r <= j) {
    it[id] += val;
    lazy[id] += val;
    return it[id];
  }
  lazy[id * 2 + 1] += lazy[id];
  lazy[id * 2] += lazy[id];
  it[id * 2 + 1] += lazy[id];
  it[id * 2] += lazy[id];
  it[id] += lazy[id];
  lazy[id] = 0;
  int mid = (l + r) >> 1;
  return it[id] = max(update(l, mid, i, j, val, id * 2),
                      update(mid + 1, r, i, j, val, id * 2 + 1));
}
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  for (int i = 1; i <= k; i++) dp[1][1] += a[1][i] + a[2][i];
  for (int i = k + 1; i <= m; i++)
    dp[1][i - k + 1] =
        dp[1][i - k] + a[1][i] - a[1][i - k] + a[2][i] - a[2][i - k];
  for (int i = 2; i <= n; i++) {
    long long S = 0;
    memset(it, 0, sizeof it);
    memset(lazy, 0, sizeof lazy);
    for (int j = 1; j <= m - k + 1; j++)
      update(1, m - k + 1, j, j, dp[i - 1][j], 1);
    for (int j = 1; j <= k; j++)
      update(1, m - k + 1, 1, j, -a[i][j], 1), S += a[i][j] + a[i + 1][j];
    for (int j = 1; j <= m - k + 1; j++) {
      if (j != 1)
        S += a[i + 1][j + k - 1] - a[i + 1][j - 1] + a[i][j + k - 1] -
             a[i][j - 1];
      dp[i][j] = it[1] + S;
      if (j != m - k + 1) {
        update(1, m - k + 1, max(1, j - k + 1), j, a[i][j], 1);
        update(1, m - k + 1, j + 1, j + k, -a[i][j + k], 1);
      }
    }
  }
  cout << *max_element(dp[n] + 1, dp[n] + m - k + 2);
  return 0;
}
