#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int num[55][20005] = {0}, pre[55][20005] = {0}, dp[55][20005] = {0},
    p_max[20005] = {0}, s_max[20005] = {0};
int main() {
  int i, j, n, m, k, l;
  scanf("%d%d%d", &n, &m, &k);
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      scanf("%d", &num[i][j]);
      pre[i][j] = pre[i][j - 1] + num[i][j];
    }
  for (i = 1; i <= m - k + 1; i++)
    dp[1][i] =
        pre[1][i + k - 1] - pre[1][i - 1] + pre[2][i + k - 1] - pre[2][i - 1];
  for (i = 2; i <= n; i++) {
    for (j = 0; j <= m + 1; j++) p_max[j] = s_max[j] = 0;
    p_max[1] = dp[i - 1][1];
    s_max[m - k + 1] = dp[i - 1][m - k + 1];
    for (j = 2; j <= m - k + 1; j++) p_max[j] = max(p_max[j - 1], dp[i - 1][j]);
    for (j = m - k; j >= 1; j--) s_max[j] = max(s_max[j + 1], dp[i - 1][j]);
    for (j = 1; j <= m - k + 1; j++) {
      dp[i][j] = max(j > k ? p_max[j - k] : 0, s_max[j + k]);
      for (l = j - k + 1; l < j + k; l++)
        dp[i][j] =
            max(dp[i][j], dp[i - 1][l] - (pre[i][min(j + k - 1, l + k - 1)] -
                                          pre[i][max(j, l) - 1]));
      dp[i][j] += pre[i][j + k - 1] - pre[i][j - 1] + pre[i + 1][j + k - 1] -
                  pre[i + 1][j - 1];
    }
  }
  int maxv = 0;
  for (i = 1; i <= m - k + 1; i++) maxv = max(maxv, dp[n][i]);
  printf("%d\n", maxv);
}
