-- noch nicht fertig

import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Vector.Unboxed as VU

main :: IO ()
main = do
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  as <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    ias = filter ((< pred n) . snd) . zip [0..] $ as :: [(Int, Int)]
    bs = countN n . map ((+) <$> fst <*> snd) $ ias :: VU.Vector Int
    cs = countN n . map ((-) <$> fst <*> snd) $ ias :: VU.Vector Int
  print . VU.sum $ VU.zipWith (*) bs cs

countN :: Int -> [Int] -> VU.Vector Int
countN n = VU.accum (+) (VU.replicate n 0) . map (flip (,) 1) . filter ((&&) <$> (0 <=) <*> (< n))
{-# INLINE countN #-}

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
