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

def main():
    n = int(input())

    g = [list(map(lambda x: int(x)-1, input().split()))[1:] for _ in range(n)]

    ans = len(g[0])
    cnt = [1 if i in g[0] else 0 for i in range(n)]

    for i in range(n):
        period, sofar = len(g[i]), cnt[i]

        cnt[i] = 0
        if sofar == 0 or period == 0:
            continue

        mul = period // gcd(period, sofar)
        ans *= mul

        for x in range(n):
            cnt[x] *= mul
        for x in g[i]:
            cnt[x] += sofar * mul // period


    if ans == 0:
        ans += 1
    print(ans)

if __name__ == '__main__':
    main()