#include <bits/stdc++.h>
using namespace std;
const int N = 55, M = 2e5 + 5;
int n, m, k;
int a[N][M] = {0};
int dp[N][M] = {0};
int sum[N][M], sum2[N][M];
int maxl[N][M] = {0}, maxr[N][M] = {0};
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      sum2[i][j] = sum2[i][j - 1] + a[i][j];
    }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < k; j++) sum[i][0] += a[i][j] + a[i + 1][j];
    for (int j = 1; j <= m; j++) {
      sum[i][j] = sum[i][j - 1];
      if (j + k - 1 <= m) sum[i][j] += a[i][j + k - 1] + a[i + 1][j + k - 1];
      sum[i][j] -= a[i][j - 1] + a[i + 1][j - 1];
    }
  }
  for (int i = 1; i <= m; i++) {
    dp[1][i] = sum[1][i];
    maxl[1][i] = max(maxl[1][i - 1], dp[1][i]);
  }
  for (int i = m; i; i--) maxr[1][i] = max(maxr[1][i + 1], dp[1][i]);
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (j > k) dp[i][j] = sum[i][j] + maxl[i - 1][j - k];
      if (j + k <= m) dp[i][j] = max(dp[i][j], sum[i][j] + maxr[i - 1][j + k]);
      for (int p = j - k + 1; p < j + k; p++) {
        if (p < 1) continue;
        if (p > m) break;
        if (p < j) {
          dp[i][j] =
              max(dp[i][j], sum[i][j] + dp[i - 1][p] -
                                (sum2[i][min(p + k - 1, m)] - sum2[i][j - 1]));
        } else {
          dp[i][j] =
              max(dp[i][j], sum[i][j] + dp[i - 1][p] -
                                (sum2[i][min(j + k - 1, m)] - sum2[i][p - 1]));
        }
      }
      maxl[i][j] = max(maxl[i][j - 1], dp[i][j]);
    }
    for (int j = m; j; j--) maxr[i][j] = max(maxr[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;
}
