#include <bits/stdc++.h>
using namespace std;
long long N, M, K, ans;
long long a[105][21005];
long long sum[105][21005];
long long tree[21005 * 8];
long long lazy[21005 * 8];
long long dp[21005 * 8];
void updLazy(long long x, long long l, long long r) {
  if (!lazy[x]) return;
  tree[x] += lazy[x];
  lazy[2 * x + 1] += lazy[x];
  lazy[2 * x + 2] += lazy[x];
  lazy[x] = 0;
}
void upd(long long x, long long l, long long r, long long lq, long long rq,
         long long v, bool t) {
  if (r < l) return;
  updLazy(x, l, r);
  if (l > rq or r < lq) return;
  if (l >= lq && r <= rq) {
    if (t) tree[x] = lazy[x] = 0;
    lazy[x] += v;
    updLazy(x, l, r);
    return;
  }
  long long mid = (l + r) / 2;
  upd(2 * x + 1, l, mid, lq, rq, v, t);
  upd(2 * x + 2, mid + 1, r, lq, rq, v, t);
  tree[x] = max(tree[2 * x + 1], tree[2 * x + 2]);
}
long long suma2(long long i, long long j) {
  return sum[i][j + K - 1] - sum[i][j - 1] + sum[i + 1][j + K - 1] -
         sum[i + 1][j - 1];
}
int main() {
  cin >> N >> M >> K;
  for (long long i = 1; i <= N; i++)
    for (long long j = 1; j <= M; j++) {
      cin >> a[i][j];
      sum[i][j] = sum[i][j - 1] + a[i][j];
    }
  for (long long i = 1; i <= N; i++)
    for (long long j = M + 1; j <= M; j++) sum[i][j] = sum[i][j - 1];
  for (long long i = N; i >= 1; i--) {
    for (long long j = 1; j + K - 1 <= M; j++) {
      if (j <= K)
        upd(0, 1, M, j, j, dp[j] - sum[i + 1][K] + sum[i + 1][j - 1], 1);
      else
        upd(0, 1, M, j, j, dp[j], 1);
    }
    for (long long j = 1; j + K - 1 <= M; j++) {
      dp[j] = suma2(i, j) + tree[0];
      ans = max(ans, dp[j]);
      upd(0, 1, M, max(1LL, j - K + 1), j, a[i + 1][j], 0);
      upd(0, 1, M, j + 1, min(M, j + K), -a[i + 1][j + K], 0);
      ans = max(ans, dp[j]);
    }
  }
  cout << ans << "\n";
  return 0;
}
