def handle_mask(mask, tree):
    """Expand the mask to match the tree structure.
    :param mask: boolean mask
    :param tree: tree structure
    :return: boolean mask
    """
    if isinstance(mask, bool):
        return [mask] * len(tree)
    return mask