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
37
38
39
40
41
def NWD(a, b):
  while a != 0 and b != 0:
    if a > b:
      a %= b
    else:
      b %= a
  return max(a, b)

def NWW(a, b):
  return a * b // NWD(a, b)

n = int(input())

r = [0 for i in range(108)]
t = [[] for i in range(108)]
dp = [0 for i in range(108)]
given = [0 for i in range(108)]

for i in range(n):
  line = list(map(int, input().split()))
  r[i] = line[0]
  for j in range(r[i]):
    t[line[j + 1] - 1].append(i)

if r[0] == 0:
  print("1")
  exit(0)

dp[0] = r[0]
given[0] = dp[0]
for i in range(1, n):
  suma = 0
  for j in range(len(t[i])):
    suma += (dp[i - 1] // dp[t[i][j]]) * (given[t[i][j]] // r[t[i][j]])
  if suma == 0 or r[i] == 0:
    dp[i] = dp[i - 1]
    continue
  given[i] = NWW(suma, r[i])
  dp[i] = dp[i - 1] * given[i] // suma

print(max(dp[n - 1], 1))