## https://yukicoder.me/problems/no/1632 MOD = 10 ** 9 + 7 def dividable_by2(C): for i in range(9): if (i + 1) % 2 != 0 and C[i] > 0: return False return True def dividable_by4(C): for i in range(9): if (i + 1) % 4 != 0 and C[i] > 0: return False return True def main(): N = int(input()) C = list(map(int, input().split())) posisive_num = 0 for c in C: if c > 0: posisive_num += 1 if posisive_num == 1: # 1つだけの正の数字がある場合 d = 0 for i in range(9): if C[i] > 0: d = i + 1 break answer = 0 d_num = 1 base = d while N > 0: y = pow(10, d_num, MOD) if N % 2 == 1: answer *= y answer %= MOD answer += base answer %= MOD base0 = (base * y) % MOD base0 %= MOD base = (base0 + base) % MOD d_num *= 2 N //= 2 print(answer) else: # 2つ以上の正の数字がある場合 # 1. 2で割れるか? gcd = 1 if dividable_by2(C): if dividable_by4(C): gcd = 4 else: gcd = 2 # 2. 3で割れるか? a = 0 for i in range(9): a += (i + 1) * C[i] if a % 3 == 0: if a % 9 == 0: gcd *= 9 else: gcd *= 3 print(gcd) if __name__ == '__main__': main()