#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define rep(i, a, b) for(int i = a; i < b; ++i)

int debug = 0;

const int N = 60;

int mod = 998244353;
int n, k, sz = 0, cnt, a[N][N], fac[N], was[N];
vector <int> g[N];

void dfs(int v) {
    if (was[v]) return;
    was[v] = 1;
    sz++;
    for (int u : g[v]) dfs(u);
}

main() {
    fac[0] = 1;
    rep(i, 1, N) fac[i] = fac[i - 1] * i % mod;

    cin >> n >> k;
    rep(i, 0, n) rep(j, 0, n) {
        cin >> a[i][j];
    }
    rep(x, 0, n) rep(y, 0, n) {
        int flag = 1;
        rep(i, 0, n) {
            if (a[i][x] + a[i][y] > k) {
                flag = 0;
            }
        }
        if (flag) {
            g[x].push_back(y);
            g[y].push_back(x);
        }
    }
    cnt = 1;
    sz = 0;
    rep(i, 0, n) {
        if (!was[i]) {
            sz = 0;
            dfs(i);
            cnt *= fac[sz];
            cnt %= mod; 
        }
    }
    fill(was, was + n + 1, 0);
    rep(i, 0, n + 1) g[i].clear();
    rep(x, 0, n) rep(y, 0, n) {
        int flag = 1;
        rep(i, 0, n) {
            if (a[x][i] + a[y][i] > k) {
                flag = 0;
            }
        }
        if (flag) {
            g[x].push_back(y);
            g[y].push_back(x);
        }
    }
    sz = 0;
    rep(i, 0, n) {
        if (!was[i]) {
            sz = 0;
            dfs(i);
            cnt *= fac[sz];
            cnt %= mod;
        }
    }
    cout << cnt << '\n';
}
#include <bits/stdc++.h>
#define rep(i,a,b) for (int i = a; i <= b; i++)
 
using namespace std;

int n, a[111000];
long long res = 1;
 
int main() {
	cin >> n;
	rep(i,1,n) cin >> a[i];
	sort(a+1, a+n+1);
	rep(i,1,n) res = res * (a[i] - a[i-1] + 1) % 1000000007;
	cout << res << "\n";
	return 0;
}
