import Control.Applicative ((<$>), (<*>)) import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import Data.List (unfoldr) import Data.List (sort, group) import Data.Char (isSpace) main :: IO () main = solve <$> readLn <*> (readil B.readInt <$> B.getLine) >>= print solve :: Int -> [Int] -> Int solve n xs = flip mod (10^9+7) $ comb n 3 - (sum . map (flip comb 3) $ l3) - (sum . map (\m -> (n-m) * comb m 2) $ l2) where l2 = filter (>=2) . map length . group . sort $ xs l3 = filter (>=3) l2 comb n m | m == 0 = 1 | n < 2 * m = comb n (n-m) | otherwise = comb (n-1) (m-1) * n `div` m readil :: Integral a => (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a] readil f = unfoldr g where g s = do (n, s') <- f s return (n, B.dropWhile isSpace s')