#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "{" << p.first << "," << p.second << "}";
  return os;
}
const int N = 3e5 + 5;
const int oo = 1e9 + 7;
int qsum[55][N];
int dp[55][N];
int pre[55][N];
int suf[55][N];
int n, m, k;
inline int sum(int i, int j, int k) {
  return qsum[i][min(j + k - 1, m)] - qsum[i][j - 1] +
         qsum[i + 1][min(j + k - 1, m)] - qsum[i + 1][j - 1];
}
inline int intersect(int i, int x, int y, int m, int k) {
  return qsum[i][min({x + k - 1, y + k - 1, m})] - qsum[i][max(x - 1, y - 1)];
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> qsum[i][j];
      qsum[i][j] += qsum[i][j - 1];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int now = sum(i, j, k);
      dp[i][j] = now;
      if (j - k >= 1) {
        dp[i][j] = max(dp[i][j], pre[i - 1][j - k] + now);
      }
      if (j + k <= m) {
        dp[i][j] = max(dp[i][j], suf[i - 1][j + k] + now);
      }
      for (int x = max(j - k + 1, 1); x <= min(j + k - 1, m); x++) {
        dp[i][j] = max(dp[i][j], now + dp[i - 1][x] - intersect(i, x, j, m, k));
      }
      pre[i][j] = max(pre[i][j - 1], dp[i][j]);
    }
    for (int j = m; j >= 1; j--) suf[i][j] = max(suf[i][j + 1], dp[i][j]);
  }
  cout << pre[n][m] << "\n";
}
