#include <bits/stdc++.h>
using namespace std;
const int MAXN = 20100;
struct seg {
  seg *fe, *fd;
  long long meio, l, r, mex, lazy;
  seg(long long x, long long y) {
    l = x, r = y;
    meio = (x + y) / 2;
    mex = 0;
    lazy = 0;
    if (l == r) return;
    fe = new seg(x, meio);
    fd = new seg(meio + 1, y);
  }
  void lazyup() {
    if (lazy == 0) return;
    mex += lazy;
    if (l != r) fe->lazy += lazy, fd->lazy += lazy;
    lazy = 0;
  }
  void up(long long a, long long b, long long novo) {
    lazyup();
    if (l >= a && r <= b) {
      lazy += novo;
      lazyup();
      return;
    }
    if (l > b || r < a) return;
    fe->up(a, b, novo), fd->up(a, b, novo);
    mex = max(fe->mex, fd->mex);
  }
  long long get() {
    lazyup();
    return mex;
  }
  void printa() {
    lazyup();
    if (l == r) {
      cout << mex << " ";
      return;
    }
    fe->printa(), fd->printa();
  }
};
long long v[55][MAXN];
long long memo[55][MAXN];
long long pre[MAXN];
signed main() {
  memset(memo, 0, sizeof memo);
  memset(pre, 0, sizeof pre);
  long long n, m, k;
  cin >> n >> m >> k;
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) cin >> v[i][j];
  long long resp = 0;
  for (long long i = n; i >= 1; i--) {
    long long soma = 0;
    if (i == n) {
      for (long long j = 1; j <= m; j++) {
        soma += v[i][j];
        if (j >= k)
          memo[i][j - k + 1] = soma, soma -= v[i][j - k + 1],
                          resp = max(resp, memo[i][j - k + 1]);
      }
      continue;
    }
    seg st(1, MAXN);
    for (long long j = 1; j <= m; j++) st.up(j, j, memo[i + 1][j]);
    for (long long j = 1; j <= m; j++) {
      st.up(max(j - k + 1, (long long)1), j, -v[i + 1][j]);
      soma += v[i + 1][j] + v[i][j];
      if (j >= k) {
        memo[i][j - k + 1] = soma + st.get();
        resp = max(resp, memo[i][j - k + 1]);
        long long a = v[i + 1][j - k + 1];
        st.up(max(j - 2 * (k - 1), (long long)1), j - k + 1,
              v[i + 1][j - k + 1]);
        soma -= v[i + 1][j - k + 1] + v[i][j - k + 1];
      }
    }
  }
  cout << resp << endl;
}
