#include <bits/stdc++.h>
using namespace std;
const int SIZE1 = 54;
const int SIZE2 = 2e4 + 23;
long long pref[SIZE1][SIZE2];
long long tab[SIZE1][SIZE2];
long long dp[SIZE1][SIZE2];
long long maks1[SIZE2], maks2[SIZE2];
int n, m, k;
long long suma(int i, int j) {
  return pref[i + 1][j + k - 1] - pref[i - 1][j + k - 1] - pref[i + 1][j - 1] +
         pref[i - 1][j - 1];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      cin >> tab[i][j];
    }
  }
  for (int i = 1; i < SIZE1; i++)
    for (int j = 1; j < SIZE2; j++)
      pref[i][j] =
          pref[i - 1][j] + pref[i][j - 1] - pref[i - 1][j - 1] + tab[i][j];
  for (int i = 1; i <= m; i++) {
    dp[1][i] = suma(1, i);
  }
  maks1[1] = dp[1][1];
  for (int j = 2; j <= m; j++) maks1[j] = max(maks1[j - 1], dp[1][j]);
  maks2[m] = dp[1][m];
  for (int j = m - 1; j >= 1; j--) maks2[j] = max(maks2[j + 1], dp[1][j]);
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      long long intersection = 0;
      long long sum = suma(i, j);
      if (j - k >= 1) dp[i][j] = max(dp[i][j], maks1[j - k] + sum);
      int iter = 0;
      for (int l = j - k + 1; l < j + k; l++) {
        int shift = l - (j - k + 1);
        if (j + shift <= j + k - 1) {
          intersection += tab[i][j + shift];
        } else {
          intersection -= tab[i][j + iter];
          iter++;
        }
        if (l >= 1) dp[i][j] = max(dp[i][j], dp[i - 1][l] + sum - intersection);
      }
      if (j + k <= m) dp[i][j] = max(dp[i][j], maks2[j + k] + sum);
    }
    maks1[1] = dp[i][1];
    for (int j = 2; j <= m; j++) maks1[j] = max(maks1[j - 1], dp[i][j]);
    maks2[m] = dp[i][m];
    for (int j = m - 1; j >= 1; j--) maks2[j] = max(maks2[j + 1], dp[i][j]);
  }
  long long res = -1;
  for (int i = 1; i <= m; i++) res = max(res, dp[n][i]);
  cout << res;
}
