def orderStatisticZeroBasedRanking(R, k):
    """
    Input: Root R of the tree (a node object); Integer number k - the rank of a node (0 <= k < size of the whole tree).
    Output: The k-th smallest element in the tree (a node object). Counting starts from 0.
    """
    assert 0 <= k < R.getSize(), "0 <= k < size of the whole tree"
    left, right = R.getLeftChild(), R.getRightChild()
    s = left.getSize() if left else 0
    if k == s:
        return R
    elif k < s:
        return orderStatisticZeroBasedRanking(left, k)
    elif k > s:
        return orderStatisticZeroBasedRanking(right, k - s - 1)