#include <bits/stdc++.h>
using namespace std;
const int MAXN = 60;
const int MAXM = 200010;
int n, m, k, a[MAXN][MAXM];
long long preSum[MAXN][MAXM], f[MAXN][MAXM];
inline long long sum(int i, int l, int r) {
  return preSum[i][r] - preSum[i][l - 1];
}
long long pre[MAXM], suf[MAXM];
int q1[MAXM], h1, t1;
int q2[MAXM], h2, t2;
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", &a[i][j]);
      preSum[i][j] = preSum[i][j - 1] + a[i][j];
    }
  for (int i = 1; i <= m - k + 1; i++) f[1][i] = sum(1, i, i + k - 1);
  for (int j = 1; j <= m - k + 1; j++)
    pre[j] = max(pre[j - 1], f[1][j] + sum(2, j, j + k - 1));
  for (int j = m - k + 1; j >= 1; j--)
    suf[j] = max(suf[j + 1], f[1][j] + sum(2, j, j + k - 1));
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= m - k + 1; j++) {
      if (j > k) f[i][j] = max(f[i][j], pre[j - k] + sum(i, j, j + k - 1));
      if (j + k <= m - k + 1)
        f[i][j] = max(f[i][j], suf[j + k] + sum(i, j, j + k - 1));
      for (int l = max(1, j - k + 1); l <= j; l++)
        f[i][j] = max(f[i][j], f[i - 1][l] + sum(i, l, j + k - 1));
      for (int l = j; l <= min(j + k - 1, m - k + 1); l++)
        f[i][j] = max(f[i][j], f[i - 1][l] + sum(i, j, l + k - 1));
    }
    for (int j = 1; j <= m - k + 1; j++)
      pre[j] = max(pre[j - 1], f[i][j] + sum(i + 1, j, j + k - 1));
    for (int j = m - k + 1; j >= 1; j--)
      suf[j] = max(suf[j + 1], f[i][j] + sum(i + 1, j, j + k - 1));
  }
  long long ans = 0;
  for (int i = 1; i <= m - k + 1; i++) ans = max(ans, f[n][i]);
  printf("%lld\n", ans);
  return 0;
}
