#include <bits/stdc++.h>
using namespace std;
using big = long long;
const int N = 60, M = 20200;
int f[N][M], l[N][M], r[N][M];
int a[N][M], s[N][M];
int get(int x1, int y1, int x2, int y2) {
  return s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1];
}
int get(int x2, int y2, int k) { return get(x2 - 1, y2 - k + 1, x2, y2); }
int get_row(int x, int y, int k) { return get(x, y - k + 1, x, y); }
int get2(int x, int j, int jj, int k) {
  assert(abs(j - jj) <= k);
  int row1 = get_row(x, j, k);
  int row2 =
      get(x - 1, min(j, jj) - k + 1, x - 1, max(j, jj)) - get_row(x - 1, jj, k);
  return row1 + row2;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      cin >> a[i][j];
    }
  }
  ++n;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      s[i][j] = s[i - 1][j] + s[i][j - 1] + a[i][j] - s[i - 1][j - 1];
    }
  }
  int ans = 0;
  if (n == 1) {
    for (int j = k; j <= m; ++j) {
      ans = max(ans, get(1, j - k + 1, 1, j));
    }
  } else {
    for (int i = 2; i <= 2; ++i) {
      for (int j = k; j <= m; ++j) {
        f[i][j] = max(f[i][j], get(i, j, k));
        ans = max(ans, f[i][j]);
      }
      for (int j = 1; j <= m; ++j) {
        l[i][j] = max(f[i][j], l[i][j - 1]);
      }
      for (int j = m; j >= 1; --j) {
        r[i][j] = max(f[i][j], r[i][j + 1]);
      }
    }
    for (int i = 3; i <= n; ++i) {
      for (int j = k; j <= m; ++j) {
        for (int jj = j - k; jj <= j + k; ++jj) {
          f[i][j] = max(f[i][j], f[i - 1][jj] + get2(i, j, jj, k));
        }
        f[i][j] = max(f[i][j], max(l[i - 1][max(j - k - 1, 0)],
                                   r[i - 1][min(j + k, m + 1)]) +
                                   get(i, j, k));
        ans = max(ans, f[i][j]);
      }
      for (int j = 1; j <= m; ++j) {
        l[i][j] = max(f[i][j], l[i][j - 1]);
      }
      for (int j = m; j >= 1; --j) {
        r[i][j] = max(f[i][j], r[i][j + 1]);
      }
    }
  }
  cout << ans << endl;
}
