#include <bits/stdc++.h>
using namespace std;
namespace RA {
int r(int p) { return 1ll * rand() * rand() % p; }
int r(int L, int R) { return r(R - L + 1) + L; }
}  // namespace RA
const int N = 60, M = 2e4 + 5;
int n, m, k, ans;
int f[N][M], a[N][M], g[N][M], h[N][M];
int w(int i, int l, int r) { return a[i][r] - a[i][l - 1]; }
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) a[i][j] += a[i][j - 1];
  for (int j = (1); j <= (m - k + 1); ++j) f[1][j] = w(1, j, j + k - 1);
  for (int i = (2); i <= (n); ++i) {
    for (int j = (1); j <= (m - k + 1); ++j)
      h[i][j] = g[i][j] = f[i - 1][j] + w(i, j, j + k - 1);
    for (int j = (1); j <= (m - k + 1); ++j)
      g[i][j] = max(g[i][j], g[i][j - 1]);
    for (int j = (m - k + 1); j >= (1); --j)
      h[i][j] = max(h[i][j], h[i][j + 1]);
    for (int j = (1); j <= (m - k + 1); ++j) {
      f[i][j] = max(f[i][j], g[i][j - k] + w(i, j, j + k - 1));
      f[i][j] = max(f[i][j], h[i][j + k] + w(i, j, j + k - 1));
      for (int l = (j - k + 1); l <= (j); ++l) {
        f[i][j] = max(f[i][j], f[i - 1][l] + w(i, l, j + k - 1));
      }
      for (int l = (j + 1); l <= (j + k - 1); ++l) {
        f[i][j] = max(f[i][j], f[i - 1][l] + w(i, j, l + k - 1));
      }
    }
  }
  for (int j = (1); j <= (m - k + 1); ++j) ans = max(ans, f[n][j]);
  printf("%d\n", ans);
  return 0;
}
