#include <bits/stdc++.h>
using namespace std;
const int N = 2e4 + 4, M = 54;
int m, n, k, a[M][N];
int S[M][N], dp[2][N], L[N], R[N], res;
int get(int xo, int yo, int xi, int yi) {
  return S[xi][yi] - S[xi][yo - 1] - S[xo - 1][yi] + S[xo - 1][yo - 1];
}
deque<pair<int, int> > dq;
void Insert(int i, int val) {
  while (dq.size() && dq.back().first <= val) dq.pop_back();
  dq.push_back(pair<int, int>(val, i));
}
void Erase(int i, int mul) {
  while (dq.size() && dq.front().second * mul <= i * mul) dq.pop_front();
}
void sol() {
  for (int i = 1; i <= (int)m + 1; ++i)
    for (int j = 1; j <= (int)n; ++j)
      S[i][j] = S[i - 1][j] + S[i][j - 1] - S[i - 1][j - 1] + a[i][j];
  for (int i = 1; i <= (int)n - k + 1; ++i) {
    dp[0][i] = get(1, i, 2, i + k - 1);
    res = max(res, dp[0][i]);
  }
  for (int row = 2; row <= (int)m; ++row) {
    for (int i = 1; i <= (int)n; ++i) L[i] = max(L[i - 1], dp[0][i]);
    for (int i = n; i >= (int)1; --i) R[i] = max(R[i + 1], dp[0][i]);
    for (int i = 1; i <= (int)n - k + 1; ++i) {
      dp[1][i] = get(row, i, row + 1, i + k - 1);
      if (i - k >= 1)
        dp[1][i] = max(dp[1][i], L[i - k] + get(row, i, row + 1, i + k - 1));
      if (i + k <= n)
        dp[1][i] = max(dp[1][i], R[i + k] + get(row, i, row + 1, i + k - 1));
    }
    dq.clear();
    for (int i = 1; i <= (int)n - k + 1; ++i) {
      if (i > k) Erase(i - k, 1);
      Insert(i, dp[0][i] - get(row, 1, row, i + k - 1));
      int val = get(row, i, row + 1, i + k - 1) + get(row, 1, row, i - 1);
      if (dq.size()) val += dq.front().first;
      dp[1][i] = max(dp[1][i], val);
    }
    dq.clear();
    for (int i = n - k + 1; i >= (int)1; --i) {
      if (i + k <= n) Erase(i + k, -1);
      Insert(i, dp[0][i] + get(row, 1, row, i - 1));
      int val = get(row, i, row + 1, i + k - 1) - get(row, 1, row, i + k - 1);
      if (dq.size()) val += dq.front().first;
      dp[1][i] = max(dp[1][i], val);
    }
    for (int i = 1; i <= (int)n; ++i) {
      res = max(res, dp[1][i]);
      dp[0][i] = dp[1][i];
      dp[1][i] = 0;
    }
  }
  cout << res << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  if (fopen("input.txt", "r")) {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  }
  cin >> m >> n >> k;
  for (int i = 1; i <= (int)m; ++i)
    for (int j = 1; j <= (int)n; ++j) cin >> a[i][j];
  sol();
  return 0;
}
