#include <bits/stdc++.h>
using namespace std;
int test = 0;
const int MAXN = 20009;
const long long MOD = 119 << 23 | 1;
class {
 public:
  int n, m, k;
  long long sum[55][MAXN];
  long long d[55][MAXN];
  void solve() {
    cin >> n >> m >> k;
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= m; ++j) {
        cin >> sum[i][j];
        sum[i][j] += sum[i][j - 1];
      }
    }
    for (int i = 1; i <= m; ++i) {
      int r = min(m, i + k - 1);
      d[1][i] = sum[1][r] - sum[1][i - 1] + sum[2][r] - sum[2][i - 1];
    }
    for (int i = 2; i <= n; ++i) {
      long long Max = 0;
      deque<pair<long long, int>> Q, QQ;
      for (int j = 1; j <= m; ++j) {
        if (j - k >= 1) Max = max(Max, d[i - 1][j - k]);
        d[i][j] = max(d[i][j], Max);
        while (!Q.empty() && Q.front().second < j + 1 - k) Q.pop_front();
        if (!Q.empty()) d[i][j] = max(d[i][j], Q.front().first + sum[i][j - 1]);
        pair<long long, int> tp = {d[i - 1][j] - sum[i][min(j + k - 1, m)], j};
        while (!Q.empty() && Q.back().first < tp.first) Q.pop_back();
        Q.push_back(tp);
      }
      Max = 0;
      for (int j = m; j >= 1; --j) {
        pair<long long, int> tp = {d[i - 1][j] + sum[i][j - 1], j};
        while (!QQ.empty() && QQ.back().first < tp.first) QQ.pop_back();
        QQ.push_back(tp);
        while (!QQ.empty() && QQ.front().second > j + k - 1) QQ.pop_front();
        if (!QQ.empty())
          d[i][j] = max(d[i][j], QQ.front().first - sum[i][min(m, j + k - 1)]);
        if (j + k <= m) Max = max(Max, d[i - 1][j + k]);
        d[i][j] = max(d[i][j], Max);
      }
      for (int j = 1; j <= m; ++j)
        d[i][j] += sum[i][min(m, j + k - 1)] + sum[i + 1][min(m, j + k - 1)] -
                   sum[i][j - 1] - sum[i + 1][j - 1];
    }
    for (int i = 2; i <= m; ++i) d[n][1] = max(d[n][i], d[n][1]);
    cout << d[n][1] << "\n";
  }
} NSPACE;
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}
