#include <bits/stdc++.h>
using namespace std;
struct IO {
  char buf[(1 << 20)], *p1, *p2;
  char pbuf[(1 << 20)], *pp;
  IO() : p1(buf), p2(buf), pp(pbuf) {}
  inline char gc() {
    return getchar();
    if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, (1 << 20), stdin);
    return p1 == p2 ? ' ' : *p1++;
  }
  inline bool blank(char ch) {
    return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
  }
  template <class T>
  inline void read(T &x) {
    register double tmp = 1;
    register bool sign = 0;
    x = 0;
    register char ch = gc();
    for (; !(ch >= '0' && ch <= '9'); ch = gc())
      if (ch == '-') sign = 1;
    for (; (ch >= '0' && ch <= '9'); ch = gc()) x = x * 10 + (ch - '0');
    if (ch == '.')
      for (ch = gc(); (ch >= '0' && ch <= '9'); ch = gc())
        tmp /= 10.0, x += tmp * (ch - '0');
    if (sign) x = -x;
  }
  inline void read(char *s) {
    register char ch = gc();
    for (; blank(ch); ch = gc())
      ;
    for (; !blank(ch); ch = gc()) *s++ = ch;
    *s = 0;
  }
  inline void read(char &c) {
    for (c = gc(); blank(c); c = gc())
      ;
  }
  template <class t>
  inline void write(t x) {
    if (x < 0)
      putchar('-'), write(-x);
    else {
      if (x > 9) write(x / 10);
      putchar('0' + x % 10);
    }
  }
} io;
const long long mod = 1e9 + 7;
const long long mo = 998244353;
const long long N = 55;
const long long M = 20005;
long long n, m, s, a[N][M], sum[N][M], f[N][M];
long long q[M], suf[N][M], pre[N][M], ans;
signed main() {
  io.read(n), io.read(m), io.read(s);
  for (long long i = (1); i <= (n); i++)
    for (long long j = (1); j <= (m); j++) io.read(a[i][j]);
  for (long long i = (1); i <= (n); i++)
    for (long long j = (1); j <= (m); j++) sum[i][j] = sum[i][j - 1] + a[i][j];
  for (long long i = (1); i <= (m); i++)
    f[1][i] = sum[1][min(i + s - 1, m)] - sum[1][i - 1];
  for (long long i = (1); i <= (m); i++)
    pre[1][i] =
        max(pre[1][i - 1], f[1][i] + sum[2][min(i + s - 1, m)] - sum[2][i - 1]);
  for (long long i = (m); i >= (1); i--)
    suf[1][i] =
        max(suf[1][i + 1], f[1][i] + sum[2][min(i + s - 1, m)] - sum[2][i - 1]);
  for (long long i = (2); i <= (n); i++) {
    for (long long j = (1); j <= (m); j++) {
      if (j + s <= m)
        f[i][j] = max(f[i][j], suf[i - 1][j + s] + sum[i][min(j + s - 1, m)] -
                                   sum[i][j - 1]);
      if (j - s >= 1)
        f[i][j] = max(f[i][j], pre[i - 1][j - s] + sum[i][min(j + s - 1, m)] -
                                   sum[i][j - 1]);
    }
    long long head = 1, tail = 0;
    for (long long j = (0); j <= (m); j++) q[j] = 0;
    for (long long j = (1); j <= (m); j++) {
      while (head <= tail && q[head] <= j - s) head++;
      if (q[head])
        f[i][j] = max(f[i][j], f[i - 1][q[head]] + sum[i][min(j + s - 1, m)] -
                                   sum[i][q[head] - 1]);
      while (head <= tail && f[i - 1][j] - sum[i][j - 1] >
                                 f[i - 1][q[tail]] - sum[i][q[tail] - 1])
        tail--;
      q[++tail] = j;
    }
    head = 1, tail = 0;
    for (long long j = (0); j <= (m); j++) q[j] = 0;
    for (long long j = (m); j >= (1); j--) {
      while (head <= tail && q[head] >= j + s) head++;
      while (head <= tail &&
             f[i - 1][j] + sum[i][min(j + s - 1, m)] >
                 f[i - 1][q[tail]] + sum[i][min(q[tail] + s - 1, m)])
        tail--;
      q[++tail] = j;
      if (q[head])
        f[i][j] =
            max(f[i][j], f[i - 1][q[head]] + sum[i][min(q[head] + s - 1, m)] -
                             sum[i][j - 1]);
    }
    for (long long j = (1); j <= (m); j++)
      pre[i][j] = max(pre[i][j - 1], f[i][j] + sum[i + 1][min(j + s - 1, m)] -
                                         sum[i + 1][j - 1]);
    for (long long j = (m); j >= (1); j--)
      suf[i][j] = max(suf[i][j + 1], f[i][j] + sum[i + 1][min(j + s - 1, m)] -
                                         sum[i + 1][j - 1]);
  }
  long long Ans = 0;
  for (long long i = (1); i <= (m); i++) Ans = max(Ans, f[n][i]);
  io.write(Ans), puts("");
  return 0;
}
