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