{-# LANGUAGE TypeApplications #-}
module Main where
import qualified Data.ByteString.Char8         as BS
import qualified Data.ByteString.Lazy.Char8    as BSL
import qualified Data.ByteString.Builder       as BSB
import           Data.Char                      ( isSpace )
import           Data.List
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM
-- see: https://hackage.haskell.org/package/containers-0.6.2.1/docs/Data-Map-Strict.html
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap

main :: IO ()
main = do
  n  <- readLn @Int
  as <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let iMinusAi = hist $ zipWith (-) [1..n] as
  let jPlusAj = hist $ zipWith (+) [1..n] as
  -- let iMinusAi = histV $ VU.zipWith (-) (VU.enumFromN 1 n) as
  -- let jPlusAj = histV $ VU.zipWith (+) (VU.enumFromN 1 n) as
  print $ go 0 iMinusAi jPlusAj
 where
  go cnt [] _  = cnt
  go cnt _  [] = cnt
  go cnt xs'@((i, x) : xs) ys'@((j, y) : ys)
    | i < j     = go cnt xs ys'
    | i > j     = go cnt xs' ys
    | otherwise = go (cnt + x * y) xs ys

-- create histogram from list
hist :: [Int] -> [(Int, Int)]
hist xs = IntMap.toAscList $ IntMap.fromListWith (+) $ zip xs $ repeat 1

histV :: VU.Vector Int -> VU.Vector (Int, Int)
histV = VU.fromList . hist . VU.toList