def perfect_inserter(t, keys):
    """Insert keys into tree t such that t is perfect.
    Args:
        t (BinaryTree): An empty tree.
        keys (list): A sorted list of keys.
    """
    def f(n):
        """find the point so partition n keys for a perfect tree"""
        # x = 1
        # while x <= n//2:
        #     x *= 2
        x = 1 << (n.bit_length() - 1)
        if x//2 - 1 <= (n-x):
            return x - 1
        else:
            return n - x//2

    n = len(keys)
    if n == 0:
        return
    else:
        x = f(n)
        t.insert(keys[x])
        perfect_inserter(t, keys[:x])
        perfect_inserter(t, keys[x+1:])