#include <bits/stdc++.h>
using namespace std;
int tree[80020];
int lazy[80020];
void push(int v) {
  tree[v * 2] += lazy[v];
  tree[v * 2 + 1] += lazy[v];
  lazy[v * 2] += lazy[v];
  lazy[v * 2 + 1] += lazy[v];
  lazy[v] = 0;
}
void build(int v, int tl, int tr, vector<int>& dp) {
  lazy[v] = 0;
  if (tl == tr) {
    tree[v] = dp[tl];
  } else {
    int tm = (tl + tr) / 2;
    build(v * 2, tl, tm, dp);
    build(v * 2 + 1, tm + 1, tr, dp);
    tree[v] = max(tree[v * 2], tree[v * 2 + 1]);
  }
}
void update(int v, int tl, int tr, int l, int r, int val) {
  if (tl == l && tr == r) {
    tree[v] += val;
    lazy[v] += val;
  } else {
    push(v);
    int tm = (tl + tr) / 2;
    if (l <= tm) {
      update(v * 2, tl, tm, l, min(r, tm), val);
    }
    if (r > tm) {
      update(v * 2 + 1, tm + 1, tr, max(tm + 1, l), r, val);
    }
    tree[v] = max(tree[v * 2], tree[v * 2 + 1]);
  }
}
int animals[52][20020], psum[52][20020];
int getSum(int y1, int x1, int y2, int x2) {
  int res = psum[y2][x2];
  if (x1 > 0) {
    res -= psum[y2][x1 - 1];
  }
  if (y1 > 0) {
    res -= psum[y1 - 1][x2];
  }
  if (x1 > 0 && y1 > 0) {
    res += psum[y1 - 1][x1 - 1];
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> animals[i][j];
      psum[i][j] = animals[i][j];
    }
  }
  for (int i = 0; i < m; i++) {
    psum[n][i] = animals[n][i] = 0;
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < m; j++) {
      if (i > 0) {
        psum[i][j] += psum[i - 1][j];
      }
      if (j > 0) {
        psum[i][j] += psum[i][j - 1];
      }
      if (i > 0 && j > 0) {
        psum[i][j] -= psum[i - 1][j - 1];
      }
    }
  }
  vector<vector<int>> dp(n + 1, vector<int>(m));
  for (int i = 0; i + k - 1 < m; i++) {
    dp[0][i] = getSum(0, i, 1, i + k - 1);
  }
  for (int i = 1; i < n; i++) {
    build(1, 0, m - 1, dp[i - 1]);
    for (int j = 0; j < k; j++) {
      update(1, 0, m - 1, max(0, j - k + 1), j, -animals[i][j]);
    }
    for (int j = 0; j + k < m; j++) {
      dp[i][j] = tree[1] + getSum(i, j, i + 1, j + k - 1);
      update(1, 0, m - 1, max(0, j - k + 1), j, animals[i][j]);
      update(1, 0, m - 1, j + 1, j + k, -animals[i][j + k]);
    }
    dp[i][m - k] = tree[1] + getSum(i, m - k, i + 1, m - 1);
  }
  cout << *max_element(dp[n - 1].begin(), dp[n - 1].end()) << '\n';
}
