import Data.List import Control.Applicative main = getLine >> getLine >>= print . solve . map read . words solve :: [Integer] -> Integer solve xs = calc x xs' `mod` 1000000007 where (x : xs') = map genericLength . group . sort $ xs calc :: Integer -> [Integer] -> Integer calc x (y : z : []) = x * y * z calc x (y : zs) = x * calc' y zs + calc y zs calc' :: Integer -> [Integer] -> Integer calc' x (y : []) = x * y calc' x (y : ys) = sum ((*) <$> [x] <*> (y : ys)) + calc' y ys