#include <bits/stdc++.h>
const int MAXN = 2e4 + 332;
int f[2][MAXN], now;
int n, m, k;
int pre[MAXN], suf[MAXN];
int a[51][MAXN];
int sm[51][MAXN];
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]);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) sm[i][j] = sm[i][j - 1] + a[i][j];
  for (int i = 1; i <= m - k + 1; ++i)
    f[now][i] = sm[1][i + k - 1] - sm[1][i - 1];
  for (int i = 2; i <= n; ++i) {
    now ^= 1;
    for (int j = 0; j <= m + 23; ++j) pre[j] = suf[j] = 0;
    for (int j = 1; j <= m - k + 1; ++j)
      pre[j] =
          std::max(pre[j - 1], f[now ^ 1][j] + sm[i][j + k - 1] - sm[i][j - 1]);
    for (int j = m - k + 1; j >= 0; --j)
      suf[j] =
          std::max(suf[j + 1], f[now ^ 1][j] + sm[i][j + k - 1] - sm[i][j - 1]);
    for (int j = 1; j <= m - k + 1; ++j) {
      f[now][j] = std::max(pre[std::max(0, j - k)], suf[j + k]) +
                  sm[i][j + k - 1] - sm[i][j - 1];
      for (int k = std::max(1, j - ::k + 1);
           k <= std::min(m - ::k + 1, j + ::k - 1); ++k) {
        int l = std::min(k, j), r = std::max(k + ::k - 1, j + ::k - 1);
        f[now][j] =
            std::max(f[now][j], f[now ^ 1][k] + sm[i][r] - sm[i][l - 1]);
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= m; ++i) ans = std::max(ans, f[now][i]);
  printf("%d\n", ans);
  return 0;
}
