let rec s ?(l = []) n =
  if n = 0 then l else s ~l:(read_int () :: l) (n-1)

let rec solve () =
  let n = read_int () in
  if n == 0 then exit 0
  else
    let l = List.fast_sort compare (s n) in
    let min = List.hd l in
    let max = List.nth l (n-1) in
    let sum = List.fold_left (+) 0 l in
    let ave = (sum-min-max) / (n-2) in
    print_int ave; print_newline ();
    solve ()

let () = solve ()