MOD = 10 ** 9 + 7 n = int(input()) c = list(map(int, input().split())) for i in range(9): if c[i] == n: print((i + 1) * (pow(10, n, MOD) - 1) * pow(9, MOD - 2, MOD) % MOD) exit(0) s = 0 for i in range(9): s += (i + 1) * c[i] ans = 1 if c[0] + c[2] + c[4] + c[6] + c[8] == n: ans *= 2 if c[0] + c[5] == n: ans *= 5 if s % 9 == 0: ans *= 9 elif s % 3 == 0: ans *= 3 print(ans)