import sys sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] # inf = 18446744073709551615 inf = 4294967295 md = 10**9+7 # md = 998244353 from itertools import permutations from math import gcd from random import randrange # def solve(aa): # s = sum(aa) # # g = 0 # for dd in permutations(aa): # a = sum(d*10**i for i, d in enumerate(dd)) # g = gcd(g, a) # # if s%9 == 0: # ans = 9 # elif s%3 == 0: # ans = 3 # else: # ans = 1 # if g != ans: # print(g, ans, s, aa) # # for n in range(2,9): # for _ in range(10): # aa = [randrange(1, 10) for _ in range(n)] # solve(aa) n = II() cc = [0]+LI() if cc.count(0) == 9: for a in range(1, 10): if cc[a]: ans = (pow(10, cc[a], md)-1)*pow(9, md-2, md)%md*a%md print(ans) exit() aa = [] for a in range(1, 10): if cc[a]: aa.append(a) g = 0 for i in range(len(aa)): for j in range(i): g = gcd(g,aa[i]-aa[j]) g *= 81 s = 0 for a in range(1, 10): pw = pow(10, cc[a], g) s = (pw*s%g+(pw-1)*a%g)%g ans = gcd(g, s)//9 print(ans)