#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using qi = queue<int>;
int n, m, k;
int mat[51][20005];
int row[51][20005];
int rowl[51][20005];
int rowr[51][20005];
int dp[51][20005];
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> mat[i][j];
    }
  }
  for (int i = 1; i <= n; ++i) {
    int tmp = 0;
    for (int j = 0; j < k; ++j) {
      tmp += mat[i - 1][j] + mat[i][j];
    }
    for (int j = 0; j <= m - k; ++j) {
      row[i][j] = tmp;
      tmp += mat[i - 1][j + k] + mat[i][j + k] - mat[i - 1][j] - mat[i][j];
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= m - k; ++j) {
      int tmp = 0;
      if (j - k >= 0) {
        tmp = max(tmp, rowl[i - 1][j - k]);
      }
      if (j + k <= m - k) {
        tmp = max(tmp, rowr[i - 1][j + k]);
      }
      int multi = 0;
      for (int r = j - k + 1; r < j; ++r) {
        multi += mat[i - 1][r + k - 1];
        if (r >= 0) {
          tmp = max(tmp, dp[i - 1][r] - multi);
        }
      }
      tmp = max(tmp, dp[i - 1][j] - multi - mat[i - 1][j + k - 1]);
      multi = 0;
      for (int r = j + k - 1; r > j; --r) {
        multi += mat[i - 1][r];
        tmp = max(tmp, dp[i - 1][r] - multi);
      }
      dp[i][j] = tmp + row[i][j];
    }
    rowl[i][0] = dp[i][0];
    for (int j = 1; j <= m - k; ++j) {
      rowl[i][j] = max(rowl[i][j - 1], dp[i][j]);
    }
    rowr[i][m - k] = dp[i][m - k];
    for (int j = m - k - 1; j >= 0; --j) {
      rowr[i][j] = max(rowr[i][j + 1], dp[i][j]);
    }
  }
  int ans = 0;
  for (int j = 0; j <= m - k; ++j) {
    ans = max(ans, dp[n][j]);
  }
  cout << ans << '\n';
}
