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%9==0 and sum([C[i-1] for i in range(3,10,3)])==N: ANS*=3 print(ANS)