#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int a[55][20005], sum[55][20005];
int b[55][20005], c[55][20005];
int dp[55][20005];
int maxfront[20005], maxback[20005];
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      scanf("%d", &a[i][j]);
      sum[i][j] = sum[i][j - 1] + a[i][j];
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m - k + 1; j++)
      c[i][j] = sum[i][j + k - 1] - sum[i][j - 1] + sum[i + 1][j + k - 1] -
                sum[i + 1][j - 1];
  for (int i = 1; i <= m; i++) dp[1][i] = c[1][i];
  for (int i = 1; i <= m; i++) maxfront[i] = max(maxfront[i - 1], dp[1][i]);
  for (int i = m; i >= 1; i--) maxback[i] = max(maxback[i + 1], dp[1][i]);
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= m - k + 1; j++) {
      int t = max(maxfront[max(j - k, 0)], maxback[min(m + 1, j + k)]);
      for (int l = max(j - k + 1, 1); l <= j; l++)
        t = max(dp[i - 1][l] - (sum[i][l + k - 1] - sum[i][j - 1]), t);
      for (int l = j + 1; l <= min(m - k + 1, j + k - 1); l++)
        t = max(dp[i - 1][l] - (sum[i][j + k - 1] - sum[i][l - 1]), t);
      dp[i][j] = t + c[i][j];
    }
    for (int j = 1; j <= m; j++) maxfront[j] = max(maxfront[j - 1], dp[i][j]);
    for (int j = m; j >= 1; j--) maxback[j] = max(maxback[j + 1], dp[i][j]);
  }
  printf("%d", max(maxfront[m], maxback[1]));
  return 0;
}
