#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e4 + 5;
int sum[55][maxn], d[55][maxn];
int dp[55][maxn];
int tree[maxn << 2], tag[maxn << 2];
int n, m, k, lim;
inline void up(int t) { tree[t] = max(tree[t << 1], tree[t << 1 | 1]); }
inline void down(int t) {
  if (tag[t]) {
    tag[t << 1] += tag[t], tag[t << 1 | 1] += tag[t];
    tree[t << 1] += tag[t], tree[t << 1 | 1] += tag[t];
    tag[t] = 0;
  }
}
inline void build(int tim, int l, int r, int t) {
  if (l == r) {
    tree[t] = dp[tim][l] + sum[tim + 1][l + k - 1] - sum[tim + 1][l - 1];
    return;
  }
  int mid = (l + r) >> 1;
  build(tim, l, mid, t << 1);
  build(tim, mid + 1, r, t << 1 | 1);
  up(t);
}
inline void update(int ll, int rr, int l, int r, int x, int t) {
  if (ll <= l && r <= rr) {
    tree[t] += x, tag[t] += x;
    return;
  }
  int mid = (l + r) >> 1;
  down(t);
  if (ll <= mid) update(ll, rr, l, mid, x, t << 1);
  if (rr > mid) update(ll, rr, mid + 1, r, x, t << 1 | 1);
  up(t);
}
inline void del(int tim, int pos) {
  if (pos) update(max(1, pos - k + 1), min(lim, pos), 1, lim, d[tim][pos], 1);
}
inline void add(int tim, int pos) {
  if (pos) update(max(1, pos - k + 1), min(lim, pos), 1, lim, -d[tim][pos], 1);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> n >> m >> k;
  lim = m - k + 1;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      cin >> d[i][j], sum[i][j] = sum[i][j - 1] + d[i][j];
  for (int i = 1; i <= n; ++i) {
    if (i > 1) {
      for (int j = 1; j < k; ++j) add(i, j);
    }
    for (int j = 1; j + k - 1 <= m; ++j) {
      int l = j, r = j + k - 1;
      if (i == 1)
        dp[i][j] = sum[i][r] - sum[i][l - 1];
      else
        del(i, l - 1), add(i, r),
            dp[i][j] = sum[i][r] - sum[i][l - 1] + tree[1];
    }
    memset(tree, 0, sizeof(int) * (4 * lim));
    memset(tag, 0, sizeof(int) * (4 * lim));
    if (i < n) build(i, 1, lim, 1);
  }
  int ans = 0;
  for (int i = 1; i <= lim; ++i) ans = max(ans, dp[n][i]);
  cout << ans << '\n';
  return 0;
}
