#include <bits/stdc++.h>
using namespace std;
const int N = 50 + 10;
const int M = 4e4 + 10;
const long long INF = 1e12;
int n, m, K;
long long sum[N][M], a[N][M], f[M];
template <typename T>
inline void chkmax(T &x, T y) {
  x = max(x, y);
}
template <typename T>
inline void chkmin(T &x, T y) {
  x = min(x, y);
}
template <typename T>
inline void read(T &x) {
  T f = 1;
  x = 0;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -f;
  for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
  x *= f;
}
struct Segment_Tree {
  long long Max[M << 2];
  inline void pushup(int now) {
    Max[now] = max(Max[now << 1], Max[now << 1 | 1]);
  }
  inline void modify(int now, int l, int r, int x, long long val) {
    if (l == r) {
      Max[now] = val;
      return;
    }
    int mid = l + r >> 1;
    if (mid >= x)
      modify(now << 1, l, mid, x, val);
    else
      modify(now << 1 | 1, mid + 1, r, x, val);
    pushup(now);
  }
  inline long long query(int now, int l, int r, int ql, int qr) {
    if (ql > qr) return -INF;
    if (l >= ql && r <= qr) return Max[now];
    int mid = l + r >> 1;
    if (mid >= qr)
      return query(now << 1, l, mid, ql, qr);
    else if (mid + 1 <= ql)
      return query(now << 1 | 1, mid + 1, r, ql, qr);
    else
      return max(query(now << 1, l, mid, ql, mid),
                 query(now << 1 | 1, mid + 1, r, mid + 1, qr));
  }
} t1, t2, t3;
int main() {
  read(n);
  read(m);
  read(K);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) read(a[i][j]);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) sum[i][j] = sum[i][j - 1] + a[i][j];
  for (int i = 1; i <= 80000; ++i) t1.Max[i] = t2.Max[i] = t3.Max[i] = -INF;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j + K - 1 <= m; ++j) {
      f[j] = max(t1.query(1, 1, m, 1, j - K), t1.query(1, 1, m, j + K, m));
      chkmax(f[j], t2.query(1, 1, m, j - K + 1, j) + sum[i][j - 1]);
      chkmax(f[j], t3.query(1, 1, m, j + 1, j + K) - sum[i][j + K - 1]);
      chkmax(f[j], 0LL);
    }
    for (int j = 1; j + K - 1 <= m; ++j) {
      f[j] = f[j] + sum[i][j + K - 1] - sum[i][j - 1] + sum[i + 1][j + K - 1] -
             sum[i + 1][j - 1];
      t1.modify(1, 1, m, j, f[j]);
      t2.modify(1, 1, m, j, f[j] - sum[i + 1][j + K - 1]);
      t3.modify(1, 1, m, j, f[j] + sum[i + 1][j - 1]);
    }
  }
  printf("%d\n", t1.query(1, 1, m, 1, m));
  return 0;
}
