#include <bits/stdc++.h>
using namespace std;
const int Maxn = 55;
const int Maxm = 2e4 + 5;
struct node {
  int l, r;
  int ma;
} tree[4 * Maxm];
int sum[Maxn][Maxm], dp[Maxn][Maxm];
void build(int root, int l, int r, int k) {
  tree[root].l = l;
  tree[root].r = r;
  if (l == r) {
    tree[root].ma = dp[k][l];
    return;
  }
  int m = (l + r) >> 1;
  build(root << 1, l, m, k);
  build(root << 1 | 1, m + 1, r, k);
  tree[root].ma = max(tree[root << 1].ma, tree[root << 1 | 1].ma);
}
int query(int root, int l, int r) {
  if (l > r) return 0;
  if (l <= tree[root].l && tree[root].r <= r) return tree[root].ma;
  int m = (tree[root].l + tree[root].r) >> 1;
  int ret = 0;
  if (l <= m) ret = max(ret, query(root << 1, l, r));
  if (r > m) ret = max(ret, query(root << 1 | 1, l, r));
  return ret;
}
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &sum[i][j]);
      sum[i][j] += sum[i][j - 1];
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    build(1, 1, m, i - 1);
    for (int j = k; j <= m; j++) {
      dp[i][j] = max(dp[i][j], query(1, 1, j - k) + sum[i][j] - sum[i][j - k] +
                                   sum[i + 1][j] - sum[i + 1][j - k]);
      dp[i][j] = max(dp[i][j], query(1, j + k, m) + sum[i][j] - sum[i][j - k] +
                                   sum[i + 1][j] - sum[i + 1][j - k]);
      for (int l = j - k + 1; l < j + k; l++)
        dp[i][j] =
            max(dp[i][j], dp[i - 1][l] + sum[i][j] - sum[i][j - k] +
                              sum[i + 1][j] - sum[i + 1][j - k] -
                              sum[i][min(j, l)] + sum[i][max(j - k, l - k)]);
      ans = max(ans, dp[i][j]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
