#include <bits/stdc++.h>
using namespace std;
long long arr[53][20010];
long long pr[53][20010];
long long mal[53][20010];
long long mar[53][20010];
long long dp[53][20010];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m, k;
  cin >> n >> m >> k;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      cin >> arr[i][j];
      pr[i][j] = pr[i][j - 1] + arr[i][j];
    }
  }
  for (long long i = 1; i <= n + 1; i++) {
    for (long long j = 1; j <= m; j++) {
      if (i > 1 && j >= k) {
        long long sum =
            pr[i][j] - pr[i][j - k] + pr[i - 1][j] - pr[i - 1][j - k];
        long long add = 0;
        if (j - k >= k) add = max(mal[i - 1][j - k], add);
        if (j + k <= m) add = max(mar[i - 1][j + k], add);
        for (long long z = max(j - k + 1, k); z <= min(j + k - 1, m); z++) {
          add = max(add, dp[i - 1][z] - pr[i - 1][min(j, z)] +
                             pr[i - 1][max(j - k, z - k)]);
        }
        dp[i][j] = add + sum;
      }
    }
    for (long long j = 1; j <= m; j++) {
      mal[i][j] = max(mal[i][j - 1], dp[i][j]);
    }
    for (long long j = m; j >= 0; j--) {
      mar[i][j] = max(mar[i][j + 1], dp[i][j]);
    }
  }
  cout << mal[n + 1][m] << endl;
  return 0;
}
