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
35
36
import math

def nww(x, y):
    return (x * y) // math.gcd(x,y)


n = int(input())
outs = [ [] ]
cnt = [0] * (n+1)
for i in range(n):
    line =[int(x) for x in (input()).split()][1:]
    outs.append(line)
score = 1
cnt[1] = 1
for i in range(1, n+1):
    if cnt[i] != 0 and len(outs[i]) > 0:
        needed = nww(len(outs[i]), cnt[i])
        added = needed // len(outs[i])

        new_score = score * ( needed // cnt[i])
        mult = (needed // cnt[i])
#        print('mult', mult)
        for x in range(1, n+1):
            cnt[x] *= mult

        for x in outs[i]:
            cnt[x] = cnt[x] + added
        
#        print(cnt)

        score = new_score

#        print(i, cnt[i], needed, new_score)
#        print(outs[i])

print(score)