#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long N, M, K;
long long A[55][20202], As[55][20202];
long long dp[20202], dp2[20202];
long long i, j, k;
int main() {
  scanf("%lld%lld%lld", &N, &M, &K);
  for (i = 0; i < N; ++i) {
    for (j = 0; j < M; ++j) {
      scanf("%lld", &A[i][j]);
      As[i][j + 1] = A[i][j] + As[i][j];
    }
  }
  for (i = 0; i < N + 1; ++i) {
    for (j = 0; j < M + 1; ++j) {
      dp2[j] = dp[j];
      dp[j] = 0;
    }
    deque<pair<long long, long long> > dq;
    for (j = K; j < M + 1; ++j) {
      while (dq.size() && dq.back().first < dp2[j]) {
        dq.pop_back();
      }
      dq.push_back({dp2[j], j});
    }
    for (j = 0; j < M + 1; ++j) {
      long long a = As[i][j] - As[i][max(0ll, j - K)] + As[i + 1][j] -
                    As[i + 1][max(0ll, j - K)];
      for (k = 0; k < K; ++k) {
        if (j + k <= M) {
          long long b = As[i][j] - As[i][max(0ll, j + k - K)];
          dp[j] = max(dp[j], dp2[j + k] + a - b);
        }
        if (j - k >= 0) {
          long long b = As[i][j - k] - As[i][max(0ll, j - K)];
          dp[j] = max(dp[j], dp2[j - k] + a - b);
        }
      }
      while (dq.size() && dq.front().second < j + K) {
        dq.pop_front();
      }
      if (dq.size() > 0) {
        dp[j] = max(dp[j], dq.front().first + a);
      }
      if (j - K + 1 < 0) continue;
      while (dq.size() && dq.back().first < dp2[j - K + 1]) {
        dq.pop_back();
      }
      dq.push_back({dp2[j - K + 1], 1e9});
    }
  }
  printf("%lld", dp[0]);
  return 0;
}
