## https://yukicoder.me/problems/no/1632 MOD = 10 ** 9 + 7 def main(): N = int(input()) C = list(map(int, input().split())) # C > 0となるものが一つしかない場合は cnt = 0 cnt_i = -1 for i in range(9): if C[i] > 0: cnt += 1 cnt_i = i + 1 if cnt == 1: ans = 0 for _ in range(C[cnt_i - 1]): ans *= 10 ans %= MOD ans += cnt_i ans %= MOD print(ans) else: # 9で割れるか? mods = 1 nine_check = 0 for i in range(9): nine_check += (i + 1) * C[i] if nine_check % 9 == 0: mods *= 9 elif nine_check % 3 == 0: mods *= 3 four_check = True for i in range(9): if (i + 1) % 4 != 0 and C[i] > 0: four_check = False break two_check = True for i in range(9): if (i + 1) % 2 != 0 and C[i] > 0: two_check = False break if four_check: mods *= 4 elif two_check: mods *= 2 print(mods) if __name__ == "__main__": main()