#include <bits/stdc++.h>
using namespace std;
const long long N = 2e4 + 5;
long long n, m, k;
long long arr[55][N];
long long dp[55][N];
long long prefixMx[55][N];
long long suffixMx[55][N];
long long sum[55][N];
long long getSum(long long i1, long long j1, long long i2, long long j2) {
  if (i1 > n) return 0;
  assert(i1 <= i2);
  assert(j1 <= j2);
  return sum[i2][j2] - sum[i2][j1 - 1] - sum[i1 - 1][j2] + sum[i1 - 1][j1 - 1];
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  for (long long i = 1; i <= n; ++i) {
    for (long long j = 1; j <= m; ++j) {
      cin >> arr[i][j];
      sum[i][j] = arr[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
    }
  }
  if (n == 1) {
    long long res = 0;
    for (long long start = 1; start + k - 1 <= m; ++start) {
      res = max(res, sum[1][start + k - 1] - sum[1][start - 1]);
    }
    cout << res;
    return 0;
  }
  for (long long j = 1; j + k - 1 <= m; ++j) {
    dp[1][j] = getSum(1, j, 2, j + k - 1);
    for (long long j = 1; j + k - 1 <= m; ++j) {
      prefixMx[1][j] = max(dp[1][j], prefixMx[1][j - 1]);
    }
    for (long long j = m - k + 1; j >= 1; --j) {
      suffixMx[1][j] = max(dp[1][j], suffixMx[1][j + 1]);
    }
  }
  for (long long i = 2; i <= n; ++i) {
    for (long long j = 1; j + k - 1 <= m; ++j) {
      long long &curr = dp[i][j];
      for (long long prevJ = j - 22; prevJ <= j + 22; ++prevJ) {
        if (prevJ < 1) continue;
        if (prevJ + k - 1 > m) continue;
        long long cost = getSum(i + 1, j, i + 1, j + k - 1);
        long long pos = max(prevJ + k, j);
        if (pos <= j + k - 1) {
          cost += getSum(i, pos, i, j + k - 1);
        }
        pos = min(j + k - 1, prevJ - 1);
        if (pos >= j) {
          cost += getSum(i, j, i, pos);
        }
        curr = max(curr, cost + dp[i - 1][prevJ]);
      }
      long long prevJ = (j - 1) - k + 1;
      if (prevJ >= 1) {
        long long extra = getSum(i, j, i + 1, j + k - 1);
        if (i == n) extra = getSum(i, j, i, j + k - 1);
        curr = max(curr, extra + prefixMx[i - 1][prevJ]);
      }
      prevJ = j + k;
      if (prevJ + k - 1 <= m) {
        long long extra = getSum(i, j, i + 1, j + k - 1);
        if (i == n) extra = getSum(i, j, i, j + k - 1);
        curr = max(curr, extra + suffixMx[i - 1][prevJ]);
      }
    }
    for (long long j = 1; j + k - 1 <= m; ++j) {
      prefixMx[i][j] = max(dp[i][j], prefixMx[i][j - 1]);
    }
    for (long long j = m - k + 1; j >= 1; --j) {
      suffixMx[i][j] = max(dp[i][j], suffixMx[i][j + 1]);
    }
  }
  cout << suffixMx[n][1];
}
