class BST {

    public Key select(int rank) {
        if (rank < 0 || rank >= size())
            throw new NoSuchElementException("rank is out of range");
        return select(root, rank).key;
    }

}