MOD = 10 ** 9 + 7 n = int(input()) a = list(map(int, input().split())) s = [1] for x in a: s.append(s[-1] * x % MOD) pow3 = [1] for _ in range(n): pow3.append(pow3[-1] * 3 % MOD) ans = 0 for i in range(1, n): ans += s[i] * 2 * pow3[n - 1 - i] ans %= MOD ans += s[n] ans %= MOD print(ans)