#include <bits/stdc++.h>
using namespace std;
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while (!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
  cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if (idx > 0)
    cerr << ", ";
  else
    cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss;
  ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
const int LOG = 21;
const int NN = (int)55;
const int MM = (int)2e4 + 25;
const int MOD = (int)998244853;
const int INF = 1 << 27;
int mul(int x, int y) { return (1LL * x * y) % MOD; }
int add(int x, int y) {
  long long res = x;
  res += y;
  return (res % MOD + MOD) % MOD;
}
int fast_pow(int x, int y) {
  if (y == 0) return 1;
  if (y & 1)
    return mul(x, fast_pow(x, y - 1));
  else {
    int aux = fast_pow(x, y >> 1);
    return mul(aux, aux);
  }
}
int two(int x) { return 1 << x; }
bool contain(int mask, int bit) { return (mask & two(bit)) > 0; }
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
int bit_count(int x) { return x == 0 ? 0 : (x & 1) + bit_count(x >> 1); }
int n, m, k;
int dp[NN][MM];
int dp_pre[MM], dp_suff[MM];
int grid[NN][MM];
void solve() {
  for (int r = n - 1; r >= 0; r--) {
    for (int c = 0; c < m; c++) {
      int val = 0;
      for (int x = c; x < c + k; x++) val += grid[r][x] + grid[r + 1][x];
      if (c - k >= 0)
        dp[r][c] = ((dp[r][c]) > (dp_pre[c - k] + val) ? (dp[r][c])
                                                       : (dp_pre[c - k] + val));
      dp[r][c] = ((dp[r][c]) > (dp_suff[c + k] + val) ? (dp[r][c])
                                                      : (dp_suff[c + k] + val));
      val = 0;
      for (int x = c; x < c + k; x++) val += grid[r][x];
      for (int x = c; x < c + k; x++) {
        dp[r][c] = ((dp[r][c]) > (dp[r + 1][x] + val) ? (dp[r][c])
                                                      : (dp[r + 1][x] + val));
        val += grid[r + 1][x];
      }
      val = 0;
      for (int x = c; x < c + k; x++) val += grid[r][x];
      for (int x = c; x >= 0 && x >= c - k; x--) {
        dp[r][c] = ((dp[r][c]) > (dp[r + 1][x] + val) ? (dp[r][c])
                                                      : (dp[r + 1][x] + val));
        val += grid[r + 1][x + k - 1];
      }
    }
    dp_pre[0] = dp[r][0];
    for (int c = 1; c < m; c++)
      dp_pre[c] = ((dp_pre[c - 1]) > (dp[r][c]) ? (dp_pre[c - 1]) : (dp[r][c]));
    dp_suff[m] = 0;
    for (int c = m - 1; c >= 0; c--)
      dp_suff[c] =
          ((dp_suff[c + 1]) > (dp[r][c]) ? (dp_suff[c + 1]) : (dp[r][c]));
  }
  int ans = dp_suff[0];
  printf("%d\n", ans);
  return;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", &grid[i][j]);
  solve();
  return 0;
}
