mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline N = int(input()) C = [0] + list(map(int, input().split())) nz = [0] * 10 for i in range(1, 10): if C[i]: nz[i] = 1 if sum(nz) == 1: c = 0 for i in range(1, 10): if nz[i]: c = i break print((c * (pow(10, N, mod) - 1) * pow(9, mod-2, mod))%mod) exit() ans = 1 # 2 flg2 = 1 for i in range(1, 10): if i % 2 and C[i]: flg2 = 0 break if flg2: ans = 2 # 4 flg4 = 1 for i in range(1, 10): if i % 4 and C[i]: flg4 = 0 break if flg4: ans = 4 # 3, 9 S = 0 for i, c in enumerate(C): S = S + c * i if S % 9 == 0: ans *= 9 elif S % 3 == 0: ans *= 3 # 7 T = set() for i in range(1, 10): if C[i]: T.add(i) T = sorted(list(T)) if T == [1, 8] or T == [2, 9]: if N % 6 == 0: ans *= 7 print(ans) assert N == sum(C) if __name__ == '__main__': main()