import Data.List

main :: IO ()
main = do
    l1 <- getLine
    l2 <- getLine
    let l = map read $ words l2 :: [Int]

    print $ f l

-- f [218,786,704,233,645,728,389]
-- f [218,233,389,645,704,728,786]

{-
f l = sum $ zipWith g (tails $ tail l') l'
    where l' = sort l

g [] _ = 0
g l x = sum $ zipWith (\l' -> h l' x) (tails $ tail l) l

h l x y = length $ takeWhile (< x+y) l
-}


--f l = length a1 + length a2*(length l' - 1) + length a3*(length l' - 1)*(length l' - 2)
f l = f1 a1' + f2 a2' (a1'++a3') + f3 (a1'++a2'++a3')
    where l' = group l
          (a1, l'') = partition ((>=3).length) l'
          (a2, a3) = partition ((==2).length) l''
          [a1', a2', a3'] = map (map head) [a1, a2, a3]

f1 l = length l

f2 (x:l1) l2 = length (filter (\(a, b) -> b < 2*a) [(x, y) | y <- l1 ++ l2]) + f2 l1 l2
f2 _ _ = 0

f3 [] = 0
f3 l = sum $ zipWith f3' l (tails $ tail l)
f3' _ [] = 0
f3' a (b:l) = length (filter (g a b) l) + f3' a l

--f3 (a:b:l) = length (filter (g a b) l) + f3 (a:l) + f3 (b:l)
--f3 _ = 0

g a b c = a < b+c && b < c+a && c < a+b

{-
f [] = error "0"
f [_] = error "1"
f l = nubBy g $ filter (\(a, b, c) -> a < b+c && b < c+a && c < a+b) $ h l

h (a:b:l) = [(a, b, c) | c <- l] ++ h (delete a (b:l))
h _ = []

g (a, b, c) (x, y, z) = not $ elem x [a, b, c] && elem y ([a, b, c] \\ [x]) && elem z ([a, b, c] \\ [x, y])
-}


{-
f l = sum $ g l

g (a:b:l) = h a b (nub l) ++ if a == b then g (delete a l) else g (b:delete a l)
g _ = []

h a b l = do
    c <- l
    return $ if a < b+c && b < c+a && c < a+b then 1 else 0-}

