let split_string ?(pattern="") = Str.split @@ Str.regexp pattern
let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let s = read_line () |> split_string

let cnt = List.fold_left (fun acc n ->
  match acc with
    | [] -> [(n, 1)]
    | (v, cnt) as t :: xs -> if v = n then (v, cnt + 1) :: xs else (n, 1) :: t :: xs
) [] @@ List.sort compare s

let () = 
  if List.length cnt < 3 then
    print_endline "0"
  else begin
    let s = Array.of_list s in
    let ans = ref @@ List.fold_left ( * ) 1 @@ List.map snd cnt in
    for i = 0 to n - 2 do
      for j = i + 1 to n - 1 do
        let k = j + (j - i) in
        if k < n && s.(i) <> s.(j) && s.(j) <> s.(k) && s.(i) <> s.(k) then ans := !ans - 1
      done
    done;
    Printf.printf "%d\n" !ans
  end