#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v);
template <typename A, typename B>
ostream &operator<<(ostream &cout, pair<A, B> const &p) {
  return cout << "(" << p.first << ", " << p.second << ")";
}
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v) {
  cout << "[";
  for (int i = 0; i < v.size(); i++) {
    if (i) cout << ", ";
    cout << v[i];
  }
  return cout << "]";
}
template <typename A, typename B>
istream &operator>>(istream &cin, pair<A, B> &p) {
  cin >> p.first;
  return cin >> p.second;
}
mt19937 rng(steady_clock::now().time_since_epoch().count());
void usaco(string filename) {
  freopen((filename + ".in").c_str(), "r", stdin);
  freopen((filename + ".out").c_str(), "w", stdout);
}
const long double pi = 3.14159265358979323846;
const long long mod = 1000000007;
long long n, m, k, q, Q, T, l, r, x, y, z;
long long a[1000005];
long long b[1000005];
long long c[1000005];
string second, t;
long long ans = 0;
long long dp[52][20005];
long long mat[52][20005];
long long pre[52][20005];
long long pmax[52][20005];
long long smax[52][20005];
pair<long long, long long> isect(pair<long long, long long> a,
                                 pair<long long, long long> b) {
  return make_pair(max(a.first, b.first), min(a.second, b.second));
}
long long gsum(int r, int c1, int c2) {
  long long v = pre[r][c2];
  if (c1 > 0) v -= pre[r][c1 - 1];
  return v;
}
long long rec(int r, int c) {
  if (r >= n || c >= m - k + 1) return 0;
  if (dp[r][c] != -1) return dp[r][c];
  long long second = gsum(r, c, c + k - 1);
  long long s2;
  if (r == n - 1)
    s2 = 0;
  else
    s2 = gsum(r + 1, c, c + k - 1);
  if (r == 0) {
    return dp[r][c] = second + s2;
  }
  long long lpos = max(c - k + 1, 0LL);
  long long rpos = min(c + k - 1, m - k);
  if (lpos != 0) dp[r][c] = max(dp[r][c], second + s2 + pmax[r - 1][lpos - 1]);
  if (rpos != m - k)
    dp[r][c] = max(dp[r][c], second + s2 + smax[r - 1][rpos + 1]);
  for (long long i = (lpos); i < (rpos + 1); i++) {
    pair<long long, long long> iv =
        isect(make_pair(i, i + k - 1), make_pair(c, c + k - 1));
    long long loss = 0;
    if (iv.first <= iv.second) loss = gsum(r, iv.first, iv.second);
    dp[r][c] = max(dp[r][c], second + s2 - loss + dp[r - 1][i]);
  }
  return dp[r][c];
}
int main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  };
  cin >> n >> m >> k;
  for (long long i = 0; i < (n); i++)
    for (int ele = 0; ele < m; ele++) cin >> mat[i][ele];
  ;
  for (long long i = 0; i < (n); i++) {
    long long run = 0;
    for (long long j = 0; j < (m); j++) {
      run += mat[i][j];
      pre[i][j] = run;
    }
  }
  for (long long i = 0; i < (n); i++)
    for (long long j = 0; j < (m); j++) dp[i][j] = -1;
  for (long long i = 0; i < (n); i++) {
    for (long long j = 0; j < (m - k + 1); j++) ans = max(ans, rec(i, j));
    long long run = 0;
    for (long long j = 0; j < (m - k + 1); j++) {
      run = max(run, dp[i][j]);
      pmax[i][j] = run;
    }
    run = 0;
    for (long long j = (m - k); j >= 0; j--) {
      run = max(run, dp[i][j]);
      smax[i][j] = run;
    }
  }
  cout << ans << endl;
}
