#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007LL;
int n, m, k;
int mat[52][40005];
int sum[52][40005];
long long dp[52][40005];
int main() {
  cin >> n >> m >> k;
  memset(sum, 0, sizeof(sum));
  memset(mat, 0, sizeof(mat));
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> mat[i][j];
    }
    for (int j = 1; j <= m + k - 1; ++j) {
      sum[i][j] = sum[i][j - 1] + mat[i][j];
    }
  }
  memset(dp, 0, sizeof(dp));
  for (int j = 1; j <= m; ++j) {
    dp[2][j] =
        sum[1][j + k - 1] - sum[1][j - 1] + sum[2][j + k - 1] - sum[2][j - 1];
  }
  for (int i = 3; i <= n + 1; ++i) {
    deque<int> dq;
    long long lmx = 0;
    for (int j = 1; j <= m; ++j) {
      while (!dq.empty() && dq.front() <= j - k) {
        lmx = max(lmx, dp[i - 1][dq.front()]);
        dq.pop_front();
      }
      long long curv =
          dp[i - 1][j] - (long long)(sum[i - 1][j + k - 1] - sum[i - 1][j - 1]);
      while (!dq.empty()) {
        int idx = dq.back();
        long long prev = dp[i - 1][idx] - (long long)(sum[i - 1][idx + k - 1] -
                                                      sum[i - 1][j - 1]);
        if (curv >= prev) {
          dq.pop_back();
        } else {
          break;
        }
      }
      dq.push_back(j);
      int idx = dq.front();
      long long det = sum[i - 1][j + k - 1] - sum[i - 1][j - 1] +
                      sum[i][j + k - 1] - sum[i][j - 1];
      dp[i][j] = max(dp[i][j], lmx + det);
      dp[i][j] = max(dp[i][j], det + dp[i - 1][idx] -
                                   (long long)(sum[i - 1][idx + k - 1] -
                                               sum[i - 1][j - 1]));
    }
    while (!dq.empty()) {
      dq.pop_back();
    }
    long long rmx = 0;
    for (int j = m; j >= 1; --j) {
      while (!dq.empty() && dq.front() >= j + k) {
        rmx = max(rmx, dp[i - 1][dq.front()]);
        dq.pop_front();
      }
      long long curv =
          dp[i - 1][j] - (long long)(sum[i - 1][j + k - 1] - sum[i - 1][j - 1]);
      while (!dq.empty()) {
        int idx = dq.back();
        long long prev = dp[i - 1][idx] - (long long)(sum[i - 1][j + k - 1] -
                                                      sum[i - 1][idx - 1]);
        if (curv >= prev) {
          dq.pop_back();
        } else {
          break;
        }
      }
      dq.push_back(j);
      int idx = dq.front();
      long long det = sum[i - 1][j + k - 1] - sum[i - 1][j - 1] +
                      sum[i][j + k - 1] - sum[i][j - 1];
      dp[i][j] = max(dp[i][j], rmx + det);
      dp[i][j] = max(dp[i][j], det + dp[i - 1][idx] -
                                   (long long)(sum[i - 1][j + k - 1] -
                                               sum[i - 1][idx - 1]));
    }
  }
  long long ans = 0;
  for (int j = 1; j <= m; ++j) {
    ans = max(ans, dp[n + 1][j]);
  }
  cout << ans << endl;
  return 0;
}
