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 lcm, gcd

class Platform:
	def __init__(self):
		self.out = []
		self.inp = []
		self.interval_input = 0

n = int(input())
pls = []
for i in range(n):
	pls.append(Platform())
for i in range(n):
	row = input().split(" ")
	for j in range(1, len(row)):
		x = int(row[j]) - 1
		pls[i].out.append(x);
		pls[x].inp.append(i);
pls[0].interval_input = len(pls[0].out)
interval = len(pls[0].out) or 1
for i in range(1, n):
	pls[i].interval_input = sum([pls[j].interval_input // len(pls[j].out) for j in pls[i].inp])
	if len(pls[i].out) and pls[i].interval_input:
		io_gcd = gcd(pls[i].interval_input, len(pls[i].out))
		new_interval = interval * len(pls[i].out) // io_gcd
		if new_interval != interval:
			mul = new_interval // interval
			for j in range (i + 1):
				pls[j].interval_input *= mul
		interval = new_interval
print(interval)