#include <bits/stdc++.h>
using namespace std;
const int MOD = int(1e9) + 7;
const long long int MOD64 = (long long int)(1e18) + 7;
const int INF = 0x7fffffff;
const long long int INF64 = 0x7fffffffffffffff;
const int N = 2e4 + 200;
int a[60][N];
int sum[60][N];
int dp[60][N];
int t[4 * N], lazy[4 * N];
void update_lazy(int i, int lo, int hi) {
  if (lazy[i]) {
    t[i] += lazy[i];
    if (lo != hi) {
      lazy[i * 2] += lazy[i];
      lazy[i * 2 + 1] += lazy[i];
    }
    lazy[i] = 0;
  }
}
int update(int i, int lo, int hi, int l, int r, int val) {
  update_lazy(i, lo, hi);
  if (lo > r || hi < l) return t[i];
  if (l <= lo && hi <= r) {
    t[i] += val;
    if (lo != hi) {
      lazy[i * 2] += val;
      lazy[i * 2 + 1] += val;
    }
    return t[i];
  }
  int mid = (lo + hi) / 2;
  return t[i] = max(update(i * 2, lo, mid, l, r, val),
                    update(i * 2 + 1, mid + 1, hi, l, r, val));
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = int(1); i < int(n + 1); i++) {
    for (int j = int(1); j < int(m + 1); j++) {
      cin >> a[i][j];
      sum[i][j] = sum[i][j - 1] + a[i][j];
    }
  }
  int mm = m - k + 1;
  for (int i = int(1); i < int(mm + 1); i++)
    dp[1][i] =
        sum[1][i + k - 1] - sum[1][i - 1] + sum[2][i + k - 1] - sum[2][i - 1];
  for (int i = int(2); i < int(n + 1); i++) {
    memset(t, 0, sizeof(t));
    memset(lazy, 0, sizeof(lazy));
    for (int j = int(1); j < int(mm + 1); j++)
      update(1, 1, mm, j, j, dp[i - 1][j]);
    for (int j = int(1); j < int(k + 1); j++) update(1, 1, mm, 1, j, -a[i][j]);
    for (int j = int(1); j < int(mm + 1); j++) {
      dp[i][j] = t[1] + sum[i][j + k - 1] - sum[i][j - 1] +
                 sum[i + 1][j + k - 1] - sum[i + 1][j - 1];
      if (j != mm) {
        update(1, 1, mm, max(1, j - k + 1), j, a[i][j]);
        update(1, 1, mm, j + 1, j + k, -a[i][j + k]);
      }
    }
  }
  cout << *max_element(dp[n] + 1, dp[n] + mm + 1) << endl;
  return 0;
}
