#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
const int maxm = 2e4 + 5;
int n, m, k;
int a[maxn][maxm];
int dp[maxn][maxm];
int sum[maxn][maxm];
int c[maxn][maxm];
int q[maxm];
void init() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) c[i][j] = c[i][j - 1] + a[i][j];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= k; j++) sum[i][1] += a[i][j];
    for (int j = 2; j + k - 1 <= m; j++)
      sum[i][j] = sum[i][j - 1] - a[i][j - 1] + a[i][j + k - 1];
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j + k - 1 <= m; j++) sum[i][j] += sum[i + 1][j];
}
void solve() {
  for (int j = 1; j + k - 1 <= m; j++) dp[1][j] = sum[1][j];
  for (int i = 2; i <= n; i++) {
    int pre = 0;
    int l = 1, r = 0;
    for (int j = 1; j + k - 1 <= m; 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]);
      while (l <= r && q[l] < j - k + 1) l++;
      while (l <= r && dp[i - 1][q[r]] - c[i][q[r] + k - 1] <
                           dp[i - 1][j] - c[i][j + k - 1])
        r--;
      q[++r] = j;
      int cost = dp[i - 1][q[l]] - c[i][q[l] + k - 1];
      int x = c[i][j - 1] + sum[i][j];
      dp[i][j] = max(dp[i][j], cost + x);
    }
    int suf = 0;
    l = 1, r = 0;
    for (int j = m - k + 1; j >= 1; j--) {
      if (j + 2 * k - 1 <= m) suf = max(suf, dp[i - 1][j + k]);
      if (j + 2 * k - 1 <= m) dp[i][j] = max(dp[i][j], suf + sum[i][j]);
      while (l <= r && q[l] > j + k - 1) l++;
      while (l <= r &&
             dp[i - 1][q[r]] + c[i][q[r] - 1] < dp[i - 1][j] + c[i][j - 1])
        r--;
      q[++r] = j;
      int cost = dp[i - 1][q[l]] + c[i][q[l] - 1];
      int x = -c[i][j + k - 1] + sum[i][j];
      dp[i][j] = max(dp[i][j], cost + x);
    }
  }
  int ans = 0;
  for (int j = 1; j + k - 1 <= m; j++) ans = max(ans, dp[n][j]);
  printf("%d\n", ans);
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
  init();
  solve();
  return 0;
}
