#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
template <class T>
inline T read() {
  T x = 0, f = 1;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  };
  while (s >= '0' && s <= '9') {
    x = (x << 3) + (x << 1) + s - 48;
    s = getchar();
  };
  return x * f;
}
template <typename T>
inline void wri(T x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  };
  if (x / 10) wri(x / 10);
  putchar(x % 10 + 48);
}
template <typename T>
inline void print(T x, char s) {
  wri(x);
  putchar(s);
}
template <typename T>
T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}
struct tree {
  long long maxv[80005];
  void push_up(int x) { maxv[x] = max(maxv[x << 1], maxv[x << 1 | 1]); }
  void update(int x, int l, int r, int p, long long v) {
    if (l == r) {
      maxv[x] = v;
      return;
    }
    int mid = (l + r) >> 1;
    if (p <= mid)
      update(x << 1, l, mid, p, v);
    else
      update(x << 1 | 1, mid + 1, r, p, v);
    push_up(x);
  }
  long long query(int x, int l, int r, int L, int R) {
    if (L > R) return -1e12;
    if (l >= L && r <= R) return maxv[x];
    long long ans = -1e12;
    int mid = (l + r) >> 1;
    if (L <= mid) ans = max(ans, query(x << 1, l, mid, L, R));
    if (R > mid) ans = max(ans, query(x << 1 | 1, mid + 1, r, L, R));
    return ans;
  }
};
tree t1, t2, t3;
int n, m, k;
long long a[55][200005], sum[55][200005], f[20005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> n >> m >> k;
  for (register int i = (1); i < (n + 1); i++) {
    for (register int j = (1); j < (m + 1); j++) {
      cin >> a[i][j];
    }
  }
  for (register int i = (1); i < (n + 1); i++) {
    for (register int j = (1); j < (m + 1); j++) {
      sum[i][j] = sum[i][j - 1] + a[i][j];
    }
  }
  for (register int i = (1); i < (80001); i++)
    t1.maxv[i] = t2.maxv[i] = t3.maxv[i] = -1e12;
  for (register int i = (1); i < (n + 1); 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));
      f[j] = max(f[j], t2.query(1, 1, m, j - k + 1, j) + sum[i][j - 1]);
      f[j] = max(f[j], t3.query(1, 1, m, j + 1, j + k) - sum[i][j + k - 1]);
      f[j] = max(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.update(1, 1, m, j, f[j]);
      t2.update(1, 1, m, j, f[j] - sum[i + 1][j + k - 1]);
      t3.update(1, 1, m, j, f[j] + sum[i + 1][j - 1]);
    }
  }
  cout << t1.query(1, 1, n, 1, n);
  return 0;
}
