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 b=0 for i in range(9): b=(b*pow(10,C[i],7)+((pow(10,C[i],7)-1)*pow(9,5,7)*(i+1)))%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)