1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
from math import lcm

n = int(input())
G = [[]] * n

for i in range(n):
    ls = list(map(int, input().split()))
    G[i] = ls[1:]

walizy = [0] * n
walizy[0] = 1

for i in range(n):
    if walizy[i] == 0 or len(G[i]) == 0:
        continue
    ile = lcm(walizy[i], len(G[i])) // walizy[i]
    for j in range(n):
        walizy[j] *= ile
    for x in G[i]:
        walizy[x - 1] += walizy[i] // len(G[i])

print(walizy[0])