#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read() {
  register T sum = 0;
  register char cc = getchar();
  int sym = 1;
  while (cc != '-' && (cc > '9' || cc < '0')) cc = getchar();
  if (cc == '-') sym = -1, cc = getchar();
  sum = sum * 10 + cc - '0';
  cc = getchar();
  while (cc >= '0' && cc <= '9') sum = sum * 10 + cc - '0', cc = getchar();
  return sym * sum;
}
template <typename T>
inline T read(T &a) {
  a = read<T>();
  return a;
}
template <typename T, typename... Others>
inline void read(T &a, Others &...b) {
  a = read(a);
  read(b...);
}
int n, m, K, ans, a[20010], f[55][20010], s[55][20010];
struct Tree {
  int val[20010 << 2];
  void build(int k, int l, int r, int *a) {
    if (l == r) {
      val[k] = a[l];
      return;
    }
    int mid = (l + r) >> 1;
    build(k << 1, l, mid, a);
    build(k << 1 | 1, mid + 1, r, a);
    val[k] = max(val[k << 1], val[k << 1 | 1]);
  }
  int query(int k, int l, int r, int x, int y) {
    if (l >= x && r <= y) return val[k];
    int mid = (l + r) >> 1, ans = -1000000000;
    if (x <= mid) ans = max(ans, query(k << 1, l, mid, x, y));
    if (y > mid) ans = max(ans, query(k << 1 | 1, mid + 1, r, x, y));
    return ans;
  }
  int query(int x, int y) {
    if (x > y) return -1000000000;
    return query(1, 1, m, x, y);
  }
} T[3];
int main() {
  read(n, m, K);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) s[i][j] = s[i][j - 1] + read<int>();
  for (int i = 1; i <= m; i++) f[0][i] = -1000000000;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) a[j] = f[i - 1][j] - s[i][j + K - 1];
    T[0].build(1, 1, m, a);
    for (int j = 1; j <= m; j++) a[j] = f[i - 1][j] + s[i][j - 1];
    T[1].build(1, 1, m, a);
    T[2].build(1, 1, m, f[i - 1]);
    for (int j = 1; j + K - 1 <= m; j++) {
      f[i][j] = max(f[i][j], T[0].query(max(j - K + 1, 1), j) + s[i][j - 1]);
      f[i][j] =
          max(f[i][j], T[1].query(j, min(j + K - 1, m)) - s[i][j + K - 1]);
      f[i][j] = max(f[i][j], max(T[2].query(1, j - K), T[2].query(j + K, m)));
      f[i][j] +=
          s[i][j + K - 1] - s[i][j - 1] + s[i + 1][j + K - 1] - s[i + 1][j - 1];
    }
    for (int j = m - K + 2; j <= m; j++) f[i][j] = -1000000000;
  }
  for (int i = 1; i <= m; i++) ans = max(ans, f[n][i]);
  printf("%d\n", ans);
  return 0;
}
