#include <bits/stdc++.h>
using namespace std;
int f[51][20007];
int n, m, k, a[52][40007], Max[100007], Tar[100007];
inline void Pushdown(int id, int l, int r) {
  if (l != r) {
    int lid = id << 1, rid = lid + 1;
    Max[lid] += Tar[id], Max[rid] += Tar[id];
    Tar[lid] += Tar[id], Tar[rid] += Tar[id];
  }
  Tar[id] = 0;
}
void Modify(int id, int l, int r, int ql, int qr, int del) {
  Pushdown(id, l, r);
  if (l >= ql && r <= qr) {
    Max[id] += del;
    Tar[id] += del;
    return;
  }
  int mid = (l + r) >> 1, lid = id << 1, rid = lid + 1;
  if (ql <= mid) Modify(lid, l, mid, ql, qr, del);
  if (qr > mid) Modify(rid, mid + 1, r, ql, qr, del);
  Max[id] = max(Max[lid], Max[rid]);
}
void Build(int id, int l, int r, int Now) {
  Tar[id] = 0;
  if (l == r) {
    Max[id] = f[Now][l];
    return;
  }
  int mid = (l + r) >> 1, lid = id << 1, rid = lid + 1;
  Build(lid, l, mid, Now);
  Build(rid, mid + 1, r, Now);
  Max[id] = max(Max[lid], Max[rid]);
}
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]), a[i][j] += a[i][j - 1];
    for (int p = 1; p <= k; ++p) a[i][m + p] = a[i][m];
  }
  for (int p = 1; p <= m; ++p)
    f[1][p] = a[1][p + k - 1] - a[1][p - 1] + a[2][p + k - 1] - a[2][p - 1];
  Build(1, 1, m, 1);
  for (int i = 2; i <= n; ++i) {
    for (int j = 1; j < k; ++j)
      Modify(1, 1, m, j - k + 1, j, -a[i][j] + a[i][j - 1]);
    for (int s = 1; s <= m; ++s) {
      Modify(1, 1, m, s, s + k - 1, -a[i][s + k - 1] + a[i][s + k - 2]);
      f[i][s] = Max[1] + a[i][s + k - 1] - a[i][s - 1] + a[i + 1][s + k - 1] -
                a[i + 1][s - 1];
      Modify(1, 1, m, s - k + 1, s, a[i][s] - a[i][s - 1]);
    }
    Build(1, 1, m, i);
  }
  printf("%d\n", Max[1]);
  return 0;
}
