module Main

import Data.Int


data Mod = Mod Int64 

instance Show Mod where
        show (Mod a) = show a


instance Num Mod where
        (+) (Mod a) (Mod b) = Mod $ (a + b) `mod` (10^9 + 7)
        (*) (Mod a) (Mod b) = Mod $ (a * b) `mod` (10^9 + 7)
        abs (Mod a) = Mod $ abs a
        signum (Mod a) = Mod $ signum a
        fromInteger = Mod . fromInteger
        negate (Mod a) = Mod . negate $ a

ans :: [Mod] -> Mod
ans
        = snd 
        . foldr 
                (\x (xsSum, totSum) -> (x + xsSum, totSum + x * xsSum)) 
                (Mod 0, Mod 0)


main :: IO ()
main = interact
        $ (++ "\n")
        . show
        . ans
        . map (Mod . read)
        . words
        . (!! 1)
        . lines
 
