using System.Numerics; using System; public class Hello { public static int MOD = 1000000007; static void Main() { var n = int.Parse(Console.ReadLine().Trim()); string[] line = Console.ReadLine().Trim().Split(' '); var a = Array.ConvertAll(line, int.Parse); getAns(n, a); } static void getAns(int n, int[] a) { var ans = 0L; var t = 1L; for (int i = 0; i < n; i++) { t *= a[i]; t %= MOD; long t2; if (n - 2 - i < 0) t2 = 1L; else { t2 = (long)BigInteger.ModPow(3, n - 2 - i, MOD) * 2L; t2 %= MOD; } t2 *= t; t2 %= MOD; ans += t2; ans %= MOD; } Console.WriteLine(ans); } }