#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
int getPrevMax(vector<int>& line, const uint left, const uint right,
               vector<int>& sum) {
  int max = 0;
  int substruct = 0;
  auto d = right - left;
  for (auto i = 1u; i < line.size(); ++i) {
    if (i >= left && i <= right)
      substruct = sum[right] - sum[i - 1];
    else if (i + d >= left && i + d <= right)
      substruct = sum[i + d] - sum[left - 1];
    else
      substruct = 0;
    if (line[i] - substruct > max) max = line[i] - substruct;
  }
  return max;
}
pair<int, uint> getMax(vector<int>& line) {
  int max = -1;
  uint id = 0;
  for (auto i = 1u; i < line.size(); ++i) {
    if (line[i] > max) {
      max = line[i];
      id = i;
    }
  }
  return {max, id};
}
int main() {
  uint i, j, n, m, k;
  cin >> n >> m >> k;
  vector<vector<int>> animal(n + 2, vector<int>(m + 1));
  vector<vector<int>> psum(n + 2, vector<int>(m + 1));
  vector<vector<int>> dp(n + 2, vector<int>(m + 1));
  for (i = 1; i <= n; ++i) {
    for (j = 1; j <= m; ++j) {
      cin >> animal[i][j];
      psum[i][j] = psum[i][j - 1] + animal[i][j];
    }
  }
  uint mm = (m - k + 1);
  int top, down;
  for (j = 1; j <= mm; ++j) {
    top = (psum[1][j + k - 1] - psum[1][j - 1]);
    down = (psum[2][j + k - 1] - psum[2][j - 1]);
    dp[1][j] = top + down;
  }
  for (i = 2; i <= n; ++i) {
    auto max = getMax(dp[i - 1]);
    for (j = 1; j <= mm; ++j) {
      top = (psum[i][j + k - 1] - psum[i][j - 1]);
      down = (psum[i + 1][j + k - 1] - psum[i + 1][j - 1]);
      if (((j + k - 1) >= max.second && j <= max.second) ||
          ((j >= max.second && j <= max.second + k - 1)))
        dp[i][j] = top + down + getPrevMax(dp[i - 1], j, (j + k - 1), psum[i]);
      else {
        dp[i][j] = top + down + max.first;
      }
    }
  }
  cout << getPrevMax(dp[n], m + 1, m + 1, psum[n]) << endl;
  return 0;
}
