founded_numbers = 0

def get_inputs():
    n = int(input())
    boxes = []
    for _ in range(n):
        box = list(map(int, input().split()))
        boxes.append(box[1:])
    return boxes

def solve(boxes, target_box_index, current_state):
    if (target_box_index >= len(boxes)):
        global founded_numbers
        founded_numbers += 1
        return
    for i in range(len(boxes[target_box_index])):
        new_number = boxes[target_box_index][i]
        if new_number in current_state:
            continue
        current_state.add(new_number)
        solve(boxes, target_box_index + 1, current_state)
        current_state.remove(new_number)

    
        
    
boxes = get_inputs()
solve(boxes, 0, set())
print(founded_numbers)

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: