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
from math import gcd

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

n = int(input())
ile = 1

wchodzi = []
for i in range(n + 1):
    wchodzi += [0]
wchodzi[1] = 1

for i in range(1, n + 1):
    vec = list(map(int, input().split()))[1:]
    if len(vec) == 0:
        continue

    if wchodzi[i] == 0:
        continue    
    
    NWW = nww(wchodzi[i], len(vec))
    mnoz = int(NWW // wchodzi[i])

    for j in range(1, n + 1):
        wchodzi[j] = int(wchodzi[j]) * mnoz
    pom = NWW // int(len(vec))
    for el in vec:
        wchodzi[el] += pom

print(int(wchodzi[1]))