#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
const int maxm = 2e5 + 100;
long long tree[4 * maxm];
long long lazy[4 * maxm];
int animal[maxn][maxm];
long long pref[maxn][maxm];
long long dp[maxn][maxm];
void push(int node, int l, int r) {
  if (lazy[node] == 0) return;
  tree[node] += lazy[node];
  if (l != r) {
    lazy[2 * node] += lazy[node];
    lazy[2 * node + 1] += lazy[node];
  }
  lazy[node] = 0;
}
void build(int node, int l, int r, int idx) {
  lazy[node] = tree[node] = 0;
  if (l > r) return;
  if (l == r) {
    tree[node] = dp[idx][l];
    return;
  }
  int mid = (l + r) >> 1;
  build(2 * node, l, mid, idx);
  build(2 * node + 1, mid + 1, r, idx);
  tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
void update(int node, int l, int r, int x, int y, long long val) {
  push(node, l, r);
  if (l > r || l > y || r < x) return;
  if (x <= l && r <= y) {
    lazy[node] += val;
    push(node, l, r);
    return;
  }
  int mid = (l + r) >> 1;
  update(2 * node, l, mid, x, y, val);
  update(2 * node + 1, mid + 1, r, x, y, val);
  tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
long long sum(int i, int j, int k) {
  long long firstLine = pref[i][j + k - 1] - pref[i][j - 1];
  long long secondLine = pref[i + 1][j + k - 1] - pref[i + 1][j - 1];
  return firstLine + secondLine;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> animal[i][j];
      pref[i][j] = pref[i][j - 1] + animal[i][j];
    }
  }
  int limit = m - k + 1;
  for (int i = 1; i <= limit; i++) dp[1][i] = sum(1, i, k);
  for (int i = 2; i <= n; i++) {
    build(1, 1, limit, i - 1);
    for (int j = 1; j <= k; j++) update(1, 1, limit, 1, j, -animal[i][j]);
    for (int j = 1; j <= limit; j++) {
      dp[i][j] = tree[1] + sum(i, j, k);
      if (j == limit) continue;
      update(1, 1, limit, max(1, j - k + 1), j, animal[i][j]);
      update(1, 1, limit, j + 1, j + k, -animal[i][j + k]);
    }
  }
  cout << *max_element(dp[n] + 1, dp[n] + limit + 1) << endl;
  return 0;
}
