N = int(input()) L = list(map(int,input().split())) ans = 0 mod = 10**9 + 7 now = L[0] for i in range(N-1): ans += now * 2 * pow(3,N-2-i,mod) ans %= mod now *= L[i+1] now %= mod #print(ans) print((ans + now)%mod)