#include <bits/stdc++.h>
using namespace std;
const long long ff = 400 + 13;
const long long ft = 3e4 + 13;
const long long mod = 998244353;
long long n, m, k, mx;
long long a[ff][ft], sum[ff][ft], f[ff][ft], ans, qzmx[ft], hzmx[ft];
long long getsum(long long i, long long l, long long r) {
  return sum[i][r] - sum[i][l - 1];
}
signed main() {
  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 j = 1; j <= m; ++j)
    mx = max(j - k, 0LL), f[1][j] = getsum(1, mx + 1, j) + getsum(2, mx + 1, j);
  for (long long i = 2; i <= n; ++i) {
    qzmx[0] = hzmx[m + 1] = 0;
    for (long long j = 1, z = m; j <= m; ++j, --z)
      qzmx[j] = max(qzmx[j - 1], f[i - 1][j]),
      hzmx[z] = max(hzmx[z + 1], f[i - 1][z]);
    for (long long j = 1; j <= m; ++j) {
      long long ls = max(j - k + 1, 0LL);
      long long rs = min(j + k - 1, m);
      long long ss = getsum(i, ls, j) + getsum(i + 1, ls, j);
      f[i][j] = max(qzmx[ls - 1], hzmx[rs + 1]) + ss;
      for (long long r = ls; r <= j; ++r)
        f[i][j] = max(f[i][j], ss + f[i - 1][r] - getsum(i, ls, r));
      for (long long r = j + 1; r <= rs; ++r)
        f[i][j] = max(f[i][j], ss + f[i - 1][r] - getsum(i, r - k + 1, j));
    }
  }
  for (long long i = 1; i <= n; ++i)
    for (long long j = 1; j <= m; ++j) ans = max(ans, f[i][j]);
  cout << ans;
}
