#include <bits/stdc++.h>
using namespace std;
int n, m, d, tem, q[20005], l, r, ans;
int a[55][20005], f[55][20005], s[55][20005];
int get(int x, int y) {
  return s[x][y] - s[x][y - d] + s[x - 1][y] - s[x - 1][y - d];
}
int main() {
  cin >> n >> m >> d;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      scanf("%d", &a[i][j]);
      s[i][j] = s[i][j - 1] + a[i][j];
    }
  for (int i = d; i <= m; i++) f[2][i] = get(2, i);
  for (int k = 2; k <= n + 1; k++) {
    tem = 0;
    for (int i = d * 2; i <= m; i++) {
      tem = max(tem, f[k - 1][i - d]);
      f[k][i] = max(f[k][i], tem + get(k, i));
    }
    tem = 0;
    for (int i = m - d; i >= d; i--) {
      tem = max(tem, f[k - 1][i + d]);
      f[k][i] = max(f[k][i], tem + get(k, i));
    }
    l = r = 0;
    for (int i = d; i <= m; i++) {
      while (l < r && q[l + 1] <= i - d) l++;
      while (l < r && f[k - 1][q[r]] - s[k - 1][q[r]] + s[k - 1][i - d] <=
                          f[k - 1][i] - s[k - 1][i] + s[k - 1][i - d])
        r--;
      q[++r] = i;
      f[k][i] = max(f[k][i], f[k - 1][q[l + 1]] - s[k - 1][q[l + 1]] +
                                 s[k - 1][i - d] + get(k, i));
    }
    l = r = 0;
    ;
    for (int i = m; i >= d; i--) {
      while (l < r && q[l + 1] >= i + d) l++;
      while (l < r && f[k - 1][q[r]] - s[k - 1][i] + s[k - 1][q[r] - d] <=
                          f[k - 1][i] - s[k - 1][i] + s[k - 1][i - d])
        r--;
      q[++r] = i;
      f[k][i] = max(f[k][i], f[k - 1][q[l + 1]] - s[k - 1][i] +
                                 s[k - 1][q[l + 1] - d] + get(k, i));
    }
  }
  for (int i = d; i <= m; i++) ans = max(f[n + 1][i], ans);
  cout << ans << endl;
  return 0;
}
