-- Try yukicoder -- author: Leonardone @ NEETSDKASU main = interact $ show . solve . map read . words mod109 = (`mod` (10^9 + 7)) solve (n:vs) = ans where (xs, ys) = splitAt (n+1) vs zs = zip xs (reverse ys) ans = fst $ foldl f (0, 0) zs f (a, s) (x, y) = (mod109 $ a + (mod109 $ y * (mod109 $ s + x)), mod109 $ s + x)