#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > A(55, vector<int>(2e4 + 5)), S(55, vector<int>(2e4 + 5));
vector<vector<int> > DP(2, vector<int>(2e4 + 5)), LR(2, vector<int>(2e4 + 5)),
    RL(2, vector<int>(2e4 + 5));
int N, M, K;
int PS(int n, int l, int r = -1) {
  if (r == -1) r = l + K - 1;
  return S[n][r] - S[n][l - 1];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> M >> K;
  for (int r = 1; r <= N; r++) {
    for (int c = 1; c <= M; c++) {
      cin >> A[r][c];
      S[r][c] = A[r][c] + S[r][c - 1];
    }
  }
  int prev = 0, curr = 1;
  for (int r = 1; r <= N; r++) {
    for (int c = 1; c + K - 1 <= M; c++) {
      int v = max(LR[prev][max(0, c - K)], RL[prev][c + K]);
      int j = max(1, c - K + 1);
      for (; j < c + K; j++) {
        int s = PS(r, max(j, c), min(j + K - 1, c + K - 1));
        v = max(v, DP[prev][j] - s);
      }
      LR[curr][c] = RL[curr][c] = DP[curr][c] = v + PS(r, c) + PS(r + 1, c);
    }
    for (int x = 1; x <= M; x++) {
      LR[curr][x] = max(LR[curr][x], LR[curr][x - 1]);
      RL[curr][M - x] = max(RL[curr][M - x], RL[curr][M - x + 1]);
    }
    swap(prev, curr);
  }
  cout << *max_element(DP[prev].begin(), DP[prev].end()) << endl;
  return 0;
}
