#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
const int MAX_N = 50;
const int MAX_M = 20000;
const int MAX_K = 20;
int n, m, k;
inline int ps(vvi &p, int i, int s, int e) {
  if (s < 1) return p[i][e];
  return p[i][e] - p[i][s - 1];
}
void calc_overlapped(vvi &ar, vvi &p, vvi &dp, int i) {
  int j;
  deque<pii> dq;
  for (j = 1; j <= m - k + 1; j++) {
    int num = dp[i - 1][j] - ps(p, i, j, j + k - 1);
    if (dq.size() && dq.front().second <= j - k) dq.pop_front();
    while (dq.size() &&
           dq.back().first + ps(p, i, dq.back().second, j - 1) <= num)
      dq.pop_back();
    dq.push_back({num, j});
    dp[i][j] = dq.front().first + ps(p, i, dq.front().second, j - 1) +
               ps(p, i, j, j + k - 1) + ps(p, i + 1, j, j + k - 1);
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int i, j;
  cin >> n >> m >> k;
  vvi init(n + 5, vi(m + 5, 0));
  vvi animal, animal_rev, psum, psum_rev, lmax, rmax, dp, dpl, dpr;
  animal = animal_rev = psum = psum_rev = lmax = rmax = dp = dpl = dpr = init;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      cin >> animal[i][j];
      psum[i][j] = psum[i][j - 1] + animal[i][j];
      animal_rev[i][m - j + 1] = animal[i][j];
    }
    for (j = 1; j <= m; j++)
      psum_rev[i][j] = psum_rev[i][j - 1] + animal_rev[i][j];
  }
  deque<pii> dq;
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m - k + 1; j++) {
      if (j > k) dp[i][j] = lmax[i - 1][j - k];
      if (j <= m - k * 2 + 1) dp[i][j] = max(dp[i][j], rmax[i - 1][j + k]);
      dp[i][j] += ps(psum, i, j, j + k - 1) + ps(psum, i + 1, j, j + k - 1);
    }
    calc_overlapped(animal, psum, dpl, i);
    calc_overlapped(animal_rev, psum_rev, dpr, i);
    for (j = 1; j <= m - k + 1; j++) {
      dp[i][j] = max({dp[i][j], dpl[i][j], dpr[i][m - j - k + 2]});
      dpl[i][j] = dpr[i][m - j - k + 2] = dp[i][j];
    }
    for (j = 1; j <= m - k + 1; j++) lmax[i][j] = max(lmax[i][j - 1], dp[i][j]);
    for (j = m - k + 1; j >= 1; j--) rmax[i][j] = max(rmax[i][j + 1], dp[i][j]);
  }
  cout << *max_element(dp[n].begin(), dp[n].end()) << endl;
}
