{-# 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 <- VU.unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let xs = histV $ VU.zipWith (-) (VU.enumFromN 1 n) as
  let ys = histV $ VU.zipWith (+) (VU.enumFromN 1 n) as
  print $ solve xs ys
 where
  solve xs ys = go 0 0 0   where
    go cnt i j
      | i >= VU.length xs || j >= VU.length xs = cnt
      | fst (xs VU.! i) < fst (ys VU.! j)      = go cnt (i + 1) j
      | fst (xs VU.! i) > fst (ys VU.! j)      = go cnt i (j + 1)
      | otherwise = go (cnt + snd (xs VU.! i) * snd (ys VU.! j)) (i + 1) (j + 1)

-- 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
