#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 55;
const int MAX_M = 20055;
int a[MAX_N][MAX_M];
int dp[MAX_N][MAX_M];
int Left[MAX_N][MAX_M], Right[MAX_N][MAX_M];
int n, m, k;
int sum[MAX_N][MAX_M];
int main() {
  cin >> n >> m >> k;
  n++;
  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];
    }
  }
  for (int j = 1; j <= m; j++) {
    int l = max(1, j - k + 1);
    for (int i = l; i <= j; i++) {
      dp[2][j] += a[1][i] + a[2][i];
    }
  }
  for (int j = 1; j <= m; j++) {
    Left[2][j] = max(Left[2][j - 1], dp[2][j]);
  }
  for (int j = m; j >= 1; j--) {
    Right[2][j] = max(Right[2][j + 1], dp[2][j]);
  }
  for (int i = 3; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int l = max(1, j - k + 1);
      int low = max(0, l - 1);
      int up = min(m + 1, j + k);
      int maxi = max(Left[i - 1][low], Right[i - 1][up]);
      for (int y = l; y <= min(m, j + k - 1); y++) {
        int x = max(l, y - k + 1);
        int s = 0;
        int le = max(l, x);
        int ri = min(y, j);
        s = (le <= ri ? sum[i - 1][ri] - sum[i - 1][le - 1] : 0);
        maxi = max(maxi, dp[i - 1][y] - s);
      }
      int total = 0;
      for (int x = l; x <= j; x++) {
        total += a[i - 1][x] + a[i][x];
      }
      dp[i][j] = maxi + total;
    }
    for (int j = 1; j <= m; j++) {
      Left[i][j] = max(Left[i][j - 1], dp[i][j]);
    }
    for (int j = m; j >= 1; j--) {
      Right[i][j] = max(Right[i][j + 1], dp[i][j]);
    }
  }
  int res = -1;
  for (int j = 1; j <= m; j++) {
    res = max(res, dp[n][j]);
  }
  cout << res;
  return 0;
}
