#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef double db;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tree<iii, null_type, greater<iii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int N, K, ans = LLONG_MAX, A[805][805], P[805][805];
ordered_set S;

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N >> K;
	for (int i = 1; i <= N; i++)
		for (int j = 1; j <= N; j++) cin >> A[i][j];
	int lo = 0, hi = 1e9, ans = -1;
	int calc = K * K - ((K * K) / 2 + 1) + 1;
	while (lo <= hi) {
		int mid = (lo + hi) / 2;
		bool yes = 0;
		for (int i = 1; i <= N; i++)
			for (int j = 1; j <= N; j++) {
				P[i][j] = (A[i][j] <= mid);
				P[i][j] += P[i - 1][j] + P[i][j - 1] - P[i - 1][j - 1];
			}
		for (int i = 1; i <= N; i++)
			for (int j = 1; j <= N; j++) {
				if (i >= K && j >= K) {
					int tmp = P[i][j] - P[i - K][j] - P[i][j - K] + P[i - K][j - K];
					if (tmp >= calc) yes = 1;
				}
			}
		if (yes) ans = mid, hi = mid - 1;
		else lo = mid + 1;
	}
	cout << ans << '\n';
}

#include "bits/stdc++.h"
using namespace std;

#define rep(i, a, b) for(int i=a; i<=b; i++)
#define trav(x, a) for(auto &x:a)
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_bacl
#define nl '\n'
#define f first
#define s second
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

template <ll Mod>
struct ModInt {
  ll n;

  ModInt(const ll x = 0) : n(x) {
    while (n < 0) n += Mod;
    n %= Mod;
  }
  explicit operator int() const { return n; }
  inline constexpr ModInt operator+(const ModInt r) const noexcept { return ModInt(*this) += r; }
  inline constexpr ModInt operator-(const ModInt r) const noexcept { return ModInt(*this) -= r; }
  inline constexpr ModInt operator*(const ModInt r) const noexcept { return ModInt(*this) *= r; }
  inline constexpr ModInt operator/(const ModInt r) const noexcept { return ModInt(*this) /= r; }
  inline constexpr ModInt &operator+=(const ModInt r) noexcept {
    n += r.n;
    if (n >= Mod) n -= Mod;
    return *this;
  }
  inline constexpr ModInt &operator-=(const ModInt r) noexcept {
    if (n < r.n) n += Mod;
    n -= r.n;
    return *this;
  }
  inline constexpr ModInt &operator*=(const ModInt r) noexcept {
    n = n * r.n % Mod;
    return *this;
  }
  inline constexpr ModInt &operator/=(const ModInt r) noexcept { return *this *= r.inv(); }

  inline constexpr ModInt pow(ll x) const noexcept {
    ModInt<Mod> ret(1), tmp(*this);
    while (x) {
      if (x&1) ret *= tmp;
      tmp *= tmp;
      x >>= 1;
    }
    return ret;
  }
  inline constexpr ModInt inv() const noexcept { return pow(Mod-2); }

  friend ostream& operator<<(ostream& os, const ModInt& obj) { return os << obj.n; }
  friend istream& operator>>(istream& is, ModInt& obj) {
    ll t;
    is >> t;
    obj = ModInt(t);
    return is;
  }
};

constexpr ll mod = 998244353; //check!
using mint = ModInt<mod>;
mint operator"" _mi(unsigned long long n) { return mint(n); }

int n;
int a[101];
mint dp[101][10001];
mint fac[101];

int main(){
	cin.tie(0)->sync_with_stdio(0);
	// freopen("input.txt", "r", stdin);

	cin >> n;
	int tot=0;
	rep(i, 1, n) cin >> a[i], tot+=a[i];
	if(tot&1){
		cout << 0; return 0;
	}

	fac[0]=1;
	rep(i, 1, n) fac[i]=fac[i-1]*i;

	dp[0][0]=1;
	rep(i, 1, n){
		for(int k=i; k>=1; k--) {
			for(int s=100*n; s>=0; s--) {
				if(a[i]<=s) dp[k][s]+=dp[k-1][s-a[i]];
			}
		}
	}
	
	mint ans=0;
	rep(i, 1, n-1){
		ans+=dp[i][tot/2]*fac[i]*fac[n-i];
		// cout << "added " << dp[i][tot/2] << "*" << fac[i] << "*" << fac[n-i] << nl;
	}
	cout << ans;
}
// w_i > tot/2 -> 0
// step 1: # ways to make sum tot/2
// step 2: each contributes 2*n1!*n2! cuz they force

// dp[k][s] = # ways to have k elements sum to s
