local mod = 1000000007 local mfl = math.floor local function bmul(x, y) local x1, y1 = mfl(x / 31623), mfl(y / 31623) local x0, y0 = x - x1 * 31623, y - y1 * 31623 return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod end local function badd(x, y) return (x + y) % mod end local n = io.read("*n") local a = {} for i = 1, n do a[i] = io.read("*n") end local b = {a[1]} for i = 2, n do b[i] = bmul(b[i - 1], a[i]) end local ret = b[n] local mul = 2 for i = n - 1, 1, -1 do ret = badd(ret, bmul(mul, b[i])) mul = (mul * 3) % mod end print(ret)