N = int(input()) l = list(map(int, input().split())) md = 1000000007 prod = [] p = 1 for i in range(N): p = (p*l[i]) % md prod.append(p) ans = 0 for i in range(N-1): ans += (2 * 3**(N-i-2) * prod[i]) % md ans += prod[N-1] print(ans%md)