#include <bits/stdc++.h>
using namespace std;
int n, m, len, a[55][20055], dp[55][20055], lmax[55][20055], rmax[55][20055];
int pre(int i, int l, int r) { return a[i][r] - a[i][l - 1]; }
void maxKiri(int i) {
  for (int j = 1; j <= m - len + 1; j++) {
    lmax[i][j] = max(lmax[i][j - 1], dp[i][j]);
  }
}
void maxKanan(int i) {
  for (int j = m - len + 1; j >= 1; j--) {
    rmax[i][j] = max(rmax[i][j + 1], dp[i][j]);
  }
}
void solveKiri(int i) {
  int cur = 0;
  deque<pair<int, int>> q;
  for (int j = 1; j <= m - len + 1; j++) {
    while (!q.empty() && q.front().second < j) {
      q.pop_front();
    }
    while (!q.empty() &&
           q.back().first < dp[i - 1][j] - pre(i, j, j + len - 1) - cur) {
      q.pop_back();
    }
    q.push_back({dp[i - 1][j] - pre(i, j, j + len - 1) - cur, j + len - 1});
    dp[i][j] = max(dp[i][j], q.front().first + cur + pre(i, j, j + len - 1) +
                                 pre(i + 1, j, j + len - 1));
    cur += pre(i, j, j);
  }
}
void solveKanan(int i) {
  int cur = 0;
  deque<pair<int, int>> q;
  for (int j = m - len + 1; j >= 1; j--) {
    while (!q.empty() && q.front().second > j + len - 1) {
      q.pop_front();
    }
    while (!q.empty() &&
           q.back().first < dp[i - 1][j] - pre(i, j, j + len - 1) - cur) {
      q.pop_back();
    }
    q.push_back({dp[i - 1][j] - pre(i, j, j + len - 1) - cur, j});
    dp[i][j] = max(dp[i][j], q.front().first + cur + pre(i, j, j + len - 1) +
                                 pre(i + 1, j, j + len - 1));
    cur += pre(i, j + len - 1, j + len - 1);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> len;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      a[i][j] += a[i][j - 1];
    }
  }
  for (int j = 1; j <= m - len + 1; j++) {
    dp[1][j] = pre(1, j, j + len - 1) + pre(2, j, j + len - 1);
  }
  maxKiri(1);
  maxKanan(1);
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= m - len + 1; j++) {
      if (j - len >= 1) {
        dp[i][j] = max(dp[i][j], lmax[i - 1][j - len] + pre(i, j, j + len - 1) +
                                     pre(i + 1, j, j + len - 1));
      }
      if (j + len <= m - len + 1) {
        dp[i][j] = max(dp[i][j], rmax[i - 1][j + len] + pre(i, j, j + len - 1) +
                                     pre(i + 1, j, j + len - 1));
      }
    }
    solveKiri(i);
    solveKanan(i);
    maxKiri(i);
    maxKanan(i);
  }
  int ans = 0;
  for (int j = 1; j <= m - len + 1; j++) {
    ans = max(ans, dp[n][j]);
  }
  cout << ans << '\n';
  return 0;
}
