#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long f = 1, ans = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    ans = ans * 10 + c - '0';
    c = getchar();
  }
  return ans * f;
}
const long long MAXN = 51;
const long long MAXM = 20001;
struct Segment_Tree {
  long long Maxn[MAXM << 2], tag[MAXM << 2];
  void Init() {
    memset(Maxn, 0, sizeof(Maxn));
    memset(tag, 0, sizeof(tag));
  }
  void pushdown(long long k, long long l, long long r) {
    if (!tag[k]) return;
    tag[k << 1] += tag[k], tag[k << 1 | 1] += tag[k];
    Maxn[k << 1] += tag[k], Maxn[k << 1 | 1] += tag[k];
    tag[k] = 0;
    return;
  }
  void Add(long long k, long long l, long long r, long long x, long long y,
           long long w) {
    if (x <= l && r <= y) {
      Maxn[k] += w;
      tag[k] += w;
      return;
    }
    long long mid = l + r >> 1;
    pushdown(k, l, r);
    if (x <= mid) Add(k << 1, l, mid, x, y, w);
    if (mid < y) Add(k << 1 | 1, mid + 1, r, x, y, w);
    Maxn[k] = max(Maxn[k << 1], Maxn[k << 1 | 1]);
    return;
  }
  long long Query() { return Maxn[1]; }
} T;
long long N, M, K, A[MAXN][MAXM], S[MAXN][MAXM], f[MAXN][MAXM];
signed main() {
  N = read(), M = read(), K = read();
  for (long long i = 1; i <= N; i++)
    for (long long j = 1; j <= M; j++)
      A[i][j] = read(), S[i][j] = S[i][j - 1] + A[i][j];
  for (long long i = 1; i <= N; i++)
    for (long long j = 1; j <= M - K + 1; j++)
      f[i][j] = S[1][j + K - 1] - S[1][j - 1] + S[2][j + K - 1] - S[2][j - 1];
  for (long long i = 2; i <= N; i++) {
    T.Init();
    for (long long j = 1; j <= M; j++) T.Add(1, 1, M, j, j, f[i - 1][j]);
    for (long long j = 1; j <= K; j++) T.Add(1, 1, M, 1, j, -A[i][j]);
    for (long long j = 1; j <= M - K + 1; j++) {
      f[i][j] = T.Query() + S[i][j + K - 1] - S[i][j - 1] +
                S[i + 1][j + K - 1] - S[i + 1][j - 1];
      T.Add(1, 1, M, max(1ll, j - K + 1), j, A[i][j]);
      T.Add(1, 1, M, j + 1, j + K, -A[i][j + K]);
    }
  }
  long long Maxn = 0;
  for (long long i = 1; i <= M - K + 1; i++) Maxn = max(Maxn, f[N][i]);
  printf("%lld\n", Maxn);
  return 0;
}
