Scanf.scanf "%d" (fun n ->
    let uv = Array.init (n - 1) (fun _ -> Scanf.scanf " %d %d" (fun u v -> min u v * (n + 1 - max u v))) in
    Printf.printf "%d\n" @@ n * (n + 1) * (n + 2) / 6 - Array.fold_left (+) 0 uv
)