#include <bits/stdc++.h>
using namespace std;
const int N = 60;
const int M = 20010;
const int logN = 17;
int n, m, k;
int a[N][M];
long long F[N][M], maxL[N][M], maxR[N][M], s[N][M];
pair<long long, long long> d[M];
int first, last;
void reset() {
  first = 1;
  last = 0;
}
void add(int pos, long long val) {
  while (first <= last && d[last].second <= val) last--;
  d[++last] = make_pair(pos, val);
}
long long get(int pos) {
  while (d[first].first <= pos - k && first <= last) first++;
  if (first > last) return 0;
  return d[first].second;
}
long long getSum(int x, int l, int r) {
  assert(l <= r);
  return s[x][r] - s[x][l - 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];
      s[i][j] = s[i][j - 1] + a[i][j];
    }
  m = m - k + 1;
  for (int l = 1; l <= m; l++) F[1][l] = getSum(1, l, l + k - 1);
  for (int i = 2; i <= n; i++) {
    for (int l = 1; l <= m; l++)
      maxL[i][l] = max(maxL[i][l - 1], F[i - 1][l] + getSum(i, l, (l + k - 1)));
    for (int l = m; l >= 1; l--)
      maxR[i][l] = max(maxR[i][l + 1], F[i - 1][l] + getSum(i, l, (l + k - 1)));
    for (int l = 1; l <= m; l++)
      F[i][l] =
          max(maxL[i][max(0, l - k)], maxR[i][min(m + 1, (l + k - 1) + 1)]) +
          getSum(i, l, (l + k - 1));
    reset();
    for (int l = 1; l <= m; l++) {
      add(l, F[i - 1][l] - s[i][l - 1]);
      F[i][l] = max(F[i][l], s[i][(l + k - 1)] + get(l));
    }
    reset();
    for (int l = m; l >= 1; l--) {
      add(m - l + 1, F[i - 1][l] + s[i][(l + k - 1)]);
      F[i][l] = max(F[i][l], get(m - l + 1) - s[i][l - 1]);
    }
  }
  long long ans = 0;
  for (int l = 1; l <= m; l++) ans = max(ans, F[n][l]);
  cout << ans;
}
