#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)

using namespace std;

uint64_t kRem = 998244353;


int64_t pow_rem(int64_t val, int64_t mul, int64_t rem)
{
	if (mul == 1) return val;

	int64_t ret = pow_rem(val, mul / 2, rem);
	ret *= ret;
	ret %= rem;

	if (mul & 1) {
		ret *= val;
		ret %= rem;
	}

	return ret;
}

int main()
{
	int n; cin >> n;
	vector<int> ns(n);
	int m = 0;
	for (auto& elem : ns) {
		cin >> elem;
		m += elem;
	}

	vector<vector<int64_t>> dp_r(n, vector<int64_t> (m + 1));

	dp_r[0][0] = 2;
	dp_r[0][ns[0]] = 1;

	FOR_LT(i, 0, n - 1) {
		FOR_LE(v, 0, m) {
			if (dp_r[i][v] != 0) {
				dp_r[i + 1][v] += dp_r[i][v] * 2;
				dp_r[i + 1][v + ns[i + 1]] += dp_r[i][v];
			}
		}

		FOR_LE(v, 0, m) {
			if (dp_r[i + 1][v] != 0) {
				dp_r[i + 1][v] %= kRem;
			}
		}
	}


	vector<vector<int64_t>> dp_rb(n, vector<int64_t>(m + 1));
	dp_rb[0][0] = 1;
	dp_rb[0][ns[0]] = 1;

	FOR_LT(i, 0, n - 1) {
		FOR_LE(v, 0, m) {
			if (dp_rb[i][v] != 0) {
				dp_rb[i + 1][v] += dp_rb[i][v];
				dp_rb[i + 1][v + ns[i + 1]] += dp_rb[i][v];
			}
		}

		FOR_LE(v, 0, m) {
			if (dp_rb[i + 1][v] != 0) {
				dp_rb[i + 1][v] %= kRem;
			}
		}
	}

	int64_t ng_cases = 0;
	FOR_LE(v, ((m + 1) / 2), m) {
		ng_cases += dp_r[n - 1][v];
		ng_cases %= kRem;
	}
	if ((m & 1) == 0) {
		ng_cases -= dp_rb[n - 1][m / 2];
		if (ng_cases < 0) ng_cases += kRem;
	}
	ng_cases *= 3;
	ng_cases %= kRem;

	int64_t all_cases = 0;
	all_cases = pow_rem(3, n, kRem);

	int64_t ans = (all_cases - ng_cases);
	if (ans < 0) ans += kRem;
 
	cout << ans << endl;
}
#include<bits/stdc++.h>
#define ll long long
#define ljc 998244353
using namespace std;
#define gc getchar
inline ll read(){
    register ll x=0,f=1;char ch=gc();
    while (!isdigit(ch)){if (ch=='-') f=-1;ch=gc();}
    while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=gc();}
    return (f==1)?x:-x;
}
ll ans[1010][1010],n;
bool vis[10101];
int tot,p[10101];
inline void init(int n){
	for (int i=2;i<=n;i++){
		if (!vis[i]) p[++tot]=i;
		for (int j=1;j<=tot;j++){
			if (1ll*i*p[j]>n) break;
			vis[i*p[j]]=1;
			if (i%p[j]==0) break;
		}
	}
}
inline ll lcm(ll a,ll b){
	if (a*b==0) return a+b;
	return a/__gcd(a,b)*b;
}
signed main(){
	n=read();
	if (n==2){
		printf("4 7\n23 10\n");
		return 0;
	}
	init(10000);
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++){
			if ((i+j)%2==0){
				ans[i][j]=1ll*p[(i+j)/2]*p[1+(i-j)/2+n];
			}		
		}
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++){
			if ((i+j)%2){
				ans[i][j]=1+lcm(ans[i-1][j],lcm(ans[i][j-1],lcm(ans[i+1][j],ans[i][j+1])));
			}		
			printf("%lld ",ans[i][j]);
		}
		puts("");
	}
	return 0;
}
