#include <bits/stdc++.h>
using namespace std;
void _print() { cout << '\n'; }
template <typename T, typename... Ts>
void _print(const T& value, const Ts&... values) {
  cout << ' ' << value;
  _print(values...);
}
template <typename T, typename... Ts>
void print(const T& value, const Ts&... values) {
  cout << value;
  _print(values...);
}
const long long N = 2e4 + 5;
long long n, m, len;
long long _a[55][N];
long long get1(long long x, long long l, long long r = 0) {
  if (l > r) return 0;
  if (r == 0) r = l + len - 1;
  return _a[x][r] - _a[x][l - 1];
}
long long get2(long long x, long long l, long long r = 0) {
  if (l > r) return 0;
  if (r == 0) r = l + len - 1;
  return _a[x][r] - _a[x][l - 1] + _a[x + 1][r] - _a[x + 1][l - 1];
}
long long dp[55][N];
long long mxl[55][N], mxr[55][N];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> len;
  for (long long i = (1); i <= (n); i++) {
    for (long long j = (1); j <= (m); j++)
      cin >> _a[i][j], _a[i][j] += _a[i][j - 1];
  }
  for (long long day = (1); day <= (n); day++) {
    for (long long p = (1); p <= (m - len + 1); p++) {
      long long& res = dp[day][p];
      long long other = mxr[day - 1][p + len];
      if (p - len >= 1) other = max(other, mxl[day - 1][p - len]);
      const long long base = get2(day, p, p + len - 1);
      res = max(res, base + other);
      for (long long rp = max(1LL, p - len + 1), lim = min(m, p + len - 1);
           rp <= lim; rp++) {
        if (rp + len - 1 > m) break;
        long long dup = get1(day, max(rp, p), min(p + len - 1, rp + len - 1));
        res = max(res, dp[day - 1][rp] + base - dup);
      }
    }
    for (long long i = (1); i <= (m); i++)
      mxl[day][i] = max(mxl[day][i - 1], dp[day][i]);
    for (long long i = (m); i >= (1); i--)
      mxr[day][i] = max(mxr[day][i + 1], dp[day][i]);
  }
  long long ans = 0;
  for (long long p = (1); p <= (m); p++) ans = max(ans, dp[n][p]);
  cout << ans << '\n';
}
