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

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