#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
int a[100][maxn], sum[100][maxn];
int dp[100][maxn];
int maxv[maxn << 2], lazy[maxn << 2];
void Build(int o, int L, int R, int r) {
  if (L == R) {
    maxv[o] = dp[r][L];
    lazy[o] = 0;
  } else {
    int M = (L + R) >> 1;
    Build(o << 1, L, M, r);
    Build(o << 1 | 1, M + 1, R, r);
    maxv[o] = max(maxv[o << 1], maxv[o << 1 | 1]);
    lazy[o] = 0;
  }
}
void Push_down(int o, int L, int R) {
  if (lazy[o]) {
    maxv[o << 1] += lazy[o];
    maxv[o << 1 | 1] += lazy[o];
    lazy[o << 1] += lazy[o];
    lazy[o << 1 | 1] += lazy[o];
    lazy[o] = 0;
  }
}
void Update(int o, int L, int R, int l, int r, int v) {
  if (l <= L && R <= r) {
    maxv[o] += v;
    lazy[o] += v;
  } else {
    Push_down(o, L, R);
    int M = (L + R) >> 1;
    if (l <= M) Update(o << 1, L, M, l, r, v);
    if (r >= M + 1) Update(o << 1 | 1, M + 1, R, l, r, v);
    maxv[o] = max(maxv[o << 1], maxv[o << 1 | 1]);
  }
}
int Query(int o, int L, int R, int l, int r) {
  if (l <= L && R <= r) {
    return maxv[o];
  } else {
    Push_down(o, L, R);
    int res = INT_MIN, M = (L + R) >> 1;
    if (l <= M) res = max(res, Query(o << 1, L, M, l, r));
    if (r >= M + 1) res = max(res, Query(o << 1 | 1, M + 1, R, l, r));
    maxv[o] = max(maxv[o << 1], maxv[o << 1 | 1]);
    return res;
  }
}
int main() {
  int n, m, k;
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &a[i][j]);
      sum[i][j] = sum[i][j - 1] + a[i][j];
    }
  }
  for (int i = 1; i <= m - k + 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 = 2; i <= n; i++) {
    Build(1, 1, m - k + 1, i - 1);
    for (int j = 1; j <= k && j + k - 1 <= m; j++) {
      Update(1, 1, m - k + 1, j, j, -(sum[i][k] - sum[i][j - 1]));
    }
    dp[i][1] = Query(1, 1, m - k + 1, 1, m - k + 1) + sum[i][k] + sum[i + 1][k];
    for (int j = 2; j <= m - k + 1; j++) {
      Update(1, 1, m - k + 1, max(1, j - k), j - 1, a[i][j - 1]);
      Update(1, 1, m - k + 1, j, min(m - k + 1, j + k - 1), -a[i][j + k - 1]);
      dp[i][j] = Query(1, 1, m - k + 1, 1, m - k + 1) + sum[i][j + k - 1] -
                 sum[i][j - 1] + sum[i + 1][j + k - 1] - sum[i + 1][j - 1];
    }
  }
  int ans = 0;
  for (int j = 1; j <= m - k + 1; j++) {
    ans = max(ans, dp[n][j]);
  }
  printf("%d\n", ans);
  getchar();
  getchar();
  return 0;
}
