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 <- VU.fromList . map unsafeTextToInt . T.words <$> T.getLine :: IO (VU.Vector Int)
  let
    f :: Int -> Int
    f i = length . filter p $ [(i + succ (as VU.! i))..(pred n)]
      where
        p :: Int -> Bool
        p j = j - i == as VU.! i + as VU.! j
  print . sum . map f $ [0..(n - 2)]

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