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
k, n1 = map(int, input().split())

number_of_meetings_in_day = [n1]
meeting_continuation = [[0 for i in range(n1)]]
# employee_allocation - stores number of employees needed to participate in each meeting [# of days, # of meetings in each day]
employee_allocation = [[0 for i in range(n1)]]

for i in range(k-1):
    day = list(map(int, input().split()))

    number_of_meetings_in_day.append(day[0])

    meeting_continuation.append(day[1:])
    employee_allocation.append([0 for i in range(len(day[1:]))])

for j in range(number_of_meetings_in_day[k-1]):
    employee_allocation[k-1][j] = 1

max_cnt = max(n1, number_of_meetings_in_day[k-1])
for i in range(k-1, 0, -1):
    cnt = 0
    for j in range(number_of_meetings_in_day[i]):
        if meeting_continuation[i][j] != 0:
            employee_allocation[i-1][meeting_continuation[i][j] - 1] += employee_allocation[i][j]

    for j in range(number_of_meetings_in_day[i-1]):
        employee_allocation[i-1][j] = max(employee_allocation[i-1][j], 1)
        cnt += employee_allocation[i-1][j]

    max_cnt = max(max_cnt, cnt)

print(max_cnt)