#include <bits/stdc++.h>
using namespace std;
int a[51][20001], pre[51][20001], dp[51][20001];
inline int sum(int i, int jl, int jr) { return pre[i][jr + 1] - pre[i][jl]; }
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) cin >> a[i][j];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) pre[i][j + 1] = a[i][j] + pre[i][j];
  }
  for (int i = 0; i < n; i++) {
    int l[20001] = {0}, r[20001] = {0};
    if (i) {
      for (int j = 0; j <= m - k; j++) {
        l[j] = max(dp[i][j] + sum(i, j, j + k - 1), j ? l[j - 1] : 0);
      }
      for (int j = m - k; j >= 0; j--) {
        r[j] = max(dp[i][j] + sum(i, j, j + k - 1), j < m - 1 ? r[j + 1] : 0);
      }
    }
    for (int j = 0; j <= m - k; j++) {
      dp[i + 1][j] = max(
          dp[i][j], max(j >= k ? l[j - k] : 0, j <= m - 2 * k ? r[j + k] : 0));
    }
    if (i) {
      deque<pair<int, int>> dq;
      for (int j = 0; j <= m - k; j++) {
        while (!dq.empty() && dq.front().first <= j - k) {
          dq.pop_front();
        }
        if (j) {
          while (!dq.empty() &&
                 dq.back().second < dp[i][j - 1] - sum(i, 0, j - 2)) {
            dq.pop_back();
          }
          dq.emplace_back(j - 1, dp[i][j - 1] - sum(i, 0, j - 2));
        }
        dp[i + 1][j] =
            max((dq.empty() ? 0 : dq.front().second + sum(i, 0, j - 1)),
                dp[i + 1][j]);
      }
      dq.clear();
      for (int j = m - k; j >= 0; j--) {
        while (!dq.empty() && dq.front().first >= j + k) {
          dq.pop_front();
        }
        if (j < m - k) {
          while (!dq.empty() &&
                 dq.back().second < dp[i][j + 1] - sum(i, j + k + 1, m - 1)) {
            dq.pop_back();
          }
          dq.emplace_back(j + 1, dp[i][j + 1] - sum(i, j + k + 1, m - 1));
        }
        dp[i + 1][j] =
            max((dq.empty() ? 0 : dq.front().second + sum(i, j + k, m - 1)),
                dp[i + 1][j]);
      }
    }
    for (int j = 0; j <= m - k; j++) dp[i + 1][j] += sum(i, j, j + k - 1);
  }
  int ans = 0;
  for (int i = 0; i <= m - k; i++) ans = max(dp[n][i], ans);
  cout << ans << endl;
}
