using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static long[] NList => ReadLine().Split().Select(long.Parse).ToArray(); public static void Main() { Solve(); } static void Solve() { var n = NN; var a = NList; var mod = 1_000_000_007; var mul = new long[n]; mul[n - 1] = 1; mul[n - 2] = 2; for (var i = n - 3; i >= 0; --i) mul[i] = mul[i + 1] * 3 % mod; var tmp = (long)a[0]; var ans = tmp * mul[0] % mod; for (var i = 1; i < n; ++i) { tmp = tmp * a[i] % mod; ans = (ans + tmp * mul[i]) % mod; } WriteLine(ans); } }