#include <bits/stdc++.h>
using namespace std;
const int N = 2e4 + 10;
int n, m, a[55][N], k;
long long s[55][N], dp[55][N];
long long L[N], R[N], ans;
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      s[i][j] = s[i][j - 1] + s[i - 1][j] - s[i - 1][j - 1] + a[i][j];
    }
  }
  auto get = [&](int r1, int c1, int r2, int c2) {
    return s[r2][c2] - s[r2][c1 - 1] - s[r1 - 1][c2] + s[r1 - 1][c1 - 1];
  };
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      L[j] = max(dp[i - 1][j], L[j - 1]);
    }
    for (int j = m; j >= 1; j--) {
      R[j] = max(dp[i - 1][j], R[j + 1]);
    }
    for (int j = 1; j + k - 1 <= m; j++) {
      if (j > k)
        dp[i][j] = L[j - k] + get(i, j, min(i + 1, n), min(m, j + k - 1));
      if (j + k <= m)
        dp[i][j] = max(dp[i][j],
                       get(i, j, min(i + 1, n), min(m, j + k - 1)) + R[j + k]);
      long long sum = get(i, j, min(i + 1, n), min(m, j + k - 1));
      for (int mid = max(j - k + 1, 1); mid <= j + k - 1; mid++) {
        dp[i][j] = max(
            dp[i][j],
            dp[i - 1][mid] + sum -
                get(i, max(j, mid), i, min(j + k - 1, mid + k - 1)) * (i != 1));
      }
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << '\n';
  return 0;
}
