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
import math
from fractions import *
n = int(input())
ls = [ [] ] * n
for i in range (n):
    vals = input()
    vals = vals.split(' ')
    k = int(vals[0])
    ls[i] = [0] * k
    for j in range(1, k+1):
        a = int(vals[j])
        a -= 1
        ls[i][j-1] = a


ans = 1

val = [  Fraction(0) ] * n
val[0] = 1
for i in range(n):
    for j in range(len(ls[i])):
        f = val[i] / Fraction(len(ls[i]))
        ans = math.lcm(f.denominator, ans)
        val[ls[i][j]] += f

print(ans)