#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const long long inf = 5e9 + 7;
const long long max_n = 51, max_m = 1 << 16;
long long n, m, k;
long long a[max_n][max_m], dp[max_n][max_m];
void scan() {
  cin >> n >> m >> k;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++)
      cin >> a[i][j], a[i][j] = a[i][j] + (j == 0 ? 0 : a[i][j - 1]);
  }
}
long long get(long long id, long long l, long long r) {
  return a[id][r] - (l == 0 ? 0 : a[id][l - 1]);
}
long long mx[2 * max_m], push[2 * max_m];
void upd(long long v, long long x) {
  push[v] += x;
  mx[v] += x;
}
void pushing(long long v) {
  upd(v * 2, push[v]);
  upd(v * 2 + 1, push[v]);
  push[v] = 0;
}
long long segget() { return mx[1]; }
void segset(long long l, long long r, long long x, long long v = 1,
            long long tl = 0, long long tr = max_m - 1) {
  if (tl > r || tr < l) return;
  if (tl >= l && tr <= r) {
    upd(v, x);
    return;
  }
  pushing(v);
  long long mid = (tl + tr) / 2;
  segset(l, r, x, v * 2, tl, mid);
  segset(l, r, x, v * 2 + 1, mid + 1, tr);
  mx[v] = max(mx[v * 2], mx[v * 2 + 1]);
}
void build(long long id) {
  for (long long i = 1; i < 2 * max_m; i++) mx[i] = push[i] = 0;
  for (long long i = 0; i < m; i++) segset(i, i, dp[id][i]);
}
void solve() {
  scan();
  vector<long long> pref(m), suf(m + k);
  for (long long i = 0; i < n; i++) {
    if (i != 0) build(i - 1);
    for (long long j = -k; j < m + k; j++) {
      if (i != 0) {
        if (j - 1 >= 0 && j - 1 < m) segset(j - k, j - 1, get(i, j - 1, j - 1));
        if (j + k - 1 >= 0 && j + k - 1 < m)
          segset(j, j + k - 1, -get(i, j + k - 1, j + k - 1));
        if (j >= 0 && j < m) {
          dp[i][j] = segget();
        }
      }
      if (j >= 0 && j < m)
        dp[i][j] += get(i, j, j + k - 1) + get(i + 1, j, j + k - 1);
    }
    for (long long j = 0; j < m; j++)
      pref[j] = max(dp[i][j], (j == 0 ? 0 : pref[j - 1]));
    for (long long j = m - 1; j >= 0; j--) suf[j] = max(dp[i][j], suf[j + 1]);
  }
  long long res = pref[m - 1];
  cout << res << endl;
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  cout.precision(10);
  solve();
}
