#include <bits/stdc++.h>
using namespace std;
int n, m, k, s[55][20015], dp[55][20015], pre[20015], suf[20015], res;
deque<int> dq1, dq2;
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) cin >> s[i][j], s[i][j] += s[i][j - 1];
  for (int j = 1; j <= m - k + 1; ++j)
    dp[1][j] = s[1][j + k - 1] - s[1][j - 1] + s[2][j + k - 1] - s[2][j - 1];
  for (int j = 1; j <= m - k + 1; ++j) pre[j] = max(pre[j - 1], dp[1][j]);
  for (int j = m - k + 1; j >= 1; --j) suf[j] = max(suf[j + 1], dp[1][j]);
  for (int i = 2; i <= n; ++i) {
    while (!dq1.empty()) dq1.pop_back();
    while (!dq2.empty()) dq2.pop_back();
    for (int j = 2; j < k; ++j) {
      while (!dq2.empty() && (dp[i - 1][j] + s[i][j - 1]) >
                                 (dp[i - 1][dq2.back()] + s[i][dq2.back() - 1]))
        dq2.pop_back();
      dq2.push_back(j);
    }
    for (int j = 1; j <= m - k + 1; ++j) {
      while (!dq1.empty() &&
             (dp[i - 1][j] - s[i][j + k - 1]) >
                 (dp[i - 1][dq1.back()] - s[i][dq1.back() + k - 1]))
        dq1.pop_back();
      dq1.push_back(j);
      while (dq1.front() <= j - k) dq1.pop_front();
      if (j + k - 1 <= m - k + 1) {
        while (!dq2.empty() &&
               (dp[i - 1][j + k - 1] + s[i][j + k - 1 - 1]) >
                   (dp[i - 1][dq2.back()] + s[i][dq2.back() - 1]))
          dq2.pop_back();
        dq2.push_back(j + k - 1);
        while (!dq2.empty() && dq2.front() <= j) dq2.pop_front();
      }
      dp[i][j] = (dp[i - 1][dq1.front()] - s[i][dq1.front() + k - 1]) +
                 s[i][j + k - 1];
      if (!dq2.empty())
        dp[i][j] =
            max(dp[i][j],
                (dp[i - 1][dq2.front()] + s[i][dq2.front() - 1]) - s[i][j - 1]);
      if (j > k)
        dp[i][j] = max(dp[i][j], pre[j - k] + s[i][j + k - 1] - s[i][j - 1]);
      if (j + k <= m - k + 1)
        dp[i][j] = max(dp[i][j], suf[j + k] + s[i][j + k - 1] - s[i][j - 1]);
      dp[i][j] += s[i + 1][j + k - 1] - s[i + 1][j - 1];
    }
    for (int j = 1; j <= m - k + 1; ++j) pre[j] = max(pre[j - 1], dp[i][j]);
    for (int j = m - k + 1; j >= 1; --j) suf[j] = max(suf[j + 1], dp[i][j]);
  }
  for (int j = 1; j <= m - k + 1; ++j) res = max(res, dp[n][j]);
  cout << res;
}
