#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e4 + 14;
int m, n, k;
int sina[maxn << 2];
int iman[maxn << 2], dp[maxn], a[maxn], lastRow[maxn];
int val(int id) { return iman[id] + sina[id]; }
void majid(int st, int en, int v, int l = 0, int r = n, int id = 1) {
  if (st <= l && r <= en) {
    sina[id] += v;
    return;
  }
  if (en <= l || r <= st) return;
  int mid = l + r >> 1;
  majid(st, en, v, l, mid, id << 1), majid(st, en, v, mid, r, id << 1 | 1);
  iman[id] = max(val(id << 1), val(id << 1 | 1));
}
void build(int l = 0, int r = n, int id = 1) {
  sina[id] = 0;
  if (r - l == 1) {
    iman[id] = dp[l] - a[l];
    return;
  }
  int mid = (l + r) / 2;
  build(l, mid, id << 1);
  build(mid, r, id << 1 | 1);
  iman[id] = max(val(id << 1), val(id << 1 | 1));
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> m >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> dp[i];
    lastRow[i] = dp[i];
  }
  if (m == 1) {
    for (int i = n - 1; i >= 0; i--)
      dp[i] += dp[i + 1] - (i + k < n ? lastRow[i + k] : 0);
    cout << *max_element(dp, dp + n) << '\n';
    return 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    dp[i] += a[i];
  }
  for (int i = n - 1; i >= 0; i--)
    dp[i] += dp[i + 1] - (i + k < n ? a[i + k] + lastRow[i + k] : 0);
  for (int day = 2; day <= m; day++) {
    memcpy(lastRow, a, sizeof a);
    fill(a + k, a + n, 0);
    for (int i = k - 1; i >= 0; i--) a[i] += a[i + 1];
    build();
    for (int i = 0; i < n; i++) {
      if (day == m)
        a[i] = 0;
      else
        cin >> a[i];
      dp[i] = a[i] + lastRow[i];
    }
    for (int i = n - 1; i >= 0; i--)
      dp[i] += dp[i + 1] - (i + k < n ? a[i + k] + lastRow[i + k] : 0);
    for (int i = 0; i < n; i++) {
      dp[i] += val(1);
      majid(i - k + 1, i + 1, lastRow[i]);
      if (i + k < n) majid(i + 1, i + k + 1, -lastRow[i + k]);
    }
  }
  cout << *max_element(dp, dp + n) << '\n';
}
