#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char c = getchar();
  int x = 0, f = 1;
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return x * f;
}
const int MAXN = 55;
const int MAXM = 2e4 + 5;
int N, M, K, ans;
int a[MAXN][MAXM], sum[MAXN][MAXM], dp[MAXN][MAXM];
int pre[MAXM], suf[MAXM];
inline int calc(int x, int l, int r, int l2, int r2) {
  if (l > l2) {
    swap(l, l2);
    swap(r, r2);
  }
  if (r < l2) return 0;
  return sum[x][r] - sum[x][l2 - 1];
}
int main() {
  N = read();
  M = read();
  K = read();
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++) {
      a[i][j] = read();
      sum[i][j] = sum[i][j - 1] + a[i][j];
    }
  if (N == 1) {
    for (int i = 1; i + K - 1 <= M; i++)
      ans = max(ans, sum[1][i + K - 1] - sum[1][i - 1]);
    printf("%d\n", ans);
    return 0;
  }
  for (int i = 1; i <= M; i++)
    dp[1][i] = sum[1][min(i + K - 1, M)] - sum[1][i - 1] +
               sum[2][min(i + K - 1, M)] - sum[2][i - 1];
  for (int i = 2; i <= N; i++) {
    pre[0] = suf[M + 1] = 0;
    for (int j = 1; j <= M; j++) pre[j] = max(pre[j - 1], dp[i - 1][j]);
    for (int j = M; j; j--) suf[j] = max(suf[j + 1], dp[i - 1][j]);
    for (int j = 1; j <= M; j++) {
      int l = max(j - K, 0), r = min(j + K, M + 1);
      dp[i][j] = max(pre[l], suf[r]) + sum[i][min(j + K - 1, M)] -
                 sum[i][j - 1] + sum[i + 1][min(j + K - 1, M)] -
                 sum[i + 1][j - 1];
      for (int k = l + 1; k < r; k++) {
        int now = calc(i, k, min(k + K - 1, M), j, min(j + K - 1, M));
        dp[i][j] =
            max(dp[i][j], dp[i - 1][k] + sum[i][min(j + K - 1, M)] -
                              sum[i][j - 1] + sum[i + 1][min(j + K - 1, M)] -
                              sum[i + 1][j - 1] - now);
      }
    }
  }
  for (int i = 1; i <= M; i++) ans = max(ans, dp[N][i]);
  printf("%d\n", ans);
  return 0;
}
