#include <bits/stdc++.h>
using namespace std;
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
long long inf = 1e18, MOD = 1e9 + 7;
string s, s1;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int ti = 1;
  while (ti--) {
    int n, m, k;
    cin >> n >> m >> k;
    vector<vector<long long>> in(n + 2, vector<long long>(m + 1)),
        pre(n + 2, vector<long long>(m + 1));
    vector<long long> dp_prev(m + 1, 0);
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) cin >> in[i][j];
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        pre[i][j] += pre[i][j - 1] + in[i][j];
      }
    }
    for (int i = 1; i <= n; i++) {
      vector<long long> dp_cur(m + 1, 0);
      vector<long long> maxi_front(m + 2, INT_MIN), maxi_minus(m + 2, INT_MIN),
          maxi_plus(m + 2, INT_MIN);
      vector<long long> maxi_back(m + 2, INT_MIN);
      for (int j = 1; j <= m - k + 1; j++)
        maxi_front[j] = max(maxi_front[j - 1], dp_prev[j]);
      for (int j = m - k + 1; j >= 1; j--)
        maxi_back[j] = max(maxi_back[j + 1], dp_prev[j]);
      set<long long> se;
      map<long long, long long> ma;
      for (int j = 1; j <= m; j++) {
        if (j > k) {
          long long val = dp_prev[j - k] - pre[i][j - 1];
          if (ma[val] == 1) se.erase(val);
          ma[val]--;
        }
        if (j <= m - k + 1) {
          long long val = dp_prev[j] - pre[i][j + k - 1];
          ma[val]++, se.insert(val);
        }
        maxi_minus[j] = *(se.rbegin());
      }
      ma.clear(), se.clear();
      for (int j = 1; j <= m; j++) {
        if (j > k) {
          long long val = dp_prev[j - k] + pre[i][j - 1 - k];
          if (ma[val] == 1) se.erase(val);
          ma[val]--;
        }
        if (j <= m - k + 1) {
          long long val = dp_prev[j] + pre[i][j - 1];
          ma[val]++, se.insert(val);
        }
        maxi_plus[j] = *(se.rbegin());
      }
      for (int j = 1; j <= m - k + 1; j++) {
        dp_cur[j] = pre[i][j + k - 1] - pre[i][j - 1] + pre[i + 1][j + k - 1] -
                    pre[i + 1][j - 1];
        long long add = max(maxi_front[max(0, j - k)], maxi_back[j + k]);
        add = max(add, maxi_minus[j] + pre[i][j - 1]);
        add = max(add, maxi_plus[j + k - 1] - pre[i][j + k - 1]);
        add = max(0ll, add);
        dp_cur[j] += add;
      }
      dp_prev = dp_cur;
    }
    long long ans = 0;
    for (int i = 1; i <= m - k + 1; i++) ans = max(ans, dp_prev[i]);
    cout << ans << endl;
  }
  return 0;
}
