import math MOD = 10**9 + 7 def main(): N = int(input().strip()) c = list(map(int, input().split())) # Check if all digits are the same non_zero = [i for i in range(9) if c[i] > 0] if len(non_zero) == 1: idx = non_zero[0] if c[idx] == N: d = idx + 1 pow_10 = pow(10, N, 9 * MOD) numerator = (pow_10 - 1) % (9 * MOD) term = (numerator // 9) % MOD ans = (d * term) % MOD print(ans) return # Case 2: Not all digits are the same all_even = True for i in range(9): if c[i] > 0 and (i + 1) % 2 != 0: all_even = False break S = sum((i + 1) * c[i] for i in range(9)) g = math.gcd(S, 9) factor = 2 if all_even else 1 ans = (factor * g) % MOD print(ans) if __name__ == "__main__": main()