#include <bits/stdc++.h>
using namespace std;
int k, m, n, p = 1 << 15, s, a[66000], l[66000], r[66000], x[20040], z[66000],
             w[60][20040];
int M(int x, int y, int d) {
  a[d] += z[d];
  if (l[d] < r[d]) {
    z[d << 1] += z[d];
    z[d << 1 | 1] += z[d];
  }
  z[d] = 0;
  if (x <= l[d] && r[d] <= y) return a[d];
  if (x > r[d] || y < l[d]) return 0;
  return a[d] = max(M(x, y, d << 1), M(x, y, d << 1 | 1));
}
void REP(int x, int y, int d, int k) {
  if (x <= l[d] && r[d] <= y) z[d] += k;
  a[d] += z[d];
  if (l[d] < r[d]) {
    z[d << 1] += z[d];
    z[d << 1 | 1] += z[d];
  }
  z[d] = 0;
  if (x <= l[d] && r[d] <= y || x > r[d] || y < l[d]) return;
  REP(x, y, d << 1, k);
  REP(x, y, d << 1 | 1, k);
  a[d] = max(a[d << 1], a[d << 1 | 1]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  for (int i = 0; i < p; i++) l[p + i] = r[p + i] = i;
  for (int i = p; --i;) {
    l[i] = l[i << 1];
    r[i] = r[i << 1 | 1];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) cin >> w[i][j];
  }
  if (n == 1) {
    for (int i = 1; i <= k; i++) s += w[1][i];
    p = s;
    for (int i = k + 1; i <= m; i++) {
      s += w[1][i] - w[1][i - k];
      p = max(p, s);
    }
    cout << p;
    return 0;
  }
  for (int i = 1; i < k; i++) s += w[1][i] + w[2][i];
  for (int i = k; i <= m; i++) {
    s += w[1][i] + w[2][i] - w[1][i - k] - w[2][i - k];
    a[p + i] = s;
  }
  for (int i = 2; i <= n; i++) {
    s = 0;
    for (int j = 1; j <= k; j++) s += w[i][j] + w[i + 1][j];
    for (int j = m; j >= 2 * k; j--) a[p + j] += s;
    for (int j = 2 * k - 1; j >= k; j--) {
      s -= w[i][j - k + 1];
      if (j <= m) a[p + j] += s;
    }
    for (int j = p; --j;) {
      a[j] = max(a[j << 1], a[j << 1 | 1]);
      z[p + j] = z[j] = 0;
    }
    x[k] = a[1];
    for (int j = k + 1; j <= m; j++) {
      z[1] += w[i][j] + w[i + 1][j] - w[i][j - k] - w[i + 1][j - k];
      REP(j - k, j - 1, 1, w[i][j - k]);
      REP(j, j + k - 1, 1, -w[i][j]);
      x[j] = M(k, m, 1);
    }
    for (int j = k; j <= m; j++) a[p + j] = x[j];
  }
  cout << *max_element(x + k, x + m + 1);
}
