#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 100;
int a[60][20010];
int dp[60][20010], lmax[60][20010], rmax[60][20010];
int qz(int i, int l, int r) { return a[i][r] - a[i][l - 1]; }
int main() {
  ios::sync_with_stdio(0);
  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], a[i][j] += a[i][j - 1];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m - k + 1; j++) {
      int num = qz(i, j, j + k - 1) + qz(i + 1, j, j + k - 1);
      if (i == 1) {
        dp[i][j] = num;
        continue;
      }
      int Max = 0;
      for (int x = max(1, j - k + 1); x <= min(m - k + 1, j + k - 1); x++)
        Max = max(Max, dp[i - 1][x] + num -
                           qz(i, max(x, j), min(x + k - 1, j + k - 1)));
      dp[i][j] = Max;
      if (j > k) dp[i][j] = max(dp[i][j], lmax[i - 1][j - k] + num);
      if (j + k - 1 <= m - k)
        dp[i][j] = max(dp[i][j], rmax[i - 1][j + k] + num);
    }
    for (int j = 1; j <= m - k + 1; j++)
      lmax[i][j] = max(lmax[i][j - 1], dp[i][j]);
    for (int j = m - k + 1; j >= 1; j--)
      rmax[i][j] = max(rmax[i][j + 1], dp[i][j]);
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) ans = max(ans, dp[n][i]);
  cout << ans << endl;
  return 0;
}
