from itertools import permutations import math n = int(input()) c = list(map(int,input().split())) ans = 0 nn = math.factorial(n) for i in range(9): if c[i] != 0: nn //= math.factorial(c[i]) ans = 0 for i in range(9): if c[i] != 0: for j in range(n): ans += (i+1) * 10 ** j * c[i] * (nn // n) print(ans % (10 ** 9 + 7) )