#include <bits/stdc++.h>
using namespace std;
const int N = 2e4 + 7;
int t[4 * N], o[4 * N];
inline void build(int v, int l, int r, int a[]) {
  if (l == r) {
    t[v] = a[l], o[v] = 0;
  } else {
    int m = (r + l) >> 1;
    build(v + v + 1, l, m, a);
    build(v + v + 2, m + 1, r, a);
    t[v] = max(t[v + v + 1], t[v + v + 2]);
  }
}
inline void push(int v) {
  t[v] += o[v];
  if (v + v + 2 < 4 * N) {
    o[v + v + 1] += o[v];
    o[v + v + 2] += o[v];
  }
  o[v] = 0;
}
inline void update(int v, int l, int r, int tl, int tr, int val) {
  push(v);
  if (tl > tr) return;
  if (tl == l && tr == r) {
    o[v] += val;
    push(v);
  } else {
    int m = (r + l) >> 1;
    update(v + v + 1, l, m, tl, min(tr, m), val);
    update(v + v + 2, m + 1, r, max(tl, m + 1), tr, val);
    t[v] = max(t[v + v + 1], t[v + v + 2]);
  }
}
inline void update(int l, int r, int val, int n) {
  update(0, 0, n - 1, l, r, val);
}
inline int findMax(int v, int l, int r, int tl, int tr) {
  push(v);
  if (tl > tr) return 0;
  if (tl == l && tr == r) {
    return t[v];
  }
  int m = (r + l) >> 1;
  int t1 = findMax(v + v + 1, l, m, tl, min(m, tr));
  int t2 = findMax(v + v + 2, m + 1, r, max(m + 1, tl), tr);
  return max(t1, t2);
}
inline int findMax(int l, int r, int n) { return findMax(0, 0, n - 1, l, r); }
int prefN[N];
int n, m, k;
int findSum(int l, int r) {
  l = max(0, l);
  r = min(r, m - 1);
  if (l > r) return 0;
  return prefN[r] - (l ? prefN[l - 1] : 0);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n >> m >> k;
  int a[n][m];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
    }
  }
  int dp[n][m];
  int sum = 0;
  for (int j = 0; j < m + k - 1; ++j) {
    if (j < m) sum += a[0][j];
    if (j >= k - 1) {
      dp[0][j - k + 1] = sum;
      sum -= a[0][j - k + 1];
    }
  }
  for (int i = 1; i < n; ++i) {
    build(0, 0, m - 1, dp[i - 1]);
    for (int j = 0; j < m; ++j) {
      dp[i][j] = 0;
    }
    prefN[0] = a[i][0];
    for (int j = 1; j < m; ++j) {
      prefN[j] = prefN[j - 1] + a[i][j];
    }
    int suff[m];
    suff[m - 1] = dp[i - 1][m - 1] + findSum(m - 1, m + k - 2);
    for (int j = m - 2; j >= 0; --j) {
      suff[j] = max(suff[j + 1], dp[i - 1][j] + findSum(j, j + k - 1));
    }
    int pref[m];
    pref[0] = dp[i - 1][0] + findSum(0, k - 1);
    for (int j = 1; j < m; ++j) {
      pref[j] = max(pref[j - 1], dp[i - 1][j] + findSum(j, j + k - 1));
    }
    for (int j = 0; j < m; ++j) {
      int lN = j, rN = min(j + k - 1, m - 1);
      int sumN = findSum(lN, rN);
      int l = max(0, j - k + 1), r = rN;
      dp[i][j] = max((l ? pref[l - 1] : 0), (r + 1 < m ? suff[r + 1] : 0));
      dp[i][j] += sumN;
    }
    int L = max(0, 0 - k + 1), R = min(0 + k - 1, m - 1);
    for (int x = L; x <= R; ++x) {
      int lL = x, rL = min(x + k - 1, m - 1);
      int lT = max(lL, L), rT = min(rL, R);
      int sumN = findSum(L, R);
      int sumL = findSum(lL, rL);
      int sumT = findSum(lT, rT);
      update(x, x, sumN + sumL - sumT, m);
    }
    dp[i][0] = max(dp[i][0], findMax(L, R, m));
    for (int j = 1; j < m; ++j) {
      L = max(0, j - k + 1), R = min(j + k - 1, m - 1);
      update(j, min(m - 1, j + k - 2), -a[i][j - 1], m);
      if (j + k - 1 <= m - 1) {
        update(L, j - 1, a[i][R], m);
        update(R, R, findSum(j, min(R + k - 1, m - 1)), m);
      }
      dp[i][j] = max(dp[i][j], findMax(L, R, m));
    }
  }
  int ans = 0;
  for (int i = 0; i < m; ++i) {
    ans = max(ans, dp[n - 1][i]);
  }
  cout << ans;
}
