#include <bits/stdc++.h>
using namespace std;
template <typename _T>
inline void read(_T &f) {
  f = 0;
  _T fu = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') {
      fu = -1;
    }
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    f = (f << 3) + (f << 1) + (c & 15);
    c = getchar();
  }
  f *= fu;
}
template <typename T>
void print(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x < 10)
    putchar(x + 48);
  else
    print(x / 10), putchar(x % 10 + 48);
}
template <typename T>
void print(T x, char t) {
  print(x);
  putchar(t);
}
const int N = 20005;
int mx[N << 2], s[55][N], f[55][N];
int n, m, k, ans;
void change(int u, int l, int r, int L, int R, int x) {
  if (l > r) return;
  if (l <= L && R <= r) {
    mx[u] = max(mx[u], x);
    return;
  }
  int mid = (L + R) >> 1;
  if (mid >= l) change(u << 1, l, r, L, mid, x);
  if (mid + 1 <= r) change(u << 1 | 1, l, r, mid + 1, R, x);
}
int query(int u, int l, int r, int x) {
  if (l == r) return mx[u];
  int mid = (l + r) >> 1, ans = mx[u];
  if (mid >= x)
    ans = max(ans, query(u << 1, l, mid, x));
  else
    ans = max(ans, query(u << 1 | 1, mid + 1, r, x));
  return ans;
}
int main() {
  read(n);
  read(m);
  read(k);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      read(s[i][j]);
      s[i][j] += s[i][j - 1];
    }
  }
  for (int i = 1; i <= m - k + 1; i++) f[1][i] = s[1][i + k - 1] - s[1][i - 1];
  for (int i = 1; i < n; i++) {
    for (int j = 1; j <= m - k + 1; j++)
      f[i][j] += s[i + 1][j + k - 1] - s[i + 1][j - 1];
    memset(mx, 0, sizeof(mx));
    for (int j = 1; j <= m - k + 1; j++)
      change(1, max(1, j - k + 1), j, 1, m - k + 1, f[i][j] + s[i + 1][j - 1]);
    for (int j = 1; j <= m - k + 1; j++)
      f[i + 1][j] = query(1, 1, m - k + 1, j) - s[i + 1][j - 1];
    memset(mx, -0x3f, sizeof(mx));
    for (int j = 1; j <= m - k + 1; j++)
      change(1, j, min(m - k + 1, j + k - 1), 1, m - k + 1,
             f[i][j] - s[i + 1][j + k - 1]);
    for (int j = 1; j <= m - k + 1; j++)
      f[i + 1][j] =
          max(f[i + 1][j], query(1, 1, m - k + 1, j) + s[i + 1][j + k - 1]);
    memset(mx, 0, sizeof(mx));
    for (int j = 1; j <= m - k + 1; j++) {
      change(1, 1, j - k, 1, m - k + 1, f[i][j]);
      change(1, j + k, m - k + 1, 1, m - k + 1, f[i][j]);
    }
    for (int j = 1; j <= m - k + 1; j++)
      f[i + 1][j] = max(f[i + 1][j], query(1, 1, m - k + 1, j) +
                                         s[i + 1][j + k - 1] - s[i + 1][j - 1]);
  }
  for (int i = 1; i <= m - k + 1; i++) ans = max(ans, f[n][i]);
  print(ans, '\n');
  return 0;
}
