MOD = 10**9 + 7 N = int(input()) c = list(map(int, input().split())) # c[0] is c_1, c[1] is c_2, ..., c[8] is c_9 count_non_zero = 0 d = -1 for i in range(9): if c[i] > 0: count_non_zero += 1 d = i + 1 # since c[i] corresponds to digit (i+1) if count_non_zero == 1 and c[d-1] == N: # Compute d * (10^N - 1)/9 mod MOD mod9_mod = 9 * MOD pow_10 = pow(10, N, mod9_mod) pow_10_minus_1 = (pow_10 - 1) % mod9_mod x = pow_10_minus_1 // 9 res = (d * x) % MOD print(res) else: # Check if all digits are even all_even = True for i in range(9): if c[i] > 0 and (i + 1) % 2 != 0: all_even = False break # Compute sum_S sum_S = 0 for i in range(9): sum_S += (i + 1) * c[i] # Compute the maximum exponent a of 3 dividing sum_S a = 0 temp = sum_S while temp % 3 == 0 and temp != 0: a += 1 temp = temp // 3 product = (2 if all_even else 1) * (3 ** a) print(product % MOD)