#include <bits/stdc++.h>
using namespace std;
int a[55][20005], f[55][20005], mx1[20005], mx2[20005], k;
int sum(int i, int j) {
  return a[i][j + k - 1] - a[i][j - 1] + a[i + 1][j + k - 1] - a[i + 1][j - 1];
}
int main() {
  int n, m;
  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]);
      a[i][j] += a[i][j - 1];
    }
  for (int i = 1; i <= m - k + 1; i++) f[1][i] = sum(1, i);
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= m - k + 1; j++) mx1[j] = max(mx1[j - 1], f[i - 1][j]);
    for (int j = m - k + 1; j; j--) mx2[j] = max(mx2[j + 1], f[i - 1][j]);
    for (int j = 1; j <= m - k + 1; j++)
      f[i][j] = max(mx1[max(j - k, 0)], mx2[j + k]) + sum(i, j);
    deque<int> q;
    for (int j = 1; j <= m - k + 1; j++) {
      while (!q.empty() && q.front() + k - 1 < j) q.pop_front();
      while (!q.empty() &&
             f[i - 1][q.back()] - (a[i][q.back() + k - 1] - a[i][j - 1]) <=
                 f[i - 1][j] - (a[i][j + k - 1] - a[i][j - 1]))
        q.pop_back();
      q.push_back(j);
      f[i][j] = max(f[i][j], f[i - 1][q.front()] + sum(i, j) -
                                 (a[i][q.front() + k - 1] - a[i][j - 1]));
    }
    while (!q.empty()) q.pop_front();
    for (int j = m - k + 1; j; j--) {
      while (!q.empty() && q.front() - k + 1 > j) q.pop_front();
      while (!q.empty() &&
             f[i - 1][q.back()] - (a[i][j + k - 1] - a[i][q.back() - 1]) <=
                 f[i - 1][j] - (a[i][j + k - 1] - a[i][j - 1]))
        q.pop_back();
      q.push_back(j);
      f[i][j] = max(f[i][j], f[i - 1][q.front()] + sum(i, j) -
                                 (a[i][j + k - 1] - a[i][q.front() - 1]));
    }
  }
  int ans = 0;
  for (int j = 1; j <= m - k + 1; j++) ans = max(ans, f[n][j]);
  printf("%d", ans);
  return 0;
}
