A scoreboard stores n distinct integer scores. Starting from an empty binary search tree, insert the scores in the order given, using the standard BST rule: to insert a key x, walk down from the root, going left if x is smaller than the current node and right if x is larger, until an empty spot is reached, where a new node is created. No rebalancing is performed.
You are then given a single integer k. Report the k-th largest score in the tree (so k = 1 is the maximum score, k = n is the minimum score).
Input format
Line 1: an integer n.
Line 2: n space-separated distinct integers — the scores, in insertion order.
Line 3: an integer k.
Output format
A single integer: the k-th largest score.
Constraints
- 1 ≤ n ≤ 40
- -1000 ≤ each score ≤ 1000, all scores distinct
- 1 ≤ k ≤ n