#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e4 + 42;
int n, m, k;
int d[55][maxn], dp[55][maxn], s[55][maxn];
int val[maxn << 2], tag[maxn << 2];
int g;
void build(int day, int l, int r, int rt) {
  if (l == r) {
    val[rt] = dp[day][l] + s[day + 1][l + k - 1] - s[day + 1][l - 1];
    return;
  }
  int mid = l + r >> 1;
  build(day, l, mid, rt << 1);
  build(day, mid + 1, r, rt << 1 | 1);
  val[rt] = max(val[rt << 1], val[rt << 1 | 1]);
}
void pushd(int rt) {
  if (!tag[rt]) return;
  val[rt << 1] += tag[rt];
  val[rt << 1 | 1] += tag[rt];
  tag[rt << 1] += tag[rt];
  tag[rt << 1 | 1] += tag[rt];
  tag[rt] = 0;
}
void upd(int a, int b, int l, int r, int rt, int v) {
  if (a <= l && r <= b) {
    val[rt] += v, tag[rt] += v;
    return;
  }
  pushd(rt);
  int mid = l + r >> 1;
  if (a <= mid) upd(a, b, l, mid, rt << 1, v);
  if (b > mid) upd(a, b, mid + 1, r, rt << 1 | 1, v);
  val[rt] = max(val[rt << 1], val[rt << 1 | 1]);
}
void upd(int day, int pos) {
  if (pos) upd(max(1, pos - k + 1), min(g, pos), 1, g, 1, -d[day][pos]);
}
void del(int day, int pos) {
  if (pos) upd(max(1, pos - k + 1), min(g, pos), 1, g, 1, d[day][pos]);
}
signed main() {
  ios ::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  cin >> n >> m >> k;
  g = m - k + 1;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> d[i][j];
      s[i][j] = s[i][j - 1] + d[i][j];
    }
  for (int i = 1; i <= n; i++) {
    if (i > 1) {
      for (int j = 1; j < k; j++) upd(i, j);
    }
    for (int j = 1; j + k - 1 <= m; j++) {
      int l = j, r = j + k - 1;
      if (i == 1)
        dp[1][j] = s[1][r] - s[1][l - 1];
      else {
        del(i, l - 1);
        upd(i, r);
        dp[i][j] = s[i][r] - s[i][l - 1] + val[1];
      }
    }
    memset(val, 0, sizeof(val));
    memset(tag, 0, sizeof(tag));
    if (i < n) build(i, 1, g, 1);
  }
  int ans = 0;
  for (int i = 1; i <= g; i++) ans = max(ans, dp[n][i]);
  cout << ans << '\n';
  return 0;
}
