#include <bits/stdc++.h>
using namespace std;
const int MAXN = 50 + 10;
const int MAXM = (int)2e4 + 10;
int n, m, k, a[MAXN][MAXM];
int s[MAXN][MAXM];
int dp[MAXN][MAXM];
struct SegmentTree {
  int s[MAXM * 5];
  void init(int k, int l, int r) {
    if (l == r) {
      s[k] = -1e9;
      return;
    }
    init(k << 1, l, ((l + r) >> 1));
    init(k << 1 | 1, ((l + r) >> 1) + 1, r);
    s[k] = -1e9;
  }
  void update(int k, int l, int r, int i, int v) {
    if (l == r) {
      s[k] = v;
      return;
    }
    if (i <= ((l + r) >> 1)) {
      update(k << 1, l, ((l + r) >> 1), i, v);
    } else {
      update(k << 1 | 1, ((l + r) >> 1) + 1, r, i, v);
    }
    s[k] = max(s[k << 1], s[k << 1 | 1]);
  }
  int query(int k, int l, int r, int i, int j) {
    if (l > j || r < i) {
      return -1e9;
    }
    if (i <= l && r <= j) {
      return s[k];
    }
    return max(query(k << 1, l, ((l + r) >> 1), i, j),
               query(k << 1 | 1, ((l + r) >> 1) + 1, r, i, j));
  }
} st1, st2;
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]);
      s[i][j] = s[i][j - 1] + a[i][j];
    }
  }
  st1.init(1, 1, m);
  st2.init(1, 1, m);
  for (int j = k; j <= m; ++j) {
    dp[1][j] = s[1][j] - s[1][j - k];
  }
  for (int i = 2; i <= n; ++i) {
    for (int j = k; j <= m; ++j) {
      st1.update(1, 1, m, j, dp[i - 1][j] - s[i][j - k]);
      st2.update(1, 1, m, j, dp[i - 1][j] + s[i][j] - s[i][j - k]);
      dp[i][j] = max(dp[i][j], s[i][j] + st1.query(1, 1, m, j - k + 1, j));
      if (j > k) {
        dp[i][j] =
            max(dp[i][j], s[i][j] - s[i][j - k] + st2.query(1, 1, m, 1, j - k));
      }
    }
    for (int j = m; j >= k; --j) {
      st1.update(1, 1, m, j, dp[i - 1][j] + s[i][j]);
      st2.update(1, 1, m, j, dp[i - 1][j] + s[i][j] - s[i][j - k]);
      dp[i][j] = max(dp[i][j], -s[i][j - k] + st1.query(1, 1, m, j, j + k - 1));
      if (j + k - 1 < m) {
        dp[i][j] =
            max(dp[i][j], s[i][j] - s[i][j - k] + st2.query(1, 1, m, j + k, m));
      }
    }
  }
  printf("%d\n", *max_element(dp[n] + 1, dp[n] + 1 + m));
  return 0;
}
