main :: IO ()
main = do
    _ <- getLine
    a <- getLine >>= return . words >>=  return . map read :: IO [Int]
    print $ solve 1000000007 a

solve :: Int -> [Int] -> Int
solve m xs = (`mod` m) . sum $ zipWith (\x y -> x * y `mod` m) xs . scanr (\x acc -> x + acc `mod` m) 0 $ tail xs
