#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 2e5;
int a[52][40001];
int sum[52][40001];
int dp[52][40001];
int n, m, k;
int cost(int h, int i, int j) {
  int ans = sum[h][j + k - 1] - sum[h][j - 1] + sum[h - 1][j + k - 1] -
            sum[h - 1][j - 1];
  int l = max(i, j), r = min(i + k - 1, j + k - 1);
  if (l <= r) ans -= sum[h - 1][r] - sum[h - 1][l - 1];
  return ans;
}
void solve1(int l, int r, int x, int y, int now) {
  if (l > r || x == -1 || y == -1) return;
  int mid = (l + r) >> 1;
  int pos = -1;
  int ans = -1;
  for (int i = x; i <= y && i <= mid; ++i) {
    int tmp = cost(now, i, mid) + dp[now - 1][i];
    if (tmp > ans) ans = tmp, pos = i;
  }
  dp[now][mid] = max(dp[now][mid], ans);
  solve1(l, mid - 1, x, pos, now);
  solve1(mid + 1, r, pos, y, now);
}
void solve2(int l, int r, int x, int y, int now) {
  if (l > r || x == -1 || y == -1) return;
  int mid = (l + r) >> 1;
  int pos = -1;
  int ans = -1;
  for (int i = max(mid, x); i <= y; ++i) {
    int tmp = cost(now, i, mid) + dp[now - 1][i];
    if (tmp > ans) ans = tmp, pos = i;
  }
  dp[now][mid] = max(dp[now][mid], ans);
  solve2(l, mid - 1, x, pos, now);
  solve2(mid + 1, r, pos, y, now);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) cin >> a[i][j];
  for (int i = 1; i <= n + 1; ++i)
    for (int j = 1; j <= m + k; ++j) sum[i][j] = sum[i][j - 1] + a[i][j];
  for (int i = 1; i <= m; ++i)
    dp[2][i] =
        sum[2][i + k - 1] - sum[2][i - 1] + sum[1][i + k - 1] - sum[1][i - 1];
  for (int i = 3; i <= n + 1; ++i) solve1(1, m, 1, m, i), solve2(1, m, 1, m, i);
  int ans = 0;
  for (int i = 1; i <= m; ++i) ans = max(ans, dp[n + 1][i]);
  cout << ans << endl;
  return 0;
}
