#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e4 + 5;
int dp[55][maxn];
int L[55][maxn], R[55][maxn];
int sum[55][maxn];
int n, m, k;
int getdp(int i, int j1, int j2) { return sum[i][j2] - sum[i][j1 - 1]; }
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int val;
      cin >> val;
      sum[i][j] = sum[i][j - 1] + val;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m - k + 1; j++) {
      int t = sum[i][j + k - 1] - sum[i][j - 1] + sum[i + 1][j + k - 1] -
              sum[i + 1][j - 1];
      if (i == 1) {
        dp[i][j] = t;
        continue;
      }
      int Max = 0;
      for (int tt = max(1, j - k + 1); tt <= min(m - k + 1, j + k - 1); tt++) {
        Max = max(Max, dp[i - 1][tt] + t -
                           getdp(i, max(tt, j), min(j + k - 1, tt + k - 1)));
      }
      dp[i][j] = Max;
      if (j > k) dp[i][j] = max(dp[i][j], L[i - 1][j - k] + t);
      if (j + k <= m - k + 1) {
        dp[i][j] = max(dp[i][j], R[i - 1][j + k] + t);
      }
    }
    for (int j = 1; j <= m - k + 1; j++) L[i][j] = max(dp[i][j], L[i][j - 1]);
    for (int j = m - k + 1; j >= 1; j--) R[i][j] = max(dp[i][j], R[i][j + 1]);
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    ans = max(ans, dp[n][i]);
  }
  cout << ans;
  return 0;
}
