import Data.Maybe
import Data.List
import Text.Printf
import qualified Data.IntMap.Strict as M
import qualified Data.ByteString.Char8 as C

parseInt :: C.ByteString -> Int
parseInt = fst . fromJust . C.readInt

main :: IO ()
main = do
  n <- parseInt <$> C.getLine
  as <- map parseInt . C.words <$> C.getLine
  let update Nothing = Just 1
      update (Just y) = Just (y + 1)
      acc (cnt, mp) (j, aj) = (cnt + M.findWithDefault 0 (j - aj) mp, M.alter update (j + aj) mp)
      (ans, _) = foldl' acc (0 :: Int, M.empty) $ zip [1..n] as
  printf "%d\n" ans