#include <bits/stdc++.h>
using namespace std;
int n, m, k, lmax, now1, now2, ans = 0;
int a[55][30050], s[55][30050], dp[55][30050];
struct Point {
  int x, val;
};
deque<Point> Q1, Q2, Q3;
void init() {
  lmax = 0;
  now1 = 0;
  now2 = 0;
  while (!Q1.empty()) Q1.pop_back();
  while (!Q2.empty()) Q2.pop_back();
  while (!Q3.empty()) Q3.pop_back();
}
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      cin >> a[i][j];
      s[i][j] = a[i][j] + s[i][j - 1];
    }
  for (int j = 1; j <= m - k + 1; j++) {
    dp[1][j] = s[1][j + k - 1] - s[1][j - 1] + s[2][j + k - 1] - s[2][j - 1];
    ans = max(ans, dp[1][j]);
  }
  for (int i = 2; i <= n; i++) {
    init();
    Q1.push_back(Point{1, dp[i - 1][1] - s[i][k]});
    for (int j = 2; j <= k; j++) {
      int val = dp[i - 1][j] - s[i][k] + s[i][j - 1];
      while (!Q2.empty() && val >= Q2.back().val) Q2.pop_back();
      Q2.push_back(Point{j, val});
    }
    for (int j = k + 1; j <= m; j++) {
      while (!Q3.empty() && dp[i - 1][j] >= Q3.back().val) Q3.pop_back();
      Q3.push_back(Point{j, dp[i - 1][j]});
    }
    Q3.push_back(Point{m + 1, 0});
    for (int j = 1; j <= m - k + 1; j++) {
      if (j - k) lmax = max(lmax, dp[i - 1][j - k]);
      while (Q1.front().x < j - k + 1) Q1.pop_front();
      while (!Q2.empty() && Q2.front().x < j + 1) Q2.pop_front();
      while (Q3.front().x < j + k) Q3.pop_front();
      int val1 = Q1.front().val + now1;
      if (!Q2.empty()) val1 = max(val1, Q2.front().val + now2);
      int val2 = max(lmax, Q3.front().val);
      int val3 =
          s[i][j + k - 1] - s[i][j - 1] + s[i + 1][j + k - 1] - s[i + 1][j - 1];
      dp[i][j] = max(val1, val2) + val3;
      ans = max(ans, dp[i][j]);
      now1 += a[i][j];
      int val = dp[i - 1][j + 1] - s[i][j + k] + s[i][j] - now1;
      while (!Q1.empty() && val > Q1.back().val) Q1.pop_back();
      Q1.push_back(Point{j + 1, val});
      now2 -= a[i][j + k];
      val = dp[i - 1][j + k] - s[i][j + k] + s[i][j + k - 1] - now2;
      while (!Q2.empty() && val > Q2.back().val) Q2.pop_back();
      Q2.push_back(Point{j + k, val});
    }
  }
  cout << ans;
}
