#include <bits/stdc++.h>
using namespace std;
int f[60][20100];
int a[60][20100], b[60][20100], lft[20100], rgt[20100];
int n, m, k;
void init(int f[]) {
  for (int i = 1; i <= m - k + 1; i += 1) {
    lft[i] = max(lft[i - 1], f[i]);
  }
  for (int i = m - k + 1; i >= 1; i -= 1) {
    rgt[i] = max(rgt[i + 1], f[i]);
  }
}
signed main() {
  std::ios::sync_with_stdio(false);
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i += 1) {
    for (int j = 1; j <= m; j += 1) {
      cin >> a[i][j];
      b[i][j] = a[i][j] + b[i][j - 1];
    }
  }
  int ans = 0;
  for (int j = 1; j <= m - k + 1; j += 1) {
    f[1][j] = b[1][j + k - 1] - b[1][j - 1] + b[2][j + k - 1] - b[2][j - 1];
    ans = max(ans, f[1][j]);
  }
  init(f[1]);
  for (int i = 2; i <= n; i += 1) {
    for (int j = 1; j <= m - k + 1; j += 1) {
      if (j - k >= 1) f[i][j] = max(f[i][j], lft[j - k]);
      if (j + k <= m - k + 1) f[i][j] = max(f[i][j], rgt[j + k]);
    }
    deque<int> q;
    for (int j = 1; j <= m - k + 1; j += 1) {
      if (q.size() && q.front() + k <= j) q.pop_front();
      for (int v;;) {
        if (!q.size()) break;
        v = q.back();
        if (f[i - 1][v] - (b[i][v + k - 1] - b[i][j - 1]) >
            f[i - 1][j] - (b[i][j + k - 1] - b[i][j - 1]))
          break;
        q.pop_back();
      }
      q.push_back(j);
      int v = q.front();
      f[i][j] = max(f[i][j], f[i - 1][v] - (b[i][v + k - 1] - b[i][j - 1]));
    }
    q.clear();
    for (int j = m - k + 1; j >= 1; j -= 1) {
      if (q.size() && q.front() >= j + k) q.pop_front();
      for (int v;;) {
        if (!q.size()) break;
        v = q.back();
        if (f[i - 1][v] - (b[i][j + k - 1] - b[i][v - 1]) >
            f[i - 1][j] - (b[i][j + k - 1] - b[i][j - 1]))
          break;
        q.pop_back();
      }
      q.push_back(j);
      int v = q.front();
      f[i][j] = max(f[i][j], f[i - 1][v] - (b[i][j + k - 1] - b[i][v - 1]));
    }
    for (int j = 1; j <= m - k + 1; j += 1) {
      f[i][j] += b[i][min(m, j + k - 1)] - b[i][j - 1] +
                 b[i + 1][min(m, j + k - 1)] - b[i + 1][j - 1];
      ans = max(ans, f[i][j]);
    }
    init(f[i]);
  }
  cout << ans << '\n';
  return 0;
}
