#include <bits/stdc++.h>
using namespace std;
int n, m, k, op[55][20005], dp[55][20005], maxnl[20005], maxnr[20005],
    sum[55][20005];
deque<int> dq;
inline void add1(int x, int i) {
  while (!dq.empty() && dp[i - 1][dq.back() - k + 1] - sum[i - 1][dq.back()] <
                            dp[i - 1][x - k + 1] - sum[i - 1][x])
    dq.pop_back();
  dq.push_back(x);
}
inline int fr1(int x) {
  while (dq.front() < x) dq.pop_front();
  return dq.front();
}
inline void add2(int x, int i) {
  while (!dq.empty() && dp[i - 1][dq.back()] + sum[i - 1][dq.back() - 1] <
                            dp[i - 1][x] + sum[i - 1][x - 1])
    dq.pop_back();
  dq.push_back(x);
}
inline int fr2(int x) {
  while (dq.front() > x) dq.pop_front();
  return dq.front();
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n; i++) {
    sum[i][0] = 0;
    for (int j = 1; j <= m; j++)
      scanf("%d", &op[i][j]), sum[i][j] = sum[i][j - 1] + op[i][j];
  }
  for (int i = 1; i <= m + 1 - k; i++) {
    dp[2][i] =
        sum[1][i + k - 1] - sum[1][i - 1] + sum[2][i + k - 1] - sum[2][i - 1];
  }
  for (int i = 1; i <= m + 1 - k; i++) maxnl[i] = max(maxnl[i - 1], dp[2][i]);
  for (int i = m + 1 - k; i >= 1; i--) maxnr[i] = max(maxnr[i + 1], dp[2][i]);
  for (int i = 3, sv; i <= n + 1; i++) {
    while (!dq.empty()) dq.pop_back();
    for (int j = 1; j <= m + 1 - k; j++) {
      int ops = sum[i - 1][j + k - 1] - sum[i - 1][j - 1] + sum[i][j + k - 1] -
                sum[i][j - 1];
      dp[i][j] = -0x3f3f3f3f, add1(j + k - 1, i);
      if (j - k >= 1) {
        dp[i][j] = max(dp[i][j], maxnl[j - k] + ops);
      }
      if (j + k <= m + 1 - k) {
        dp[i][j] = max(dp[i][j], maxnr[j + k] + ops);
      }
      sv = fr1(max(k, j));
      dp[i][j] = max(dp[i][j], dp[i - 1][sv - k + 1] - sum[i - 1][sv] +
                                   sum[i - 1][j + k - 1] + sum[i][j + k - 1] -
                                   sum[i][j - 1]);
    }
    while (!dq.empty()) dq.pop_back();
    for (int j = m + 1 - k; j >= 1; j--) {
      add2(j, i);
      sv = fr2(min(m + 1 - k, k - 1 + j));
      dp[i][j] =
          max(dp[i][j], dp[i - 1][sv] + sum[i - 1][sv - 1] - sum[i - 1][j - 1] +
                            sum[i][j + k - 1] - sum[i][j - 1]);
    }
    for (int j = 1; j <= m + 1 - k; j++) maxnl[j] = max(dp[i][j], maxnl[j - 1]);
    for (int j = m + 1 - k; j >= 1; j--) maxnr[j] = max(dp[i][j], maxnr[j + 1]);
  }
  int ans = 0;
  for (int i = 1; i <= m + 1 - k; i++) ans = max(ans, dp[n + 1][i]);
  printf("%d", ans);
  return 0;
}
