#include <bits/stdc++.h>
using namespace std;
const int N = 20005;
const int M = 30000;
const long long base = 137;
const long long mod = 1000000007LL;
using namespace std;
int n, m, k, sum[55][N], a[55][N * 2], F[55][N], IT[N * 4], lazy[N * 4];
int b[N];
void build(int k, int l, int r, int index) {
  lazy[k] = 0;
  if (l == r) {
    IT[k] = F[index][l] + b[l];
    return;
  }
  int mid = (l + r) >> 1;
  build((k << 1), l, mid, index);
  build(((k << 1) + 1), mid + 1, r, index);
  IT[k] = max(IT[(k << 1)], IT[((k << 1) + 1)]);
}
void laz(int k, int l, int r) {
  if (lazy[k] == 0) return;
  IT[k] += lazy[k];
  if (l != r) {
    lazy[(k << 1)] += lazy[k];
    lazy[((k << 1) + 1)] += lazy[k];
  }
  lazy[k] = 0;
}
void update(int k, int l, int r, int u, int v, int val) {
  laz(k, l, r);
  if (u > v) return;
  if (l > v || r < u) return;
  if (l >= u && r <= v) {
    lazy[k] += val;
    laz(k, l, r);
    return;
  }
  int mid = (l + r) >> 1;
  update((k << 1), l, mid, u, v, val);
  update(((k << 1) + 1), mid + 1, r, u, v, val);
  IT[k] = max(IT[(k << 1)], IT[((k << 1) + 1)]);
}
int get(int k, int l, int r, int u, int v) {
  laz(k, l, r);
  if (l > v || r < u) return 0;
  if (l >= u && r <= v) return IT[k];
  int mid = (l + r) >> 1;
  return max(get((k << 1), l, mid, u, v),
             get(((k << 1) + 1), mid + 1, r, u, v));
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      cin >> a[i][j];
      sum[i][j] = sum[i][j - 1] + a[i][j];
    }
  for (int j = 1; j <= m; ++j)
    F[1][j] = sum[1][min(j + k - 1, m)] - sum[1][j - 1];
  for (int i = 2; i <= n; ++i) {
    for (int j = k + 1; j <= m; ++j)
      b[j] = sum[i][min(j + k - 1, m)] - sum[i][j - 1] + sum[i][k];
    for (int j = 1; j <= k; ++j) b[j] = sum[i][min(j + k - 1, m)];
    build(1, 1, m, i - 1);
    F[i][1] = get(1, 1, m, 1, m);
    for (int j = 2; j <= m; ++j) {
      update(1, 1, m, max(1, j - k), j - 1, a[i][j + k - 1]);
      update(1, 1, m, j, min(j + k - 1, m), -a[i][j - 1]);
      update(1, 1, m, 1, j - k - 1, -a[i][j - 1]);
      update(1, 1, m, 1, j - k - 1, a[i][j + k - 1]);
      update(1, 1, m, j + k, m, -a[i][j - 1]);
      update(1, 1, m, j + k, m, a[i][j + k - 1]);
      F[i][j] = get(1, 1, m, 1, m);
    }
  }
  int res = 0;
  for (int i = 1; i <= m; ++i) res = max(res, F[n][i]);
  cout << res << '\n';
  return 0;
}
