import math


def compute_perfect_tree(total):
    """
    Determine # of ways complete tree would be constructed from 2^k - 1 values.
    This is a really subtle problem to solve. One hopes for a recursive solution,
    because it is binary trees, and the surprisingly simple equation results
    from the fact that it is a complete tree. It comes down to the number of
    ways you can independently interleave the sequential values from two subsequences.
    The total of the subsequences is (total - 1), because you leave out the subtree root.
    Each of the (total // 2) half sequences are then interleaved. To properly count
    the number of possibilities, you need to multiply by the ways you can create
    subtrees of half the side (one for the left and one for the right).

    https://stackoverflow.com/questions/17119116/how-many-ways-can-you-insert-a-series-of-values-into-a-bst-to-form-a-specific-tr
    """
    if total == 1:
        return 1
    half = total // 2
    return (math.factorial(total-1) / (math.factorial(half) * math.factorial(half))) * compute_perfect_tree(half) * compute_perfect_tree(half)