N=int(input()) C=list(map(int,input().split())) A=[] for i in range(9): for j in range(C[i]): A.append(i+1) ANS=0 M=(N+1)>>1 L=N>>1 t=0 for u in range(5,-1,-1): t+=(1<=L: x=((1<>k)&1: z|=(1<0: for j in DP[i]: if (-j*P[N-c])%mod in DP[x]: ANS=t break if ANS==t: break if c>=M: continue for j in range(N): if (i>>j)&1: continue if j>0 and A[j-1]==A[j] and (i>>(j-1))&1==0: continue for k in DP[i]: DP[i|(1<