Scanf.scanf "%d" (fun n ->
    let module M = Map.Make (struct type t = int let compare = compare end) in
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    Array.sort (fun a b -> compare b a) a;

    let rec loop_2 t i p c =
        if i = n then 0 else
            if a.(i) <> p then loop_2 t (i + 1) a.(i) c else
                t * a.(i)
    in

    let rec loop_1 i p c =
        if i = n then 0 else
            if a.(i) <> p then (
                if c >= 2 then loop_2 p (i + 1) a.(i) 1
                          else loop_1 (i + 1) a.(i) 1
            ) else (
                let c = c + 1 in
                if c = 4 then p * p else
                    loop_1 (i + 1) p c
            )
    in
    loop_1 1 a.(0) 1 |> Printf.printf "%d\n"
)