import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Data.Tuple.Extra

main = do
  let readInt = fmap (second B.tail) . B.readInt
  n <- readLn
  xs <- VU.unfoldrN n readInt <$> B.getLine
  print $ solve n xs

solve n xs = VU.foldl (+%) 0 ys
  where
    (+%) x y = (x + y) `mod` (10^9 + 7)

    (*%) x y = (x * y) `mod` (10^9 + 7)

    ss = VU.scanl (+%) 0 xs

    ys = VU.generate n $ \i ->
      (xs VU.! i) *% ((ss VU.! n) - (ss VU.! (i+1)))
