#include <bits/stdc++.h>
using namespace std;
const int MAXN = 55, MAXM = 20020;
int n, m, k, acc[MAXN][MAXM], dp[MAXN][MAXM], ans, pfx[MAXM], sfx[MAXM];
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", &acc[i][j]), acc[i][j] += acc[i][j - 1];
  for (int i = n; i >= 1; --i) {
    for (int j = 1; j <= m - k + 1; ++j) {
      int aux = acc[i][j + k - 1] - acc[i][j - 1] + acc[i + 1][j + k - 1] -
                acc[i + 1][j - 1];
      if (i == n) {
        dp[i][j] = aux;
        fprintf(stderr, "%d ", dp[i][j]);
        continue;
      }
      for (int l = j; l < j + k; ++l)
        dp[i][j] = max(dp[i][j], dp[i + 1][l] - (acc[i + 1][j + k - 1] -
                                                 acc[i + 1][l - 1]));
      for (int l = j - k + 1; l < j; ++l)
        dp[i][j] = max(dp[i][j], dp[i + 1][l] - (acc[i + 1][l + k - 1] -
                                                 acc[i + 1][j - 1]));
      if (j > k) dp[i][j] = max(dp[i][j], pfx[j - k]);
      if (j + k <= m - k + 1) dp[i][j] = max(dp[i][j], sfx[j + k]);
      dp[i][j] += aux;
      fprintf(stderr, "%d ", dp[i][j]);
    }
    fprintf(stderr, "\n");
    for (int j = 1; j <= m - k + 1; ++j) pfx[j] = max(pfx[j - 1], dp[i][j]);
    for (int j = m - k + 1; j >= 1; --j) sfx[j] = max(sfx[j + 1], dp[i][j]);
  }
  for (int i = 1; i <= m - k + 1; ++i) ans = max(ans, dp[1][i]);
  printf("%d\n", ans);
}
