Scanf.scanf "%d" (fun n ->
    let module M = Map.Make (struct type t = int let compare (a:int) (b:int) = compare a b end) in
    let rec loop i map acc =
        if i > n then acc else
            let a = Scanf.scanf " %d" (fun a -> a) in
            let acc = acc + try M.find (i - a) map with _ -> 0 in
            let key = i + a in
            let map = M.add key (1 + try M.find key map with _ -> 0) map in
            loop (i + 1) map acc
    in
    loop 1 M.empty 0 |> Printf.printf "%d\n"
)