MOD = 10**9 + 7 N = int(input()) c = list(map(int, input().split())) # Check if all digits are even all_even = True for i in range(9): digit = i + 1 if c[i] > 0 and digit % 2 != 0: all_even = False break # Check if all digits are 5 all_5 = True for i in range(9): digit = i + 1 if c[i] > 0 and digit != 5: all_5 = False break # Compute the sum of all digits s = sum((i + 1) * c[i] for i in range(9)) # Compute the maximum exponent e where 3^e divides s e = 0 temp = s while temp % 3 == 0: e += 1 temp = temp // 3 # Compute the divisor d d = 1 if all_even: d *= 2 if all_5: d *= 5 d *= pow(3, e, MOD) d %= MOD # Ensure the result is within MOD print(d)