import qualified Data.List as L import qualified Data.Maybe as Maybe import qualified Data.ByteString.Char8 as BSC8 readIntegers :: IO [Integer] readIntegers = map (fst . Maybe.fromJust . BSC8.readInteger) . BSC8.words <$> BSC8.getLine factorial n = product [n, n-1 .. 1] nCr n r = n' `div` r' where -- unroll just what you need and nothing more n' = product [n, n-1 .. n-r+1] r' = factorial r main :: IO () main = do n <- readLn :: IO Integer xs <- readIntegers print $ flip mod 1000000007 $ snd $ L.foldl1' (\acc x -> (fst x, (snd acc) + (snd x * nCr (n - 1) (fst x)))) $ zip [0 ..] xs