#include <bits/stdc++.h>
using namespace std;
const int N = 55, M = 2e4 + 5;
int n, m, k;
long long a[N][M], f[N][M], mx1[M], mx2[M];
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      scanf("%lld", &a[i][j]);
      a[i][j] += a[i][j - 1];
    }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m - k + 1; j++) {
      int b =
          a[i][j + k - 1] - a[i][j - 1] + a[i + 1][j + k - 1] - a[i + 1][j - 1];
      f[i][j] = max(mx1[j - k], mx2[j + k]) + b;
      for (int l = j - k + 1; l <= j + k - 1; l++) {
        int x = max(j, l), y = min(j + k - 1, l + k - 1);
        int c = i > 1 ? a[i][y] - a[i][x - 1] : 0;
        f[i][j] = max(f[i][j], f[i - 1][l] - c + b);
      }
    }
    for (int j = 1; j <= m - k + 1; j++) mx1[j] = max(mx1[j - 1], f[i][j]);
    for (int j = m - k + 1; j; j--) mx2[j] = max(mx2[j + 1], f[i][j]);
  }
  long long ans = 0;
  for (int i = 1; i <= m - k + 1; i++) ans = max(ans, f[n][i]);
  printf("%lld", ans);
  return 0;
}
