N=int(input()) C=list(map(int,input().split())) mod=10**9+7 if max(C)==N: ANS=0 for i in range(9): if C[i]: ANS=(pow(10,N,mod)-1)*pow(9,mod-2,mod)*(i+1)%mod print(ANS) exit() x=sum([C[i]*(i+1) for i in range(9)]) ANS=1 if sum([C[i-1] for i in range(1,10,2)])==0: ANS*=2 if sum([C[i-1] for i in range(4,10,4)])==N: ANS*=2 if x%3==0: ANS*=3 if x%9==0: ANS*=3 if x%27==0 and sum([C[i-1] for i in range(3,10,3)])==N: ANS*=3 a,b=0,0 for i in range(9): if a&1: b+=4*(C[i]>>1)*(i+1) b+=3*(C[i]&1)*(i+1) a=(a+C[i])&1 else: b+=4*(C[i]>>1)*(i+1) b+=1*(C[i]&1)*(i+1) a=(a+C[i])&1 b%=7 F=[min(C[i],1) for i in range(9)] if b==0 and (F==[1,0,0,0,0,0,0,1,0] or F==[0,1,0,0,0,0,0,0,1]): ANS*=7 print(ANS)