#include <bits/stdc++.h>
const int N = 55;
const int M = 2e4 + 5;
const long long inf = 9223372036854775807ll;
int n, m, i, j, k;
long long a[N][M], sum[N][M], dp[M];
long long mx[3][M << 2];
inline void push_up(int c, int u) {
  mx[c][u] = std::max(mx[c][u << 1], mx[c][u << 1 | 1]);
}
void build(int l, int r, int u) {
  if (l == r) {
    mx[0][u] = mx[1][u] = mx[2][u] = -inf;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, u << 1);
  build(mid + 1, r, u << 1 | 1);
  push_up(0, u);
  push_up(1, u);
  push_up(2, u);
}
void modify(int c, int p, int l, int r, int u, long long v) {
  if (l == r) {
    mx[c][u] = v;
    return;
  }
  int mid = (l + r) >> 1;
  if (p <= mid) {
    modify(c, p, l, mid, u << 1, v);
  } else {
    modify(c, p, mid + 1, r, u << 1 | 1, v);
  }
  push_up(c, u);
}
long long range_max(int c, int ql, int qr, int l, int r, int u) {
  if (ql <= l && r <= qr) {
    return mx[c][u];
  }
  long long res = -inf;
  int mid = (l + r) >> 1;
  if (ql <= mid) {
    res = std::max(res, range_max(c, ql, qr, l, mid, u << 1));
  }
  if (mid < qr) {
    res = std::max(res, range_max(c, ql, qr, mid + 1, r, u << 1 | 1));
  }
  return res;
}
int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%lld", a[i] + j);
      sum[i][j] = sum[i][j - 1] + a[i][j];
    }
  }
  build(1, m, 1);
  for (int i = 1; i <= n; i++) {
    auto conb = [&](int x, int y) {
      long long res = 0;
      res += sum[x][y + k - 1] - sum[x][y - 1];
      if (x < n) {
        res += sum[x + 1][y + k - 1] - sum[x + 1][y - 1];
      }
      return res;
    };
    for (int j = 1; j <= m - k + 1; j++) {
      dp[j] = 0;
      if (i == 1) {
        dp[j] = conb(i, j);
        continue;
      }
      if (j - k >= 1) {
        dp[j] = std::max(dp[j], range_max(0, 1, j - k, 1, m, 1));
      }
      if (j + k <= m) {
        dp[j] = std::max(dp[j], range_max(0, j + k, m, 1, m, 1));
      }
      dp[j] = std::max(dp[j], range_max(1, std::max(j - k + 1, 1), j, 1, m, 1) +
                                  sum[i][j - 1]);
      dp[j] = std::max(dp[j],
                       range_max(2, j, j + k - 1, 1, m, 1) - sum[i][j + k - 1]);
      dp[j] += conb(i, j);
    }
    for (int j = 1; j <= m - k + 1; j++) {
      modify(0, j, 1, m, 1, dp[j]);
      modify(1, j, 1, m, 1, dp[j] - sum[i + 1][j + k - 1]);
      modify(2, j, 1, m, 1, dp[j] + sum[i + 1][j - 1]);
    }
  }
  long long ans = 0;
  for (int i = 1; i <= m; i++) {
    ans = std::max(ans, dp[i]);
  }
  printf("%lld\n", ans);
  return 0;
}
