#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e4 + 6;
int n, m, k;
int ani[55][maxn], dp[55][maxn], sum[55][maxn];
struct data {
  int l, r;
  int mx;
  int tag;
} tr[maxn * 4];
void build(int k, int s, int t) {
  tr[k].l = s;
  tr[k].r = t;
  if (s == t) {
    tr[k].mx = 0;
    return;
  }
  int mid = (s + t) >> 1;
  build(k << 1, s, mid);
  build(k << 1 | 1, mid + 1, t);
  tr[k].mx = max(tr[k << 1].mx, tr[k << 1 | 1].mx);
}
void pushdown(int k) {
  tr[k << 1].tag += tr[k].tag;
  tr[k << 1 | 1].tag += tr[k].tag;
  tr[k << 1].mx += tr[k].tag;
  tr[k << 1 | 1].mx += tr[k].tag;
  tr[k].tag = 0;
}
void update(int k, int a, int b, int x) {
  int l = tr[k].l, r = tr[k].r;
  if (a == l && r == b) {
    tr[k].tag += x;
    tr[k].mx += x;
    return;
  }
  if (tr[k].tag) pushdown(k);
  int mid = (l + r) >> 1;
  if (b <= mid)
    update(k << 1, a, b, x);
  else if (a > mid)
    update(k << 1 | 1, a, b, x);
  else {
    update(k << 1, a, mid, x);
    update(k << 1 | 1, mid + 1, b, x);
  }
  tr[k].mx = max(tr[k << 1].mx, tr[k << 1 | 1].mx);
}
int ask(int k, int a, int b) {
  int l = tr[k].l, r = tr[k].r;
  if (a == l && b == r) {
    return tr[k].mx;
  }
  if (tr[k].tag) pushdown(k);
  int mid = (l + r) >> 1;
  if (b <= mid)
    return ask(k << 1, a, b);
  else if (a > mid)
    return ask(k << 1 | 1, a, b);
  else
    return max(ask(k << 1, a, mid), ask(k << 1 | 1, mid + 1, b));
}
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> ani[i][j];
      sum[i][j] = sum[i][j - 1] + ani[i][j];
    }
  }
  for (int i = 1; i <= m - k + 1; i++)
    dp[1][i] = (sum[1][i + k - 1] - sum[1][i - 1]) +
               (sum[2][i + k - 1] - sum[2][i - 1]);
  for (int i = 2; i <= n; i++) {
    memset(tr, 0, sizeof(tr));
    build(1, 1, 2 * m);
    for (int j = 1; j <= m; j++) update(1, j, j, dp[i - 1][j]);
    for (int j = 1; j <= k; j++) update(1, 1, j, -ani[i][j]);
    for (int j = 1; j <= m - k + 1; j++) {
      dp[i][j] =
          max(dp[i][j], ask(1, 1, m) + sum[i][j + k - 1] - sum[i][j - 1] +
                            sum[i + 1][j + k - 1] - sum[i + 1][j - 1]);
      update(1, max(1, j - k + 1), j, ani[i][j]);
      update(1, j + 1, j + k, -ani[i][j + k]);
    }
  }
  int ans = -1;
  for (int i = 1; i <= m; i++) ans = max(ans, dp[n][i]);
  cout << ans << endl;
}
