#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int f[55][20005];
int a[55][20005];
int s[55][20005];
int p[55][20005];
int q[55][20005];
int s1[19][20005], s2[19][20005], logn[20005];
inline int max(int a, int b) { return (a > b ? a : b); }
inline int q1(int l, int r) {
  int t = logn[r - l + 1];
  return max(s1[t][l], s1[t][r - (1 << t) + 1]);
}
inline int q2(int l, int r) {
  int t = logn[r - l + 1];
  return max(s2[t][l], s2[t][r - (1 << t) + 1]);
}
int main() {
  int i, j, l, ans = 0;
  scanf("%d%d%d", &n, &m, &k);
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      scanf("%d", &a[i][j]);
      s[i][j] = s[i][j - 1] + a[i][j];
    }
  }
  int w = m - k + 1;
  for (i = 1; i <= w; i++) f[1][i] = s[1][i + k - 1] - s[1][i - 1];
  for (i = 1; i <= w; i++)
    p[1][i] = max(p[1][i - 1], f[1][i] + s[2][i + k - 1] - s[2][i - 1]);
  for (i = w; i >= 1; i--)
    q[1][i] = max(q[1][i + 1], f[1][i] + s[2][i + k - 1] - s[2][i - 1]);
  for (logn[0] = -1, i = 1; i <= w; i++) logn[i] = logn[(i >> 1)] + 1;
  for (j = 2; j <= n; j++) {
    for (i = 1; i <= w; i++) s1[0][i] = f[j - 1][i] - s[j][i - 1];
    for (i = 1; i <= w; i++) s2[0][i] = f[j - 1][i] + s[j][i + k - 1];
    for (l = 1; l <= logn[w]; l++) {
      for (i = 1; i + (1 << l) - 1 <= w; i++) {
        s1[l][i] = max(s1[l - 1][i], s1[l - 1][i + (1 << (l - 1))]);
        s2[l][i] = max(s2[l - 1][i], s2[l - 1][i + (1 << (l - 1))]);
      }
    }
    for (i = 1; i <= w; i++) {
      int st = max(1, i - k + 1), ed = min(w, i + k - 1);
      f[j][i] = max(p[j - 1][st - 1], q[j - 1][ed + 1]) + s[j][i + k - 1] -
                s[j][i - 1];
      if (st <= i) f[j][i] = max(f[j][i], q1(st, i) + s[j][i + k - 1]);
      if (i + 1 <= ed) f[j][i] = max(f[j][i], q2(i + 1, ed) - s[j][i - 1]);
    }
    for (i = 1; i <= w; i++)
      p[j][i] =
          max(p[j][i - 1], f[j][i] + s[j + 1][i + k - 1] - s[j + 1][i - 1]);
    for (i = w; i >= 1; i--)
      q[j][i] =
          max(q[j][i + 1], f[j][i] + s[j + 1][i + k - 1] - s[j + 1][i - 1]);
  }
  for (i = 1; i <= w; i++) ans = max(ans, f[n][i]);
  printf("%d\n", ans);
  return 0;
}
