#include <bits/stdc++.h>
using namespace std;
int get() {
  int x = 0;
  char s = getchar();
  while (s < '0' || s > '9') s = getchar();
  while (s >= '0' && s <= '9')
    x = (x << 3) + (x << 1) + (s ^ 48), s = getchar();
  return x;
}
int Min(const int x, const int y) {
  if (x < y) return x;
  return y;
}
int Max(const int x, const int y) {
  if (x > y) return x;
  return y;
}
const int N = 55, M = 2e4 + 5;
int n, m, k, a[N][M], sum[N][M], dp[N][M], mxp[N][M], mxs[N][M];
deque<pair<int, int> > q;
int bj(const int i) { return Min(i + k - 1, m); }
int main() {
  n = get(), m = get(), k = get();
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) sum[i][j] = sum[i][j - 1] + (a[i][j] = get());
  for (int i = 1; i <= m; ++i) {
    dp[1][i] = sum[1][bj(i)] - sum[1][i - 1];
    mxp[1][i] = Max(mxp[1][i - 1], dp[1][i] + sum[2][bj(i)] - sum[2][i - 1]);
  }
  for (int i = m; i; --i)
    mxs[1][i] = Max(mxs[1][i + 1], dp[1][i] + sum[2][bj(i)] - sum[2][i - 1]);
  for (int i = 2; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (j + k <= m)
        dp[i][j] =
            Max(dp[i][j], mxs[i - 1][j + k] + sum[i][bj(j)] - sum[i][j - 1]);
      if (j - k >= 1)
        dp[i][j] =
            Max(dp[i][j], mxp[i - 1][j - k] + sum[i][bj(j)] - sum[i][j - 1]);
    }
    q.clear();
    for (int j = 1; j <= m; ++j) {
      while (!q.empty() && q.front().second <= j - k) q.pop_front();
      while (!q.empty() && dp[i - 1][j] - sum[i][j - 1] > q.back().first)
        q.pop_back();
      q.push_back(pair<int, int>(dp[i - 1][j] - sum[i][j - 1], j));
      dp[i][j] = Max(dp[i][j], q.front().first + sum[i][bj(j)]);
    }
    q.clear();
    for (int j = m; j; --j) {
      while (!q.empty() && q.front().second >= j + k) q.pop_front();
      while (!q.empty() && dp[i - 1][j] + sum[i][bj(j)] > q.back().first)
        q.pop_back();
      q.push_back(pair<int, int>(dp[i - 1][j] + sum[i][bj(j)], j));
      dp[i][j] = Max(dp[i][j], q.front().first - sum[i][j - 1]);
    }
    for (int j = 1; j <= m; ++j)
      mxp[i][j] =
          Max(mxp[i][j - 1], dp[i][j] + sum[i + 1][bj(j)] - sum[i + 1][j - 1]);
    for (int j = m; j; --j)
      mxs[i][j] =
          Max(mxs[i][j + 1], dp[i][j] + sum[i + 1][bj(j)] - sum[i + 1][j - 1]);
  }
  int ans = 0;
  for (int i = 1; i <= m; ++i) ans = Max(ans, dp[n][i]);
  printf("%d", ans);
  return 0;
}
