Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    Array.sort compare a;

    let sum = if n = 2 then a.(n - 1) else
                    Array.fold_left (+) 0 a - a.(0) - a.(1) + a.(n - 2)
    in

    Printf.printf "%d\n" sum
)