#include <bits/stdc++.h>
using namespace std;
const int N = 60;
const int M = 20010;
int n, m, k;
int a[N][M];
long long s[N][M];
long long c[M << 2], p[M << 2];
long long f[N][M];
long long ans;
long long calc(int x, int y) {
  return s[x][min(m, y + k - 1)] - s[x][y - 1] + s[x + 1][min(m, y + k - 1)] -
         s[x + 1][y - 1];
}
void Build(int x, int l, int r, int row) {
  p[x] = 0;
  if (l == r) {
    c[x] = f[row - 1][l] - (l <= k ? s[row][k] - s[row][l - 1] : 0);
    return;
  }
  int mid = l + r >> 1;
  Build(x << 1, l, mid, row);
  Build(x << 1 | 1, mid + 1, r, row);
  c[x] = max(c[x << 1], c[x << 1 | 1]);
}
void pushdown(int x) {
  c[x << 1] += p[x];
  p[x << 1] += p[x];
  c[x << 1 | 1] += p[x];
  p[x << 1 | 1] += p[x];
  p[x] = 0;
}
void Update(int x, int l, int r, int L, int R, int y) {
  if (l > R || r < L) return;
  if (l >= L && r <= R) {
    c[x] += y;
    p[x] += y;
    return;
  }
  if (p[x]) pushdown(x);
  int mid = l + r >> 1;
  Update(x << 1, l, mid, L, R, y);
  Update(x << 1 | 1, mid + 1, r, L, R, y);
  c[x] = max(c[x << 1], c[x << 1 | 1]);
}
void modify(int x, int y, bool fl) {
  Update(1, 1, m, max(1, y - k + 1), y, (fl ? -1 : 1) * a[x][y]);
}
void solve() {
  for (int i = 1; i <= m; i++) f[1][i] = calc(1, i);
  for (int i = 2; i <= n; i++) {
    Build(1, 1, m, i);
    f[i][1] = c[1] + calc(i, 1);
    for (int j = 2; j <= m; j++) {
      modify(i, j - 1, 0);
      if (j + k - 1 <= m) modify(i, j + k - 1, 1);
      f[i][j] = c[1] + calc(i, j);
    }
  }
}
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]), s[i][j] = s[i][j - 1] + a[i][j];
  solve();
  for (int j = 1; j <= m; j++) ans = max(ans, f[n][j]);
  cout << ans << endl;
  return 0;
}
