#include <bits/stdc++.h>
using namespace std;
int sum[52][20002];
int a[52][20002];
int dp[52][20002];
int st[80002], add[80002];
void push(int n, int s, int e, int val) {
  st[n] += val;
  if (s != e) {
    add[n + n] += val;
    add[n + n + 1] += val;
  }
  add[n] = 0;
}
void update(int n, int s, int e, int l, int r, int v) {
  push(n, s, e, add[n]);
  if (s > r || l > e) return;
  if (l <= s && e <= r) {
    push(n, s, e, v);
    return;
  }
  int mid = (s + e) / 2;
  update(n + n, s, mid, l, r, v);
  update(n + n + 1, mid + 1, e, l, r, v);
  st[n] = max(st[n + n], st[n + n + 1]);
}
int query(int n, int s, int e, int l, int r) {
  push(n, s, e, add[n]);
  if (s > r || l > e) return 0;
  if (l <= s && e <= r) return st[n];
  int mid = (s + e) / 2;
  return max(query(n + n, s, mid, l, r), query(n + n + 1, mid + 1, e, l, r));
}
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] += a[i][j];
      sum[i][j] += sum[i][j - 1];
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    memset(st, 0, sizeof(st));
    memset(add, 0, sizeof(add));
    if (i == 1) {
      for (int j = k; j <= m; j++) {
        dp[i][j] += (sum[i][j] - sum[i][j - k]);
        if (i + 1 <= n) dp[i][j] += (sum[i + 1][j] - sum[i + 1][j - k]);
        ans = max(ans, dp[i][j]);
      }
    } else {
      for (int j = k; j <= m; j++) {
        int l = j - k + 1, r = j;
        if (j == k) {
          for (int j2 = k; j2 <= m; j2++) {
            int l2 = j2 - k + 1, r2 = j2;
            update(1, 1, m, j2, j2, dp[i - 1][j2]);
            if (l <= l2 && l2 <= r) {
              update(1, 1, m, j2, j2, -(sum[i][r] - sum[i][l2 - 1]));
            }
          }
        } else {
          update(1, 1, m, max(k, j - k), j - 1, a[i][j - k]);
          update(1, 1, m, j, min(m, j + k - 1), -a[i][j]);
        }
        dp[i][j] = query(1, 1, m, 1, m) + sum[i][j] - sum[i][j - k];
        if (i + 1 <= n) dp[i][j] += sum[i + 1][j] - sum[i + 1][j - k];
        ans = max(ans, dp[i][j]);
      }
    }
  }
  printf("%d\n", ans);
}
