import math def main(): MOD = 10**9 + 7 N = int(input()) c = list(map(int, input().split())) if N == 1: for i in range(9): if c[i] == 1: print(i + 1) return else: count_nonzero = sum(1 for x in c if x > 0) if count_nonzero == 1: for i in range(9): if c[i] > 0: d = i + 1 break pow_10 = pow(10, N, MOD) numerator = (pow_10 - 1) % MOD inv9 = 111111112 # Modular inverse of 9 mod MOD sum_part = (numerator * inv9) % MOD M = (d * sum_part) % MOD print(M) return else: a = 0 if c[0] == 0 and c[2] == 0 and c[4] == 0 and c[6] == 0 and c[8] == 0: a = 1 b = 0 if c[4] == N: b = 1 S = 0 for i in range(9): S += (i + 1) * c[i] g = math.gcd(S, 9) d = (pow(2, a, MOD) * pow(5, b, MOD)) % MOD d = (d * g) % MOD print(d) if __name__ == "__main__": main()