def circuit_size(spn):
    nodes = get_nodes_by_type(spn)
    size = 0
    for n in nodes:
        if (isinstance(n, Product) or isinstance(n, Sum)):
            size += len(n.children)
        elif isinstance(n, CLTree):
            queue = [n.dtree_root]
            clt_size = 0
            while queue:
                peek_node = queue.pop(0)
                queue.extend(peek_node.children)
                if (not peek_node.is_leaf()):
                    clt_size += ((1 + len(peek_node.children)) * 2)
                clt_size += 4
            size += (clt_size - 2)
    return size
def circuit_size(spn):
    nodes = get_nodes_by_type(spn)
    size = 0
    for n in nodes:
        if (isinstance(n, Product) or isinstance(n, Sum)):
            size += len(n.children)
        elif isinstance(n, CLTree):
            queue = [n.dtree_root]
            clt_size = 0
            while queue:
                peek_node = queue.pop(0)
                queue.extend(peek_node.children)
                if (not peek_node.is_leaf()):
                    clt_size += ((1 + len(peek_node.children)) * 2)
                clt_size += 4
            size += (clt_size - 2)
    return size