#include <bits/stdc++.h>
using namespace std;
int sum[55][20004];
deque<pair<int, int> > que;
int dp[55][20005];
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int num;
      cin >> num;
      sum[i][j] = sum[i][j - 1] + num;
    }
  }
  for (int i = 1; i <= m - k + 1; i++) {
    dp[1][i] =
        sum[1][i + k - 1] - sum[1][i - 1] + sum[2][i + k - 1] - sum[2][i - 1];
  }
  for (int i = 2; i <= n; i++) {
    que.clear();
    int pre = 0, suf = 0;
    for (int j = 1; j <= m - k + 1; j++) {
      if (j >= k + 1) pre = max(pre, dp[i - 1][j - k]);
      if (j >= k + 1)
        dp[i][j] = max(dp[i][j], pre + sum[i][j + k - 1] - sum[i][j - 1] +
                                     sum[i + 1][j + k - 1] - sum[i + 1][j - 1]);
      while (que.size() and
             que.back().first <= dp[i - 1][j] - sum[i][j + k - 1])
        que.pop_back();
      que.push_back(pair<int, int>(dp[i - 1][j] - sum[i][j + k - 1], j));
      while (que.size() and que.front().second < j - k + 1) que.pop_front();
      dp[i][j] = max(dp[i][j], que.front().first + sum[i][j - 1] +
                                   sum[i + 1][j + k - 1] - sum[i + 1][j - 1] +
                                   sum[i][j + k - 1] - sum[i][j - 1]);
    }
    que.clear();
    for (int j = m - k + 1; j >= 1; j--) {
      if (j + k <= m - k + 1) suf = max(suf, dp[i - 1][j + k]);
      if (j + k <= m - k + 1)
        dp[i][j] = max(dp[i][j], suf + sum[i][j + k - 1] - sum[i][j - 1] +
                                     sum[i + 1][j + k - 1] - sum[i + 1][j - 1]);
      while (que.size() and que.back().first <= dp[i - 1][j] + sum[i][j - 1])
        que.pop_back();
      que.push_back(pair<int, int>(dp[i - 1][j] + sum[i][j - 1], j));
      while (que.size() and que.front().second > j + k - 1) que.pop_front();
      dp[i][j] = max(dp[i][j], que.front().first - sum[i][j + k - 1] +
                                   sum[i + 1][j + k - 1] - sum[i + 1][j - 1] +
                                   sum[i][j + k - 1] - sum[i][j - 1]);
    }
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) ans = max(ans, dp[n][i]);
  cout << ans << endl;
  return 0;
}
