Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    let hist = Array.make (n + 1) 0 in
    Array.iter (fun v -> hist.(v) <- hist.(v) + 1) a;
    let sum = Array.fold_left (fun acc v -> acc + v * (v - 1) / 2) 0 hist in
    for i = 0 to n - 1 do
        let k = hist.(a.(i)) in
        Printf.printf "%d\n" (sum - k + 1)
    done
)