
let rec input xs n =
    if n = 0 then
        xs
    else
        let a = Scanf.scanf "%d " (fun a -> a) in
        input (a :: xs) (n-1)

let rec solve xs n res
    = if n = 0 then
          Printf.printf "%d\n" res
      else
          solve xs (n-1) (res + (List.nth xs (1 + (n-1)*2)))
        
let _ =
    let xs = Scanf.scanf "%d " (fun n -> 3 * n) |> input [] |> List.sort compare in
    let xs = List.rev xs in
    solve xs ((List.length xs) / 3) 0
 
