#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &n) {
  n = 0;
  T f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-') f = -1, c = getchar();
  while (isdigit(c)) n = n * 10 + c - '0', c = getchar();
  n *= f;
}
int n, m, k, lim;
int a[55][20005], f[55][20005], s[55][20005];
int mx[20005 * 4], tag[20005 * 4];
void push_down(int p) {
  mx[(p << 1)] += tag[p], mx[(p << 1 | 1)] += tag[p];
  tag[(p << 1)] += tag[p], tag[(p << 1 | 1)] += tag[p];
  tag[p] = 0;
}
void build(int p, int l, int r, int id) {
  tag[p] = 0;
  mx[p] = -0x3f3f3f3f;
  if (l == r) {
    mx[p] = f[id][l] + s[id + 1][l + k - 1] - s[id + 1][l - 1];
    return;
  }
  build((p << 1), l, ((l + r) >> 1), id);
  build((p << 1 | 1), ((l + r) >> 1) + 1, r, id);
  mx[p] = max(mx[(p << 1)], mx[(p << 1 | 1)]);
}
void update(int p, int l, int r, int ul, int ur, int k) {
  if (l >= ul && r <= ur) {
    mx[p] += k, tag[p] += k;
    return;
  }
  push_down(p);
  if (((l + r) >> 1) >= ul) update((p << 1), l, ((l + r) >> 1), ul, ur, k);
  if (((l + r) >> 1) < ur)
    update((p << 1 | 1), ((l + r) >> 1) + 1, r, ul, ur, k);
  mx[p] = max(mx[(p << 1)], mx[(p << 1 | 1)]);
}
int main() {
  cin >> n >> m >> k;
  lim = m - k + 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      read(a[i][j]);
      s[i][j] = s[i][j - 1] + a[i][j];
    }
  }
  for (int i = 1; i <= lim; i++) {
    f[1][i] = s[1][i + k - 1] - s[1][i - 1];
  }
  build(1, 1, lim, 1);
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= k; j++) {
      update(1, 1, lim, 1, min(j, lim), -a[i][j]);
    }
    for (int j = 1; j <= lim; j++) {
      f[i][j] = mx[1] + s[i][j + k - 1] - s[i][j - 1];
      update(1, 1, lim, max(j - k + 1, 1), j, a[i][j]);
      update(1, 1, lim, j + 1, min(j + k, lim), -a[i][j + k]);
    }
    build(1, 1, lim, i);
  }
  int ans = -0x3f3f3f3f;
  for (int i = 1; i <= lim; i++) {
    ans = max(ans, f[n][i]);
  }
  cout << ans << endl;
  return 0;
}
