#include <bits/stdc++.h>
using namespace std;
struct piii {
  long long first, second, th;
  bool operator<(const piii &b) {
    if (first != b.first) return first < b.first;
    if (second != b.second) return second < b.second;
    return th < b.th;
  }
};
const int maxn = 55;
const int maxm = 20200;
int n, m, k;
int a[maxn][maxm], f[maxn][maxm], s[maxn][maxm];
int mxl[maxm], mxr[maxm];
int sum(int i, int j) {
  return s[i][j] - s[i][j - k] + s[i - 1][j] - s[i - 1][j - k];
}
int main() {
  cout << setprecision(2) << fixed;
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) cin >> a[i][j];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) s[i][j] = s[i][j - 1] + a[i][j];
  for (int i = k; i <= m; i++) f[2][i] = sum(2, i);
  n++;
  for (int i = 3; i <= n; i++) {
    for (int j = 1; j <= m; j++) mxl[j] = max(mxl[j - 1], f[i - 1][j]);
    for (int j = m; j > 0; j--) mxr[j] = max(mxr[j + 1], f[i - 1][j]);
    for (int j = k; j <= m; j++) {
      int cursum = 0, t = j - k + 1;
      while (t <= m && t < j + k) {
        if (t <= j) cursum += a[i - 1][t];
        if (t > j) cursum -= a[i - 1][t - k];
        f[i][j] = max(f[i][j], f[i - 1][t] - cursum);
        t++;
      }
      f[i][j] = max(f[i][j], max(mxl[j - k], mxr[j + k]));
      f[i][j] += sum(i, j);
    }
  }
  int res = 0;
  for (int i = 1; i <= m; i++) res = max(res, f[n][i]);
  cout << res;
  return 0;
}
