#include using namespace std; long long n, m = 0, t = 1; long long a[200000]; const long long M = 1e9 + 7; long long powm(long long a, long long b) { long long u = 1, v = a; while (b > 0) { if (b & 1) u = u * v % M; v = v * v % M; b >>= 1; } return u; } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) { t = t * a[i] % M; if(i < n - 1) m = (m + t * powm(3, n - 2 - i) * 2 % M) % M; else m = (m + t) % M; } cout << m << endl; }