#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
const int maxm = 2e4 + 5;
int a[maxn][maxm], dp[maxm], nxt[maxm], sum[maxn][maxm];
int pre[maxm], suff[maxm];
int n, m, k;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m >> k;
  for (int i = 0; i <= n - 1; i++)
    for (int j = 0; j <= m - 1; j++) cin >> a[i][j];
  for (int i = 0; i <= n - 1; i++)
    for (int j = 0; j <= k - 1; j++) sum[i][0] += a[i][j];
  for (int i = 0; i <= n - 1; i++)
    for (int j = 1; j <= m - k; j++)
      sum[i][j] = sum[i][j - 1] + a[i][j + k - 1] - a[i][j - 1];
  for (int i = 0; i <= m - k; i++) nxt[i] = sum[0][i] + sum[1][i];
  for (int i = 1; i <= n - 1; i++) {
    for (int j = 0; j <= m - k; j++) dp[j] = nxt[j], nxt[j] = 0;
    pre[0] = dp[0];
    for (int i = 1; i <= m - k; i++) pre[i] = max(pre[i - 1], dp[i]);
    suff[m - k] = dp[m - k];
    for (int i = m - k - 1; i >= 0; i--) suff[i] = max(suff[i + 1], dp[i]);
    for (int j = 0; j <= m - k; j++) {
      if (j - k >= 0) nxt[j] = max(pre[j - k], nxt[j]);
      if (j + k <= m - k) nxt[j] = max(suff[j + k], nxt[j]);
    }
    int tmp = 0;
    deque<pair<int, int> > que;
    for (int j = 0; j <= m - k; j++) {
      int now = dp[j] - tmp - sum[i][j];
      while (que.size() && que.front().first < now) que.pop_front();
      que.push_front(pair<int, int>(now, j));
      if (j - k >= 0 && que.size() && que.back().second == j - k)
        que.pop_back();
      nxt[j] = max(nxt[j], que.back().first + tmp);
      tmp += a[i][j];
    }
    tmp = 0;
    que.clear();
    for (int j = m - k; j >= 0; j--) {
      int now = dp[j] - tmp - sum[i][j];
      while (que.size() && que.front().first < now) que.pop_front();
      que.push_front(pair<int, int>(now, j));
      if (j + k <= m - k && que.size() && que.back().second == j + k)
        que.pop_back();
      nxt[j] = max(nxt[j], que.back().first + tmp);
      tmp += a[i][j + k - 1];
    }
    for (int j = 0; j <= m - k; j++) nxt[j] += sum[i][j] + sum[i + 1][j];
  }
  int res = 0;
  for (int i = 0; i <= m - k; i++) res = max(res, nxt[i]);
  cout << res << "\n";
}
