#include <bits/stdc++.h>
using namespace std;
const int MM = 2e4 + 5;
struct Node {
  int l, r, lz, mx;
} seg[MM * 4];
int n, m, k, dp[55][MM], a[55][MM], b[55][MM];
void build(int u, int l, int r, int i) {
  seg[u].l = l;
  seg[u].r = r;
  seg[u].lz = 0;
  if (l == r) {
    seg[u].mx = dp[i - 1][l];
    return;
  }
  int mid = (l + r) / 2;
  build(u * 2, l, mid, i);
  build(u * 2 + 1, mid + 1, r, i);
  seg[u].mx = max(seg[u * 2].mx, seg[u * 2 + 1].mx);
}
void upd(int u, int l, int r, int v);
void push(int u) {
  if (seg[u].lz == 0) return;
  for (int i = 0; i < 2; i++) {
    upd(u * 2 + i, seg[u * 2 + i].l, seg[u * 2 + i].r, seg[u].lz);
  }
  seg[u].lz = 0;
}
void upd(int u, int l, int r, int v) {
  if (seg[u].l == l && seg[u].r == r) {
    seg[u].mx += v;
    seg[u].lz += v;
    return;
  }
  push(u);
  int mid = (seg[u].l + seg[u].r) / 2;
  if (r <= mid)
    upd(u * 2, l, r, v);
  else if (l > mid)
    upd(u * 2 + 1, l, r, v);
  else
    upd(u * 2, l, mid, v), upd(u * 2 + 1, mid + 1, r, v);
  seg[u].mx = max(seg[u * 2].mx, seg[u * 2 + 1].mx);
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      b[i][j] = a[i][j];
      a[i][j] += a[i][j - 1];
    }
  }
  for (int i = 1; i + k - 1 <= m; i++) {
    dp[1][i] = a[1][i + k - 1] - a[1][i - 1] + a[2][i + k - 1] - a[2][i - 1];
  }
  for (int i = 2; i <= n; i++) {
    build(1, 1, m, i);
    auto get_sum = [&](int l, int r) {
      int val = a[i][r] - a[i][l - 1];
      if (i != n) val += a[i + 1][r] - a[i + 1][l - 1];
      return val;
    };
    for (int j = 1; j <= k; j++) {
      int l = max(j - k + 1, 1), r = j;
      if (l <= r) upd(1, l, r, -b[i][j]);
    }
    dp[i][1] = seg[1].mx + get_sum(1, k);
    for (int j = k + 1; j <= m; j++) {
      int st = j - k + 1;
      int pos = j - k;
      int l = max(pos - k + 1, 1), r = pos;
      if (l <= r) upd(1, l, r, b[i][pos]);
      pos = j;
      l = max(pos - k + 1, 1), r = pos;
      if (l <= r) upd(1, l, r, -b[i][pos]);
      dp[i][st] = seg[1].mx + get_sum(st, st + k - 1);
    }
  }
  int ans = 0;
  for (int i = 1; i + k - 1 <= m; i++) ans = max(ans, dp[n][i]);
  cout << ans << "\n";
}
