1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
D = [[] for _ in range(0, 109)]
Ruchy = [0] * 109

def nwd(a, b):
    if b == 0:
        return a
    return nwd(b, a%b)

def main():
    n = int(input())
    for i in range(1, n + 1):
        temp = input().split(" ")
        D[i] = [int(num) for num in temp[1::]]

    wynik = len(D[1])
    if len(D[1]) == 0:
        print("1")
        return
    for i in range(0, len(D[1])):
        Ruchy[D[1][i]] = 1
    for i in range(2, n + 1):
        if Ruchy[i] == 0 or len(D[i]) == 0:
            continue
        u1 = len(D[i])//nwd(len(D[i]),Ruchy[i])
        u2 = Ruchy[i]//nwd(len(D[i]),Ruchy[i])
        wynik *= u1
        for j in range(1, n + 1):
            Ruchy[j] *= u1
        for j in range(0, len(D[i])):
            Ruchy[D[i][j]] += u2

    print(wynik)

main()