module IntMap = Map.Make (struct
  type t = int
  let compare = compare
end)

let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " Fun.id in
  let ans = ref 0 in
  let m = ref IntMap.empty in
  for i = n - 1 downto 0 do
    ans := !ans + Option.value ~default:0 (IntMap.find_opt (as_.(i) + i) !m);
    m :=
      IntMap.add (i - as_.(i))
        (1 + Option.value ~default:0 (IntMap.find_opt (i - as_.(i)) !m)) !m
  done;
  Printf.printf "%d\n" !ans

