#include <bits/stdc++.h>
using namespace std;
template <class T>
void _R(T &x) {
  cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(long long &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class T, class... U>
void R(T &head, U &...tail) {
  _R(head);
  R(tail...);
}
template <class T>
void _W(const T &x) {
  cout << x;
}
void _W(const int &x) { printf("%d", x); }
void _W(const long long &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T, class U>
void _W(const pair<T, U> &x) {
  _W(x.first);
  putchar(' ');
  _W(x.second);
}
template <class T>
void _W(const vector<T> &x) {
  for (auto i = x.begin(); i != x.end(); _W(*i++))
    if (i != x.cbegin()) putchar(' ');
}
void W() {}
template <class T, class... U>
void W(const T &head, const U &...tail) {
  _W(head);
  putchar(sizeof...(tail) ? ' ' : '\n');
  W(tail...);
}
int MOD = 1e9 + 7;
void ADD(long long &x, long long v) {
  x = (x + v) % MOD;
  if (x < 0) x += MOD;
}
const int SIZE = 80010;
long long ma[SIZE], _tmp[SIZE];
void push(int id) {
  if (_tmp[id] == 0) return;
  _tmp[id * 2] += _tmp[id];
  ma[id * 2] += _tmp[id];
  _tmp[id * 2 + 1] += _tmp[id];
  ma[id * 2 + 1] += _tmp[id];
  _tmp[id] = 0;
}
void pull(int id) { ma[id] = max(ma[id * 2], ma[id * 2 + 1]); }
void seg_init(int L, int R, int id) {
  ma[id] = _tmp[id] = 0;
  if (L == R) {
    return;
  }
  int mm = (L + R) / 2;
  seg_init(L, mm, id * 2);
  seg_init(mm + 1, R, id * 2 + 1);
  pull(id);
}
long long qq(int L, int R, int id, int ll, int rr) {
  if (R < ll || L > rr) return LLONG_MIN;
  if (L >= ll && R <= rr) return ma[id];
  int mm = (L + R) / 2;
  push(id);
  return max(qq(L, mm, id * 2, ll, rr), qq(mm + 1, R, id * 2 + 1, ll, rr));
}
void ins(int L, int R, int id, int ll, int rr, long long v) {
  if (R < ll || L > rr) return;
  if (L >= ll && R <= rr) {
    ma[id] += v;
    _tmp[id] += v;
    return;
  }
  int mm = (L + R) / 2;
  push(id);
  ins(L, mm, id * 2, ll, rr, v);
  ins(mm + 1, R, id * 2 + 1, ll, rr, v);
  pull(id);
}
int dp[52][SIZE];
int a[52][SIZE];
int dp0[52][SIZE];
int get(int lv, int x, int y) {
  x--;
  if (x <= 0) return dp0[lv][y];
  return dp0[lv][y] - dp0[lv][x];
}
int main() {
  int n, m, k;
  R(n, m, k);
  for (int i = (1); i <= (n); ++i)
    for (int j = (1); j <= (m); ++j) {
      R(a[i][j]);
      dp0[i][j] = dp0[i][j - 1] + a[i][j];
    }
  int r_bound = m + 1 - k;
  for (int i = (1); i <= (n); ++i) {
    if (i == 1) {
      for (int j = (1); j <= (r_bound); ++j)
        dp[i + 1][j] = get(1, j, j + k - 1) + get(2, j, j + k - 1);
      continue;
    } else {
      seg_init(1, r_bound, 1);
      for (int j = (1); j <= (r_bound); ++j) {
        ins(1, r_bound, 1, j, j, dp[i][j] + dp0[i][min(k, j - 1)]);
      }
    }
    for (int j = (1); j <= (r_bound); ++j) {
      dp[i + 1][j] = qq(1, r_bound, 1, 1, r_bound) + get(i + 1, j, j + k - 1);
      if (j + 1 <= r_bound) ins(1, r_bound, 1, j + 1, r_bound, -a[i][j]);
      if (j - k >= 1) ins(1, r_bound, 1, 1, j - k, -a[i][j]);
      if (j + k < r_bound) ins(1, r_bound, 1, j + k + 1, r_bound, a[i][j + k]);
      ins(1, r_bound, 1, 1, j, a[i][j + k]);
    }
  }
  int an = 0;
  for (int i = (1); i <= (r_bound); ++i) an = max(an, dp[n + 1][i]);
  W(an);
  return 0;
}
