N = int(input()) A = list(map(int, input().split())) mod = 10 ** 9 + 7 div3 = pow(3, mod-2, mod) ans = 0 head = 1 tail = 2 * pow(3, N - 1, mod) % mod for i, a in enumerate(A): head = head * a % mod tail = tail * div3 % mod if i == N - 1: tail = 1 ans += head * tail % mod ans %= mod print(ans)