#include <bits/stdc++.h>
using namespace std;
int dp[60][20010];
int S[60][20010];
int n, m, k;
int sum(int i, int l, int r) {
  if (l > r) return 0;
  return S[i][r] - S[i][l - 1];
}
int L[20010], R[20010];
int pre[20010], suf[20010];
int ST[2][200010];
void init(int tree[], int A[], int node, int li, int ls) {
  if (li == ls) {
    tree[node] = A[li];
  } else {
    int mid = (li + ls) / 2;
    init(tree, A, 2 * node, li, mid);
    init(tree, A, 2 * node + 1, mid + 1, ls);
    tree[node] = max(tree[2 * node], tree[2 * node + 1]);
  }
}
int query(int tree[], int node, int li, int ls, int i, int j) {
  if (i > ls || j < li) return -0x3f3f3f3f;
  if (li >= i && ls <= j) return tree[node];
  int mid = (li + ls) / 2;
  int left = query(tree, 2 * node, li, mid, i, j);
  int right = query(tree, 2 * node + 1, mid + 1, ls, i, j);
  return max(left, right);
}
int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &S[i][j]);
      S[i][j] += S[i][j - 1];
    }
  }
  int ans = 0;
  for (int i = n; i > 0; i--) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = 0;
      int l = max(1, j - k + 1), r = min(m, j + k - 1);
      if (l > 1) {
        dp[i][j] = pre[l - 1] + sum(i + 1, j, r);
      }
      if (r < m) {
        dp[i][j] = max(dp[i][j], suf[r + 1] + sum(i + 1, j, r));
      }
      dp[i][j] = max(dp[i][j], query(ST[0], 1, 1, m, l, j) + S[i + 1][r]);
      dp[i][j] =
          max(dp[i][j], query(ST[1], 1, 1, m, j + 1, r) - S[i + 1][j - 1]);
      dp[i][j] += sum(i, j, r);
      ans = max(ans, dp[i][j]);
    }
    for (int j = 1; j <= m; j++) {
      pre[j] = dp[i][j];
      suf[j] = dp[i][j];
    }
    for (int j = 2; j <= m; j++) {
      pre[j] = max(pre[j], pre[j - 1]);
      suf[m - j + 1] = max(suf[m - j + 1], suf[m - j + 2]);
    }
    for (int j = 1; j <= m; j++) {
      L[j] = dp[i][j] - S[i][min(m, j + k - 1)];
      R[j] = dp[i][j] + S[i][j - 1];
    }
    init(ST[0], L, 1, 1, m);
    init(ST[1], R, 1, 1, m);
  }
  printf("%d\n", ans);
  return 0;
}
