#include <bits/stdc++.h>
using namespace std;
long long N, M, K, ans;
long long a[105][21005];
long long sum[105][21005];
long long dp[105][21005];
long long bstdpl[21005];
long long bstdpr[21005];
long long suma2(long long i, long long j) {
  return sum[i][j + K - 1] - sum[i][j - 1] + sum[i + 1][j + K - 1] -
         sum[i + 1][j - 1];
}
long long suma1(long long i, long long j) {
  return sum[i][j + K - 1] - sum[i][j - 1];
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> N >> M >> K;
  for (long long i = 1; i <= N; i++)
    for (long long j = 1; j <= M; j++) {
      cin >> a[i][j];
      sum[i][j] = sum[i][j - 1] + a[i][j];
    }
  for (long long i = 1; i <= N; i++)
    for (long long j = M + 1; j <= M + 2 * K; j++) sum[i][j] = sum[i][j - 1];
  for (long long i = N; i >= 1; i--) {
    for (long long j = 1; j + K - 1 <= M; j++) {
      long long tmp = 0;
      for (long long k = max(1LL, j - K + 1LL); k <= j; k++)
        tmp = max(tmp, dp[i + 1][k] + suma2(i, j) - sum[i + 1][k + K - 1] +
                           sum[i + 1][j - 1]);
      for (long long k = j; k <= min(M, j + K - 1LL); k++)
        tmp = max(tmp, dp[i + 1][k] + suma2(i, j) - sum[i + 1][j + K - 1] +
                           sum[i + 1][k - 1]);
      if (j > K) tmp = max(tmp, suma2(i, j) + bstdpl[j - K]);
      if (j + K <= M) tmp = max(tmp, suma2(i, j) + bstdpr[j + K]);
      dp[i][j] = tmp;
      ans = max(ans, tmp);
    }
    for (long long j = 1; j <= M; j++) bstdpl[j] = max(dp[i][j], bstdpl[j - 1]);
    for (long long j = M; j >= 1; j--) bstdpr[j] = max(bstdpr[j + 1], dp[i][j]);
  }
  cout << ans << "\n";
  return 0;
}
