from math import gcd import itertools MOD = 10**9 + 7 n = int(input()) A = list(map(int, input().split())) if max(A) == n: c = A.index(n) + 1 ans = (pow(10, n, MOD * 9) - 1) // 9 * c print(ans % MOD) elif n <= 5: C = [] for i, a in enumerate(A, 1): C += [i] * a G = [] for P in itertools.permutations(C): x = 0 for p in P: x = 10 * x + p G.append(x) x = G[0] for g in G: x = gcd(x, g) print(x) else: G = [] for i in range(1, 10): for j in range(i + 1, 10): if A[i - 1] > 0 and A[j - 1] > 0: G.append((10 * j + i) - (10 * i + j)) G.append((100 * j + i) - (100 * i + j)) G.append((1000 * j + i) - (1000 * i + j)) x = G[0] for g in G: x = gcd(x, g) ans = 1 for i in range(2, x + 1): if x % i != 0: continue tot = 0 ten = 1 mod = i for j, a in enumerate(A, 1): tot += ten * (pow(10, a, mod) - 1) // 9 * j tot %= mod ten *= pow(10, a, mod) ten %= mod if tot == 0: ans = i print(ans)