/* Author: rrrr_wys
 **/

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
typedef double db;
typedef long long ll;
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;

const int N = 810;
const int P = 1e9 + 7;

int bn, bm, bit[N][N];
void init(int n, int m) {
  memset(bit, 0, sizeof bit);
  bn = n, bm = m;
}
void add(int x, int y) {
  for (int i = x; i <= bn; i += i & -i)
    for (int j = y; j <= bm; j += j & -j)
      ++bit[i][j];
}
int ask(int x, int y) {
  int ans = 0;
  for (int i = x; i > 0; i -= i & -i)
    for (int j = y; j > 0; j -= j & -j)
      ans += bit[i][j];
  return ans;
}
int n, k, a[N][N], b[N][N];
int dx[4] = {0, -1, -1, 0};
int dy[4] = {0, -1, 0, -1};
int inb(int x, int y, int k) {
  if (x < 1 || x > n || y < 1 || y > n)
    return 0;
  x += k;
  y += k;
  if (x < 1 || x > n || y < 1 || y > n)
    return 0;
  return 1;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  int rnk = k * k - ((k * k) / 2 + 1) + 1;
  // cout << rnk << "\n";
  vector<pair<ll, pii>> v;
  rep(i, 1, n) rep(j, 1, n) cin >> a[i][j], v.pb({a[i][j], {i, j}});
  sort(v.begin(), v.end());
  auto ck = [&](int m) {
    init(n, n);
    rep(i, 0, v.size() - 1) if (v[i].fi <= m) add(v[i].se.fi, v[i].se.se);
    rep(i, 1, n) rep(j, 1, n) if (i + k - 1 <= n && j + k - 1 <= n) {
      int tt = ask(i + k - 1, j + k - 1) - ask(i + k - 1, j - 1) -
               ask(i - 1, j + k - 1) + ask(i - 1, j - 1);
      if (tt >= rnk)
        return 1;
    }
    return 0;
  };
  int l = v[0].fi, r = v.back().fi, ans = -1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (ck(mid))
      r = mid - 1, ans = mid;
    else
      l = mid + 1;
  }
  cout << ans << "\n";
}
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b); i-- > (a); )
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) int((x).size())
#define lb(x...) lower_bound(x)
#define ub(x...) upper_bound(x)

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll B = 10000;
const ll inf = B * (2e5 + 30);

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	ld p, q, s; cin >> p >> q >> s;
	ll a = round(B * p);
	ll b = round(B * q);
	ll r = round(B * s);

	ll ans = 0;
	for (ll x = -inf; x <= inf; x += B) {
		ll d = r * r - (x - a) * (x - a);
		if (d < 0) continue;
		ll l = 0, r = sqrt(d) + 30;
		while (r - l > 1) {
			ll m = l + (r - l) / 2;
			(m * m <= d ? l : r)  = m;
		}
		
		ans += (b + l + inf) / B - (b - r + inf) / B;
	}

	cout << ans;
}