#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<vi> vvi;
#define INF (1e9)

vvi A;
int N, K;

// index が条件を満たすかどうか
bool isOK(ll val) {
  vvi B(N + 1, vi(N + 1, 0));

  // imosu
  // B[i+1][j+1] = A[0][0] ~ A[i][j]
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      B[i + 1][j + 1] = B[i + 1][j] + B[i][j + 1] - B[i][j];
      if (A[i][j] <= val) B[i + 1][j + 1] += 1;
    }
  }

  // for (int i = 0; i <= N; i++) {
  //   for (int j = 0; j <= N; j++) {
  //     cout << B[i][j];
  //   }
  //   cout << endl;
  // }
  // cout << endl;

  for (int i = 0; i <= N - K; i++) {
    for (int j = 0; j <= N - K; j++) {
      // A[i, j] ~ A[i+K, j+K]
      // cout << val << ":  "
      //      << "A[" << i << "][" << j << "] ~ A[" << i + K - 1 << "]["
      //      << j + K - 1 << "]" << endl;
      // for (int a = i; a < i + K; a++) {
      //   for (int b = j; b < j + K; b++) {
      //     if (A[a][b] <= val)
      //       cout << A[a][b] << ' ';
      //     else
      //       cout << "_ ";
      //   }
      //   cout << endl;
      // }
      ll s = B[i + K][j + K] - B[i + K][j] - B[i][j + K] + B[i][j];
      // cout << s << "*2 >= " << K << "*" << K << endl;
      // cout << endl;
      if (s * 2 >= K * K) return true;
    }
  }

  return false;
}

ll binary_search() {
  ll ng = -1;
  ll ok = 1e9 + 1;

  // ok と ng のどちらが大きいかわからないことを考慮
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;  // オーバーフロー注意

    // cout << ok << ' ' << mid << ' ' << ng << endl;
    if (isOK(mid))
      ok = mid;
    else
      ng = mid;
  }
  return ok;
}

int main() {
  cin >> N >> K;
  A = vvi(N, vi(N));
  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j < N; j++) {
      cin >> A[i][j];
    }
  }

  ll ans = binary_search();

  cout << ans << endl;
}

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int) x.size()
#define cat(x) cerr << #x << " = " << x << endl
#define all(x) x.begin(), x.end()
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
 
using ll = long long;
using ld = long double;
using namespace std;
 
int n, k, MOD = 998244353;
ll res;

int f(int x) {
	if (2 * n < x) return 0;
	if (x - 1 <= n)	return x - 1;
	return 2 * n - x + 1;
}		
 
int main() {
	scanf("%d%d", &n, &k);
	rep(s, 2, 2 * n) {
		int s2 = s - k;
		if (s2 <= 1) continue;
		res += 1LL * f(s) * f(s2);
	}
	printf("%lld\n", res);
}
