#include <bits/stdc++.h>
using namespace std;
const int N = 2e4 + 30;
mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());
int n, m, k, a[51][N], dp[50][N], ans;
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &a[i][j]);
      a[i][j] += a[i][j - 1];
    }
  }
  for (int i = 1; i + k <= m + 1; i++) {
    dp[0][i] = a[0][i + k - 1] - a[0][i - 1];
    ans = max(ans, dp[0][i]);
  }
  for (int i = 1; i < n; i++) {
    int pre = 0;
    for (int j = 1; j <= m; j++) pre = max(pre, dp[i - 1][j]);
    deque<pair<int, int>> q;
    for (int j = 1; j + k <= m + 1; j++) {
      while (q.size() && q.front().second + k <= j) q.pop_front();
      if (j - k > 0)
        pre = max(pre, dp[i - 1][j - k] + a[i][j - 1] - a[i][j - k - 1]);
      dp[i][j] = pre + a[i][j + k - 1] - a[i][j - 1];
      if (!q.empty()) {
        int temp = q.front().first + a[i][j - 1] - a[i][q.front().second - 1];
        dp[i][j] = max(dp[i][j], a[i][j + k - 1] - a[i][j - 1] + temp);
      }
      while (q.size()) {
        int temp = q.back().first + a[i][j] - a[i][q.back().second - 1];
        int temp1 = dp[i - 1][j] + a[i][j] - a[i][j - 1];
        if (temp > temp1) break;
        q.pop_back();
      }
      q.push_back({dp[i - 1][j], j});
      ans = max(ans, dp[i][j]);
    }
    pre = 0;
    q.clear();
    for (int j = m - k + 1; j > 0; j--) {
      if (j + 2 * k - 1 <= m)
        pre =
            max(pre, dp[i - 1][j + k] + a[i][j + 2 * k - 1] - a[i][j + k - 1]);
      dp[i][j] = max(dp[i][j], pre + a[i][j + k - 1] - a[i][j - 1]);
      while (q.size() && q.front().second >= j + k) q.pop_front();
      dp[i][j] = max(dp[i][j], pre + a[i][j + k - 1] - a[i][j - 1]);
      if (!q.empty()) {
        int temp =
            q.front().first + a[i][q.front().second + k - 1] - a[i][j + k - 1];
        dp[i][j] = max(dp[i][j], a[i][j + k - 1] - a[i][j - 1] + temp);
      }
      while (q.size()) {
        int temp = q.back().first + a[i][q.back().second + k - 1] - a[i][j - 1];
        int temp1 = dp[i - 1][j] + a[i][j + k - 1] - a[i][j - 1];
        if (temp > temp1) break;
        q.pop_back();
      }
      q.push_back({dp[i - 1][j], j});
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << endl;
}
