from math import gcd import sys input = sys.stdin.readline def ones(N): return (pow(10, N, mod) - 1) * pow(9, mod-2, mod) % mod mod = 10**9 + 7 N = int(input()) c = [0] + list(map(int, input().split())) for d in range(1, 10): if c[d] == N: print(d * ones(N) % mod) exit() ans = 0 for i in range(1, 9): for j in range(i + 1, 10): a = 10 * j + i b = 10 * i + j ans = gcd(ans, b - a) total = sum(d * c[d] for d in range(1, 10)) if total % 9 != 0 and ans % 9 == 0: ans //= 3 if total % 3 != 0 and ans % 3 == 0: ans //= 3 if ans % 5 == 0: ans //= 5 if c[8] != N and ans % 8 == 0: ans //= 2 if c[4] + c[8] != N and ans % 4 == 0: ans //= 2 if c[2] + c[4] + c[6] + c[8] != N and ans % 2 == 0: ans //= 2 print(ans)