import Control.Arrow
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V
import Control.Monad.State (State, evalState, gets, modify)
import Data.Map.Strict (Map, lookup, insert, empty)
import Data.Foldable

main :: IO ()
main = readLn >>= main'
    where
        main' n = breads >>= print . solve n

solve :: Int -> [Int] -> Int
solve n as = run calc (0, n)
    where
        calc :: Memoizer (Int, Int) Int -> Memoizer (Int, Int) Int
        calc recf (i, j)
            | i == j = return 0
            | i + 1 == j = return $ avs V.! j
            | otherwise = summ . (v :) <$> mapM ff [(i + 1)..j]
            where
                ff x = add <$> l <*> r
                    where
                        l = mul (cf (x - i - 1)) <$> recf (i, x - 1)
                        r = mul (cf (j - x)) <$> recf (x, j)
                        cf = mul (ps V.! (j - i - 1)) . (rps V.!)
                v = (val $ ss V.! j - ss V.! i) `mul` (ps V.! (j - i))
                summ = foldl1' add
                prodm = foldl1' mul
                        
        ss = V.fromList $ scanl (+) 0 as
        avs = V.fromList $ 0 : as
        ps = V.fromList $ scanl mul 1 [1..n]
        rps = V.fromList . scanl mul 1 $ map inv [1..n]

add :: Int -> Int -> Int
add x y = val $ x + y

mul :: Int -> Int -> Int
mul x y = val $ x * y

inv :: Int -> Int
inv x = fact x $ 10 ^ 9 + 5
    where
        fact b e
            | e == 0 = 1
            | odd e = mul b $ fact b (e - 1)
            | otherwise = mul v v
            where
                v = fact b $ e `div` 2

val :: Int -> Int
val = (`mod` m)
    where
        m = 10 ^ 9 + 7

type Memoizer a b = a -> State (Map a b) b

run :: (Ord a) => (Memoizer a b -> Memoizer a b) -> a -> b
run f = flip evalState empty . memoizeFix f

memoizeFix :: (Ord a) => (Memoizer a b -> Memoizer a b) -> Memoizer a b
memoizeFix f x = gets (Data.Map.Strict.lookup x) >>= maybe (f (memoizeFix f) x >>= ((<$) <*> (modify . Data.Map.Strict.insert x))) return

breads :: IO [Int]
breads = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine