import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as C
import Data.Vector.Algorithms.Search
import Data.Vector.Algorithms.Intro as VAI

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

main :: IO ()
main = do
    n <- readLn
    as <- r n
    let ls = U.imap (+) as
    let rs = U.imap (-) as
    mutRs <- U.thaw rs
    VAI.sort mutRs
    res <- U.forM ls (\l -> do
            il <- binarySearchL mutRs l
            ir <- binarySearchR mutRs l
            return $ ir - il)
    print $ U.sum res