#include <bits/stdc++.h>
using namespace std;
int a[55][21212], D[55][21212], S[55][21212], l[55][21212], r[55][21212],
    lmx[55][21212], rmx[55][21212];
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  int i, j;
  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];
  for (i = k; i <= m; i++)
    D[2][i] = S[2][i] - S[2][i - k] + S[1][i] - S[1][i - k];
  int ans = 0;
  for (i = 3; i <= n + 1; i++) {
    {
      deque<int> Q, w;
      int pls = 0;
      for (j = k; j <= m; j++) {
        pls += a[i - 1][j - k];
        int v = D[i - 1][j] - (S[i - 1][j] - S[i - 1][j - k]) - pls;
        while (!Q.empty() && Q.back() <= v) Q.pop_back(), w.pop_back();
        Q.push_back(v);
        w.push_back(j);
        while (!w.empty() && w.front() <= j - k) Q.pop_front(), w.pop_front();
        l[i][j] = Q.front() + pls;
        lmx[i - 1][j] = max(lmx[i - 1][j - 1], D[i - 1][j]);
      }
    }
    {
      deque<int> Q, w;
      int pls = 0;
      for (j = m; j >= k; j--) {
        pls += a[i - 1][j + 1];
        int v = D[i - 1][j] - (S[i - 1][j] - S[i - 1][j - k]) - pls;
        while (!Q.empty() && Q.back() <= v) Q.pop_back(), w.pop_back();
        Q.push_back(v);
        w.push_back(j);
        while (!w.empty() && j + k <= w.front()) Q.pop_front(), w.pop_front();
        r[i][j] = Q.front() + pls;
        rmx[i - 1][j] = max(rmx[i - 1][j + 1], D[i - 1][j]);
      }
    }
    for (j = k; j <= m; j++) {
      int v = max(l[i][j], r[i][j]);
      if (j - k >= k) v = max(v, lmx[i - 1][j - k]);
      if (j + k <= m) v = max(v, rmx[i - 1][j + k]);
      D[i][j] = v + S[i][j] - S[i][j - k] + S[i - 1][j] - S[i - 1][j - k];
    }
  }
  for (i = k; i <= m; i++) ans = max(ans, D[n + 1][i]);
  printf("%d\n", ans);
  return 0;
}
