
#pragma GCC optimize(3)
#pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")

#include<iostream>
#include<cstring>
#include<cstdio>
#include<climits>
#include<algorithm>
#include<queue>
#include<vector>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define int long long
#define mod 998244353
using namespace std;
inline int read(){
	int f=1,ans=0; char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
	return f*ans;
}
const int MAXN=411;
int f[2][MAXN][MAXN][3][3],N,A[27],g[MAXN][MAXN];
signed main(){
	//freopen("6.in","r",stdin);
	N=read(); for(int i=1;i<=26;i++) A[i]=read();
	int cur=0;
	f[cur][0][0][0][0]=24*24; 
	f[cur][1][0][0][1]=f[cur][1][0][1][0]=f[cur][0][1][2][0]=f[cur][0][1][0][2]=24;
	f[cur][1][1][1][2]=f[cur][1][1][2][1]=1;
	f[cur][2][0][1][1]=f[cur][0][2][2][2]=1;
	for(int i=2;i<N;i++){
		memset(f[cur^1],0,sizeof(f[cur^1])),cur^=1;
		for(int j=0;j<=N;j++)
			for(int k=0;k<=N;k++){
				if(i&1){
					for(int p=0;p<=2;p++){
						f[cur][j][k][p][0]+=23*f[cur^1][j][k][p][0]; f[cur][j][k][p][0]%=mod;
						f[cur][j+1][k][p][1]+=f[cur^1][j][k][p][0]; f[cur][j+1][k][p][1]%=mod;
						f[cur][j][k+1][p][2]+=f[cur^1][j][k][p][0]; f[cur][j][k+1][p][2]%=mod;
						f[cur][j][k][p][0]+=24*f[cur^1][j][k][p][1]; f[cur][j][k][p][0]%=mod;
						f[cur][j][k+1][p][2]+=f[cur^1][j][k][p][1]; f[cur][j][k+1][p][2]%=mod;
						f[cur][j][k][p][0]+=24*f[cur^1][j][k][p][2]; f[cur][j][k][p][0]%=mod;
						f[cur][j+1][k][p][1]+=f[cur^1][j][k][p][2]; f[cur][j+1][k][p][1]%=mod;
					}
				}else{
					for(int p=0;p<=2;p++){
						f[cur][j][k][0][p]+=23*f[cur^1][j][k][0][p]; f[cur][j][k][0][p]%=mod;
						f[cur][j+1][k][1][p]+=f[cur^1][j][k][0][p]; f[cur][j+1][k][1][p]%=mod;
						f[cur][j][k+1][2][p]+=f[cur^1][j][k][0][p]; f[cur][j][k+1][2][p]%=mod;
						f[cur][j][k][0][p]+=24*f[cur^1][j][k][1][p]; f[cur][j][k][0][p]%=mod;
						f[cur][j][k+1][2][p]+=f[cur^1][j][k][1][p]; f[cur][j][k+1][2][p]%=mod;
						f[cur][j][k][0][p]+=24*f[cur^1][j][k][2][p]; f[cur][j][k][0][p]%=mod;
						f[cur][j+1][k][1][p]+=f[cur^1][j][k][2][p]; f[cur][j+1][k][1][p]%=mod;
					}
				}
			}
	}
	for(int i=0;i<=N;i++) for(int j=0;j<=N;j++) for(int p1=0;p1<=2;p1++) for(int p2=0;p2<=2;p2++) g[i][j]+=f[cur][i][j][p1][p2],g[i][j]%=mod;
	for(int i=N;i>=0;i--) for(int j=N;j>=0;j--) g[i][j]+=g[i+1][j]+g[i][j+1]-g[i+1][j+1],g[i][j]=((g[i][j]%mod)+mod)%mod;
	int Ans=g[0][0];
	for(int i=1;i<=26;i++) Ans-=g[A[i]+1][0],Ans=((Ans%mod)+mod)%mod;
	for(int i=1;i<=26;i++) for(int j=i+1;j<=26;j++) Ans+=g[A[i]+1][A[j]+1],Ans=((Ans%mod)+mod)%mod;
	printf("%lld\n",Ans); return 0;
}