import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as V
main=print.solve.V.unfoldr(B.readInt.B.dropWhile isSpace)=<<B.getContents
solve=V.foldl1'(+%).(V.zipWith(*%)=<<V.scanl'(+%)0).V.tail
a+%b=(a+b)`mod`m
a*%b=(a*b)`mod`m
m=10^9+7