#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>
#include <bitset>
// #include <atcoder/all>
#include <fstream>
#include <random>
#include <cassert>

//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;
// using namespace atcoder;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e16;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(ll i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const long double PI = 3.1415926535897932;

using Graph = vector<vector<ll>>;


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << ketasitei;

	ll n;
	cin >> n;
	vector<ll> a(n), b(n), c(n), d(n), e(n);
	ll ma, mb, mc, md, me;
	ma = 0; mb = 0; mc = 0; md = 0; me = 0;

	ll an, bn, cn, dn, en;

	rep(i, n)
	{
		cin >> a[i] >> b[i] >> c[i] >> d[i] >> e[i];
		if (ma < a[i])
		{
			ma = a[i];
			an = i;
		}
		if (mb < b[i])
		{
			mb = b[i];
			bn = i;
		}
		if (mc < c[i])
		{
			mc = c[i];
			cn = i;
		}
		if (md < d[i])
		{
			md = d[i];
			dn = i;
		}
		if (me < e[i])
		{
			me = e[i];
			en = i;
		}
	}

	ll aa, bb, cc, dd, ee;
	ll ans = 0;

	for (int i = 0; i < n-1; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			aa = max(a[i], a[j]);
			bb = max(b[i], b[j]);
			cc = max(c[i], c[j]);
			dd = max(d[i], d[j]);
			ee = max(e[i], e[j]);

			ll check = 0;

			if (aa == min({ aa,bb,cc,dd,ee }))
			{
				check = an;
			}
			if (bb == min({ aa,bb,cc,dd,ee }))
			{
				check = bn;
			}
			if (cc == min({ aa,bb,cc,dd,ee }))
			{
				check = cn;
			}
			if (dd == min({ aa,bb,cc,dd,ee }))
			{
				check = dn;
			}
			if (ee == min({ aa,bb,cc,dd,ee }))
			{
				check = en;
			}

			aa = max(aa, a[check]);
			bb = max(bb, b[check]);
			cc = max(cc, c[check]);
			dd = max(dd, d[check]);
			ee = max(ee, e[check]);

			ans = max(ans, min({ aa,bb,cc,dd,ee }));
		}
	}

	cout << ans << endl;


	return 0;
}
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}


const ll MOD = 998244353;
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
ll rev(ll x) {
	return bin_pow(x, MOD - 2);
}

const int N = 101;
const int C = 10101;
int n;
int S;
int dp[N][C];
int f[N];

int main()
{
	startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	dp[0][0] = 1;
	S = 0;
	for (int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		for (int j = i; j >= 0; j--)
			for (int y = 0; y <= S; y++)
				dp[j + 1][y + x] = add(dp[j + 1][y + x], dp[j][y]);
		S += x;
	}
	if (S & 1) {
		printf("0\n");
		return 0;
	}
	f[0] = 1;
	for (int i = 1; i < N; i++)
		f[i] = mult(f[i - 1], i);
	int ans = 0;
	S /= 2;
	for (int k = 0; k <= n; k++)
		ans = add(ans, mult(mult(f[k], f[n - k]), dp[k][S]));
	printf("%d\n", ans);

	return 0;
}
