#include <bits/stdc++.h>
using namespace std;
const int N = 55, M = 2e4 + 5, K = 22;
int a[N][M];
int dp[N][M], sum[N][M];
int pre[M], suf[M];
inline int getsum(int d, int l, int r) { return sum[d][r] - sum[d][l - 1]; }
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      sum[i][j] = sum[i][j - 1] + a[i][j];
    }
  }
  int mx = m - k + 1;
  for (int i = 1; i <= mx; i++) dp[1][i] = getsum(1, i, i + k - 1);
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= mx; j++)
      pre[j] = max(pre[j - 1], dp[i - 1][j] + getsum(i, j, j + k - 1));
    for (int j = mx; j > 0; j--)
      suf[j] = max(suf[j + 1], dp[i - 1][j] + getsum(i, j, j + k - 1));
    for (int c = 1; c <= mx; c++) {
      int ll = max(0, c - k);
      int rr = min(mx + 1, c + k);
      dp[i][c] = max(pre[ll], suf[rr]) + getsum(i, c, c + k - 1);
      for (int p = ll + 1; p < rr; p++) {
        int lft = min(p, c);
        int rgt = max(p + k - 1, c + k - 1);
        dp[i][c] = max(dp[i][c], dp[i - 1][p] + getsum(i, lft, rgt));
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= mx; i++) ans = max(ans, dp[n][i]);
  cout << ans << endl;
}
