AtCoder Beginner Contest 118 - Foods Loved by Everyone

Katsusando loves omelette rice.
Besides, he loves crème brûlée, tenderloin steak and so on, and believes that these foods are all loved by everyone.
To prove that hypothesis, he conducted a survey on M kinds of foods and asked N people whether they like these foods or not.
The i-th person answered that he/she only likes the A_{i1}-th, A_{i2}-th, ..., A_{iK_i}-th food.
Find the number of the foods liked by all the N people.

-----Constraints-----
 - All values in input are integers.
 - 1 \leq N, M \leq 30
 - 1 \leq K_i \leq M
 - 1 \leq A_{ij} \leq M
 - For each i (1 \leq i \leq N), A_{i1}, A_{i2}, ..., A_{iK_i} are distinct.

-----Constraints-----
Input is given from Standard Input in the following format:
N M
K_1 A_{11} A_{12} ... A_{1K_1}
K_2 A_{21} A_{22} ... A_{2K_2}
:
K_N A_{N1} A_{N2} ... A_{NK_N}

-----Output-----
Print the number of the foods liked by all the N people.

-----Sample Input-----
3 4
2 1 3
3 1 2 3
2 3 2

-----Sample Output-----
1

As only the third food is liked by all the three people, 1 should be printed.

Difficulty: EASY

Starter code:

Solutions:
(N, M) = map(int, input().split())
food = []
for i in range(N):
	food.append(list(map(int, input().split())))
like = [0 for i in range(M)]
for i in range(N):
	for j in range(food[i][0]):
		like[food[i][j + 1] - 1] += 1
print(like.count(N))


(n, m) = map(int, input().split())
food = [0] * (m + 1)
for i in range(n):
	l = [int(x) for x in input().split()]
	l = set(l[1:])
	for x in l:
		food[x] += 1
ans = food.count(n)
print(ans)


(N, M) = map(int, input().split())
d = [0] * M
for _ in range(N):
	(K, *A) = map(int, input().split())
	for a in A:
		d[a - 1] += 1
print(d.count(N))


(N, M) = map(int, input().split())
b = []
s = [0] * M
for i in range(N):
	a = list(map(int, input().split()))
	del a[0]
	a.sort()
	b.append(a)
for i in range(N):
	for j in range(len(b[i])):
		s[b[i][j] - 1] += 1
print(s.count(N))


(n, m) = list(map(int, input().split()))
like = [0] * m
for _ in range(n):
	al = list(map(int, input().split()))
	k = al[0]
	ai = al[1:]
	for a in ai:
		like[a - 1] += 1
print(like.count(n))


(n, m) = list(map(int, input().split()))
foods = []
for i in range(n):
	foods.append(list(map(int, input().split())))
if len(foods) == 1:
	print(len(foods[0]) - 1)
else:
	ans = 0
	for i in foods[0][1:len(foods[0])]:
		cnt = 0
		for j in range(1, len(foods)):
			if i in foods[j][1:len(foods[j])]:
				cnt += 1
				if cnt == len(foods) - 1:
					ans += 1
	print(ans)


(n, m) = map(int, input().split())
ans = [0] * m
for i in range(n):
	tmp = list(map(int, input().split()))
	for j in range(len(tmp)):
		if j == 0:
			pass
		else:
			ans[tmp[j] - 1] += 1
print(ans.count(n))


(n, m) = list(map(int, input().split()))
if n == 1:
	a = list(map(int, input().split()))
	print(a[0])
else:
	A = list(map(int, input().split()))
	ans = set(A[1:])
	for _ in range(n - 1):
		A = list(map(int, input().split()))
		ans = ans & set(A[1:])
	print(len(ans))


(n, m) = map(int, input().split())
l = [0] * (m + 1)
for i in range(n):
	a = list(map(int, input().split()))
	for j in a[1:]:
		l[j] += 1
print(l.count(n))


(N, M) = map(int, input().split())
m = set((i for i in range(1, M + 1)))
for i in range(N):
	(k, *a) = map(int, input().split())
	m = m & set(a)
print(len(m))


(n, m) = list(map(int, input().split()))
s = set((i for i in range(1, m + 1)))
for i in range(n):
	(k, *a) = list(map(int, input().split()))
	s &= set(a)
print(len(s))


(N, M) = map(int, input().split())
ans = set(range(1, M + 1))
for _ in range(N):
	L = list(map(int, input().split()))
	ans &= set(L[1:])
print(len(ans))


(n, m) = map(int, input().split())
l = []
for i in range(n):
	p = list(map(int, input().split()))
	for j in range(1, p[0] + 1):
		l.append(p[j])
cnt = 0
for k in l:
	if l.count(k) == n:
		cnt += 1
print(cnt // n)


(a, b) = map(int, input().split())
L = []
for s in range(a):
	x = input().split()[1:]
	L = list(set(L) & set(x))
	if s == 0:
		L = x
print(len(L))


(N, M) = map(int, input().split())
A = []
for _ in range(N):
	KA = list(map(int, input().split()))
	A.append(KA[1:])
ans = [0] * M
for a in A:
	for i in a:
		ans[i - 1] += 1
print(ans.count(N))


(n, m) = map(int, input().split())
c = set(range(1, m + 1))
for i in range(n):
	(k, *a) = map(int, input().split())
	c &= set(a)
print(len(c))


(N, M) = map(int, input().split())
list = []
s = set(range(1, M + 1))
for i in range(N):
	(K, *A) = map(int, input().split())
	s &= set(A)
print(len(s))


(n, m) = map(int, input().split())
ans = set(input().split()[1:])
for _ in range(n - 1):
	ans &= set(input().split()[1:])
print(len(ans))


(N, M) = map(int, input().split())
liked = set(range(1, M + 1))
for _ in range(N):
	liked &= set(map(int, input().split()[1:]))
print(len(liked))


(N, M) = map(int, input().split())
R = set(range(1, M + 1))
for i in range(N):
	L = list(map(int, input().split()))
	R = set(L[1:]) & R
print(len(R))


(n, m) = map(int, input().split())
like = [0] * (m + 1)
for i in range(n):
	(k, *a) = map(int, input().split())
	for j in a:
		like[j] += 1
print(like.count(n))


(N, M) = map(int, input().split())
l = [0] * M
for _ in range(N):
	(K, *A) = map(int, input().split())
	for i in range(K):
		l[A[i] - 1] += 1
print(l.count(N))


(N, M) = map(int, input().split())
a = [input().split() for i in range(N)]
for b in a:
	del b[0]
x = set(a[0])
for b in a:
	x = x & set(b)
print(len(x))


(n, m) = map(int, input().split())
print(len(set.intersection(*[set(input().split()[1:]) for _ in [0] * n])))


(N, M) = map(int, input().split())
c = set(range(M + 1))
for i in range(N):
	(a, *b) = map(int, input().split())
	c &= set(b)
print(len(c))


(n, m) = map(int, input().split())
ans = set(range(1, 31))
for i in range(n):
	kA = list(map(int, input().split()))
	k = kA[0]
	A = kA[1:]
	ans = ans & set(A)
print(len(ans))


def i():
	return list(map(int, input().split()))
l = [set(i()[1:]) for _ in range(i()[0])]
print(len(l[0].intersection(*l[1:])))


(N, M) = map(int, input().split())
a = set((str(x) for x in range(1, M + 1)))
for i in range(N):
	li = list(input().split())
	a = a & set(li[1:])
print(len(a))


(a, b) = map(int, input().split())
for i in range(a):
	(n, *a) = map(int, input().split())
	if i == 0:
		l = a
	else:
		l = set(a) & set(l)
print(len(l))


(N, M) = map(int, input().split())
X = [0] * (M + 1)
for _ in range(N):
	A = list(map(int, input().split()))[1:]
	for a in A:
		X[a] += 1
print(X.count(N))


(N, M) = map(int, input().split())
C = set(list(range(1, M + 1)))
for _ in range(N):
	L = list(map(int, input().split()))
	A = L[1:]
	C = C & set(A)
print(len(C))


(N, M) = map(int, input().split())
l = [list(map(int, input().split())) for i in range(N)]
ans = [0] * (M + 1)
for i in range(N):
	for j in range(l[i][0]):
		ans[l[i][j + 1]] += 1
print(ans.count(N))


(n, m) = map(int, input().split(' '))
ks = [set(list(map(int, input().split(' ')))[1:]) for i in range(n)]
ans = set.intersection(*ks)
print(len(ans))


(n, m) = map(int, input().split())
all = [0 for i in range(m)]
ans = 0
for i in range(n):
	p = list(map(int, input().split()))
	last = p[0] + 1
	for l in range(1, last):
		all[p[l] - 1] += 1
for i in all:
	if i == n:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
l = [{int(i) for i in input().split()[1:]} for i in range(n)]
cnt = l[0]
for a in l:
	cnt = cnt & a
print(len(cnt))


(n, m) = map(int, input().split())
lis = [list(map(int, input().split()))[1:] for _ in range(n)]
print(len(set.intersection(*map(set, lis))))


(N, M) = map(int, input().split())
S = set(range(1, M + 1))
for i in range(N):
	(K, *A) = map(int, input().split())
	S &= set(A)
print(len(S))


(n, m) = map(int, input().split())
ka = [list(map(int, input().split())) for i in range(n)]
cnt = 0
for i in range(m + 1):
	suki = 0
	for j in range(n):
		if i in ka[j][1:]:
			suki += 1
	if suki == n:
		cnt += 1
print(cnt)


(N, M) = map(int, input().split())
d = [0] * M
for i in range(N):
	KA = list(map(int, input().split()))
	A = KA[1:]
	for i in A:
		d[i - 1] += 1
print(d.count(N))


(n, m) = map(int, input().split())
ans = set(range(m + 1))
for i in range(n):
	a = list(map(int, input().split()))
	ans = ans & set(a[1:])
print(len(ans))


(n, m) = map(int, input().split())
s = set((i + 1 for i in range(m)))
for i in range(n):
	t = [int(i) for i in input().split()]
	t = set(t[1:])
	s = s & t
print(len(s))


(n, m) = [int(_) for _ in input().split()]
s = set(range(1, m + 1))
for i in range(n):
	s &= set([int(_) for _ in input().split()][1:])
print(len(s))


def inpl():
	return list(map(int, input().split()))
(N, M) = inpl()
food = set(inpl()[1:])
for _ in [0] * (N - 1):
	food &= set(inpl()[1:])
print(len(food))


(n, m) = map(int, input().split())
(c, *a) = map(int, input().split())
for i in range(n - 1):
	(x, *y) = map(int, input().split())
	a = list(set(a) & set(y))
print(len(a))


(N, M) = map(int, input().split())
l = [0] * M
for _ in range(N):
	A = list(map(int, input().split()))
	for j in range(A[0]):
		l[A[j + 1] - 1] += 1
print(l.count(N))


(N, M) = list(map(int, input().split()))
ans = set(list(map(int, input().split()))[1:])
for i in range(N - 1):
	line = set(list(map(int, input().split()))[1:])
	ans = ans & line
print(len(ans))


(N, M) = map(int, input().split())
B = [0] * 30
for i in range(N):
	(K, *A) = map(int, input().split())
	for a in A:
		B[a - 1] += 1
print(sum((c == N for c in B)))


(N, M) = list(map(int, input().split()))
K1 = []
for i in range(N):
	K1.append(list(map(int, input().split())))
new_K1 = []
for n in range(N):
	del K1[n][0]
	new_K1.extend(K1[n])
count = 0
for y in range(1, M + 1):
	if new_K1.count(y) == N:
		count += 1
print(count)


(n, m) = list(map(int, input().split()))
c = []
cnt = 0
for i in range(n):
	a = list(map(int, input().split()))
	for j in range(1, len(a)):
		c.append(a[j])
for j in range(1, m + 1):
	if c.count(j) == n:
		cnt += 1
print(cnt)


(n, m) = map(int, input().split())
KA = [list(map(int, input().split())) for _ in range(n)]
ans = [0] * m
for i in range(n):
	A = KA[i][1:]
	for a in A:
		ans[a - 1] += 1
cnt = 0
for a in ans:
	if a == n:
		cnt += 1
print(cnt)


(N, M) = map(int, input().split())
B = set((m for m in range(1, 1 + M)))
for n in range(N):
	A = list(map(int, input().split()))
	B &= set(A[1:])
print(len(B))


(N, M) = list(map(int, input().split()))
con = 0
like = 0
List = []
for i in range(1, N + 1):
	L = list(map(int, input().split()))
	for a in range(L[0]):
		b = L[a + 1]
		List.append(b)
for j in range(1, M + 1):
	con = 0
	for k in List:
		if k == j:
			con += 1
	if con == N:
		like += 1
print(like)


(n, m) = map(int, input().split())
a = []
for _ in [0] * n:
	a.extend(list(map(int, input().split()))[1:])
print(sum((n == a.count(i + 1) for i in range(m))))


(N, M) = map(int, input().split())
h = {i for i in range(1, M + 1)}
for _ in range(N):
	a = list(map(int, input().split()))
	a = set(a[1:])
	h &= a
print(len(h))


(n, m) = map(int, input().split())
foods = set(range(1, m + 1))
for _ in range(n):
	(k, *a) = map(int, input().split())
	foods &= set(a)
print(len(foods))


(n, m) = map(int, input().split())
line = [0 for i in range(m + 1)]
ans = 0
for i in range(n):
	like_list = list(map(int, input().split()))
	for j in range(like_list[0]):
		line[like_list[j + 1]] += 1
for i in range(m + 1):
	if line[i] == n:
		ans += 1
print(ans)


(N, M) = [int(i) for i in input().split()]
foods = set(range(1, M + 1))
for i in range(N):
	foods = foods & set([int(i) for i in input().split()][1:])
print(len(foods))


(n, m) = map(int, input().split())
fav = set(range(1, m + 1))
for i in range(n):
	fav &= set(map(int, input().split()[1:]))
print(len(fav))


(N, M) = map(int, input().split())
res = [0] * M
for i in range(N):
	(K, *A) = map(int, input().split())
	for j in range(K):
		res[A[j] - 1] += 1
cnt = 0
for i in range(M):
	cnt += res[i] == N
print(cnt)


(N, M) = map(int, input().split())
food = set(range(1, M + 1))
for i in range(N):
	A = map(int, input().split()[1:])
	food &= set(A)
print(len(food))


(n, m) = map(int, input().split())
k_a = [list(map(int, input().split())) for _ in range(n)]
ans = {}
for a in k_a:
	for i in a[1:]:
		if i in ans.keys():
			ans[i] += 1
		else:
			ans[i] = 1
print(sum([1 for (i, v) in ans.items() if v == n]))


(N, M) = map(int, input().split())
R = set(range(1, M + 1))
for _ in range(N):
	(K, *A) = map(int, input().split())
	R &= set(A)
print(len(R))


(n, m) = map(int, input().split())
A = set(range(1, m + 1))
for _ in range(n):
	(a, *b) = map(int, input().split())
	A = A & set(b)
print(len(A))


(n, m) = map(int, input().split())
l = range(1, m + 1)
for i in range(n):
	b = list(map(int, input().split()))
	b.pop(0)
	l = set(l) & set(b)
print(len(l))


(n, m) = map(int, input().split())
S = set(range(1, m + 1))
for _ in range(n):
	(ignore, *A) = map(int, input().split())
	S &= set(A)
print(len(S))


print(len(set.intersection(*[set(input().split()[1:]) for _ in [0] * int(input().split()[0])])))


(n, m) = map(int, input().split())
l = [0] * m
for i in range(n):
	k = tuple(map(int, input().split()))[1:]
	for i in k:
		l[i - 1] += 1
print(l.count(n))


(n, m) = map(int, input().split())
k = set(input()[2:].split())
for i in range(n - 1):
	k = k & set(input()[2:].split())
print(len(k))


from collections import Counter

def mapt(fn, *args):
	return tuple(map(fn, *args))

def Input():
	return mapt(int, input().split(' '))

def main():
	(n, m) = Input()
	data = [Input()[1:] for _ in range(n)]
	d = Counter((num for row in data for num in row))
	print(sum((value == n for value in d.values())))
main()


(n, m) = map(int, input().split())
dic = {}
ans = 0
for _ in range(n):
	lis = input().split()
	for i in range(1, len(lis)):
		if lis[i] in dic:
			dic[lis[i]] += 1
		else:
			dic[lis[i]] = 1
for v in dic.values():
	if v == n:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
L = [i for i in range(1, m + 1)]
for j in range(n):
	l = list(map(int, input().split()))
	del l[0]
	L = set(l) & set(L)
print(len(L))


(n, m) = map(int, input().split())
s = set(map(str, range(m + 1)))
for _ in range(n):
	s &= set(input().split()[1:])
print(len(s))


(n, m) = map(int, input().split())
A = set(list(map(int, input().split()))[1:])
for i in range(n - 1):
	A &= set(list(map(int, input().split()))[1:])
print(len(A))


(n, m) = map(int, input().split())
S = set(range(1, m + 1))
for i in range(n):
	(K, *a) = map(int, input().split())
	S = S & set(a)
print(len(S))


import itertools
(N, M) = map(int, input().split())
L = []
(res, cnt) = (0, 1)
for i in range(N):
	K = list(map(int, input().split()))
	L.append(K[1:])
L = list(itertools.chain.from_iterable(L))
L.sort()
L.append(100)
for i in range(len(L) - 1):
	if L[i] == L[i + 1]:
		cnt += 1
	else:
		if cnt == N:
			res += 1
		cnt = 1
print(res)


(a, b) = map(int, input().split())
for i in range(a):
	if i == 0:
		x = set(input().split()[1:])
	else:
		x = x & set(input().split()[1:])
print(len(x))


(n, m) = (int(i) for i in input().split())
x = [0] * m
for i in range(n):
	y = [int(i) for i in input().split()]
	for j in y[1:]:
		x[j - 1] += 1
print(x.count(n))


(N, M) = list(map(int, input().split()))
d = {i: 0 for i in range(1, M + 1)}
for _ in range(N):
	L = list(map(int, input().split()))[1:]
	for i in L:
		d[i] += 1
cnt = sum([1 for (k, v) in list(d.items()) if v == N])
print(cnt)


I = lambda : input().split()
(n, m) = map(int, I())
s = set(I()[1:])
for _ in [0] * ~-n:
	s &= set(I()[1:])
print(len(s))


q = set(map(str, range(31)))
for s in open(0).readlines()[1:]:
	t = set(s.split()[1:])
	q &= t
print(len(q))


(n, m) = map(int, input().split())
s = {}
for _ in range(n):
	(*b,) = map(int, input().split())
	b = b[1:]
	a = set(b)
	if not s:
		s = a
	else:
		s = s & a
print(len(s))


(n, m) = map(int, input().split())
s = set(range(1, m + 1))
for i in range(n):
	a = [int(x) for x in input().split()][1:]
	a = set(a)
	s &= a
print(len(s))


(N, M) = map(int, input().split())
se = set(range(1, M + 1))
for _ in range(N):
	(k, *A) = map(int, input().split())
	se &= set(A)
print(len(se))


(n, m) = map(int, input().split())
data = [0] * n
for i in range(n):
	data[i] = input().split()
ans = 0
if n == 1:
	print(len(data[0]) - 1)
else:
	for i in range(1, int(data[0][0]) + 1):
		bool = True
		for j in range(1, n):
			if data[0][i] not in data[j][1:]:
				bool = False
		if bool:
			ans += 1
	print(ans)


(n, m) = map(int, input().split())
a = set(range(1, m + 1))
for _ in range(n):
	a &= set(list(map(int, input().split()))[1:])
print(len(a))


(N, M) = map(int, input().split())
ans = set(range(1, M + 1))
for _ in range(N):
	(_, *rest) = map(int, input().split())
	ans &= set(rest)
print(len(ans))


(N, M) = map(int, input().split())
a = [set(input().split()[1:]) for _ in range(N)]
like = a[0]
for i in range(1, N):
	like = like & a[i]
print(len(like))


(n, m) = map(int, input().split())
for i in range(n):
	a = list(map(int, input().split()))
	a.pop(0)
	if i == 0:
		b = set(a)
	b = set(a) & b
print(len(b))


(N, M) = map(int, input().split())
S = set(range(1, M + 1))
for _ in range(N):
	l = list(map(int, input().split()))
	l.remove(l[0])
	s = set(l)
	S = S & s
print(len(S))


(n, m) = map(int, input().split())
a = []
for _ in range(n):
	(_, *b) = map(int, input().split())
	a += b
print(sum((n == a.count(i + 1) for i in range(m))))


N = input().split()[0]
like = set(input().split()[1:])
for i in range(int(N) - 1):
	like = like & set(input().split()[1:])
print(len(like))


(_, *t) = open(0)
print(len(set.intersection(*[set(s.split()[1:]) for s in t])))


from collections import Counter
from typing import List

def answer(n: int, m: int, kas: List[List[int]]) -> int:
	response = sum((ka[1:] for ka in kas), [])
	result = list(Counter(response).values())
	return result.count(n)

def main():
	(n, m) = map(int, input().split())
	kas = [list(map(int, input().split())) for _ in range(n)]
	print(answer(n, m, kas))

def __starting_point():
	main()
__starting_point()


import functools
(N, M) = map(int, input().split())
A = [set(map(int, input().split()[1:])) for _ in range(N)]
print(len(functools.reduce(set.intersection, A)))


(N, M) = map(int, input().split())
S = set([x for x in range(1, M + 1)])
for i in range(N):
	A = list(map(int, input().split()))
	B = set(A[1:])
	S = S & B
print(len(S))


(N, M) = map(int, input().split())
x = {i + 1 for i in range(M)}
for _ in range(N):
	x &= set(list(map(int, input().split()))[1:])
print(len(x))


((n, m), *ka) = [list(map(int, s.split())) for s in open(0)]
c = [0] * (m + 1)
for (k, *a) in ka:
	for elm in a:
		c[elm] += 1
print(c.count(n))


(N, M) = map(int, input().split())
f = [0] * M
for i in range(N):
	for a in list(map(int, input().split()))[1:]:
		f[a - 1] += 1
print(f.count(N))


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
x = [0] * m
for i in range(n):
	for j in range(1, a[i][0] + 1):
		for k in range(1, 31):
			if a[i][j] == k:
				x[k - 1] += 1
ans = 0
for l in x:
	if l == n:
		ans += 1
print(ans)


(N, M) = list(map(int, input().split()))
ka = [[int(x) for x in input().split()] for _ in range(N)]
K = list()
A = list()
for i in range(N):
	K.append(ka[i][0])
	A.append(ka[i][1:])
ans = [0] * (M + 1)
for i in range(N):
	for j in range(K[i]):
		ans[A[i][j]] += 1
cnt = 0
for i in range(M + 1):
	if ans[i] == N:
		cnt += 1
print(cnt)


(a, b) = map(int, input().split())
c = list(map(int, input().split()))[1:]
for _ in range(a - 1):
	c = set(c) & set(list(map(int, input().split()))[1:])
print(len(c))


(N, M) = map(int, input().split())
S = set(range(1, M + 1))
for _ in range(N):
	S.intersection_update(set(list(map(int, input().split()))[1:]))
print(len(S))


(N, M) = map(int, input().split())
ans = set(range(1, M + 1))
for _ in range(N):
	(K, *As) = map(int, input().split())
	ans &= set(As)
print(len(ans))


import sys
input = sys.stdin.readline

def main():
	(N, M) = [int(x) for x in input().split()]
	KA = [[int(x) for x in input().split()] for _ in range(N)]
	ans = [0] * M
	for ka in KA:
		for a in ka[1:]:
			ans[a - 1] += 1
	print(sum([int(x == N) for x in ans]))

def __starting_point():
	main()
__starting_point()


(N, M) = map(int, input().split())
KA = [list(map(int, input().split())) for _ in range(N)]
s = set(range(1, M + 1))
for (k, *A) in KA:
	s &= set(A)
print(len(s))


(n, m) = (int(i) for i in input().split())
a = [{int(i) for i in input().split()[1:]} for _ in range(n)]
ans = a[0]
for s in a:
	ans = ans & s
print(len(ans))


(n, m) = [int(i) for i in input().split()]
list_a = [[s for s in input().split()] for i in range(0, n)]
list_ans = [str(s) for s in range(1, m + 1)]
for i in range(0, n):
	for j in range(0, m):
		if list_ans[j] not in list_a[i][1:]:
			list_ans[j] = '0'
print(len([s for s in list_ans if s != '0']))


(n, m) = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
count = 0
for i in range(1, m + 1):
	check = True
	for j in range(n):
		if i not in a[j][1:]:
			check = False
	if check:
		count += 1
print(count)


(n, m) = map(int, input().split())
a = [0] * m
for i in range(n):
	a1 = list(map(int, input().split()))
	for i in a1[1:]:
		a[i - 1] += 1
print(a.count(n))


(N, M) = map(int, input().split())
A = [0] * M
for _ in range(N):
	(_, *T) = map(int, input().split())
	for t in T:
		A[t - 1] += 1
print(A.count(N))


(n, m) = map(int, input().split())
a = [0] * m
for _ in range(n):
	b = list(map(int, input().split()))
	for i in b[1:]:
		a[i - 1] += 1
print(sum((x == n for x in a)))


(N, M) = map(int, input().split())
KA = []
flag = [0] * M
for i in range(N):
	for j in list(map(int, input().split()))[1:]:
		flag[j - 1] += 1
print(flag.count(N))


(n, m) = map(int, input().split())
e = 0
d = []
for i in range(1, n + 1):
	l = list(map(int, input().split()))
	for a in range(l[0]):
		b = l[a + 1]
		d.append(b)
for j in range(1, m + 1):
	c = 0
	for k in d:
		if k == j:
			c += 1
	if c == n:
		e += 1
print(e)


(n, m) = map(int, input().split())
res = set(range(1, m + 1))
for i in range(n):
	(a, *b) = map(int, input().split())
	res &= set(b)
print(len(res))


(N, M) = list(map(int, input().split()))
t = [0 for i in range(M + 1)]
for i in range(N):
	A = list(map(int, input().split()))
	for j in range(1, A[0] + 1):
		t[A[j]] += 1
ans = 0
for i in t:
	if i == N:
		ans += 1
print(ans)


(n, m) = list(map(int, input().split()))
nums = [0 for num in range(m)]
for i in range(n):
	k = [int(s) for s in input().split()]
	for j in range(1, len(k)):
		nums[k[j] - 1] += 1
print(nums.count(n))


(N, M) = input().split(' ')
S = set((str(i) for i in range(1, int(M) + 1)))
for _ in range(int(N)):
	S = S & set(input().split(' ')[1:])
print(len(S))


(n, m) = map(int, input().split())
S = set(range(1, m + 1))
for i in range(n):
	(k, *A) = map(int, input().split())
	S &= set(A)
print(len(S))


(n, m) = map(int, input().split())
al = []
kazu = []
for i in range(n):
	ka = list(map(str, input().split()))
	for j in range(int(ka[0])):
		al.append(ka[j + 1])
from collections import Counter
l = Counter(al)
for i in range(m):
	kazu.append(l[str(i + 1)])
print(kazu.count(n))


(n, m) = map(int, input().split())
k = [list(map(int, input().split())) for _ in range(n)]
l = [0 for i in range(m)]
count = 0
for i in k:
	for j in i[1:]:
		l[j - 1] += 1
for i in l:
	if i == n:
		count += 1
print(count)


(N, M) = list(map(int, input().split()))
l = set([i for i in range(1, M + 1)])
for _ in range(N):
	(k, *lst) = list(map(int, input().split()))
	l = l & set(lst)
print(len(l))


(n, m) = map(int, input().split())
lst = [list(map(int, input().split()))[1:] for _ in range(n)]
set_ans = set.intersection(*map(set, lst))
print(len(set_ans))


a = list(map(int, input().split()))
N = a[0]
M = a[1]
ctr = [0 for i in range(M)]
for i in range(N):
	b = list(map(int, input().split()))
	for j in range(b[0]):
		for k in range(M):
			if b[j + 1] == k + 1:
				ctr[k] += 1
flag = [N == ctr[j] for j in range(M)]
print(sum(flag))


(N, M) = [int(x) for x in input().split()]
Like = [0 for _ in range(M + 1)]
for i in range(N):
	KA = [int(x) for x in input().split()]
	for j in range(1, KA[0] + 1):
		Like[KA[j]] += 1
ans = 0
for i in range(M + 1):
	if Like[i] == N:
		ans += 1
print(ans)


(N, M) = map(int, input().split())
s = [input().split() for _ in range(N)]
ans = set(s[0][1:])
for l in s[1:]:
	ans = ans & set(l[1:])
print(len(ans))


(N, M) = map(int, input().split())
l = [0] * M
for i in range(N):
	L = list(map(int, input().split()))
	num = L[0]
	A = L[1:]
	for j in range(num):
		l[A[j] - 1] += 1
print(l.count(N))


def lcm(a, b):
	return a * b // math.gcd(a, b)
MOD = 10 ** 9 + 7
(n, m) = list(map(int, input().split()))
L = [0] * (m + 1)
for i in range(n):
	A = list(map(int, input().split()))
	for k in range(1, A[0] + 1):
		L[A[k]] += 1
print(L.count(n))


from collections import Counter
(n, m) = map(int, input().split())
lis = []
cnt = 0
for i in range(n):
	l = list(map(int, input().split()))
	lis += l[1:]
d = Counter(lis)
for i in d.values():
	if i == n:
		cnt += 1
print(cnt)


(n, m) = map(int, input().split())
a = [0] * (m + 1)
for _ in range(n):
	s = list(map(int, input().split()))
	for i in range(1, len(s)):
		a[s[i]] += 1
print(a.count(n))


(N, M) = map(int, input().split())
B = set(range(1, M + 1))
for _ in range(N):
	A = [int(x) for x in input().split()]
	B &= set(A[1:])
print(len(B))


(n, m) = list(map(int, input().split()))
like = [0] * m
for i in range(n):
	a = list(map(int, input().split()))[1:]
	for j in a:
		like[j - 1] += 1
print(sum((i == n for i in like)))


(N, M) = map(int, input().split())
K = []
ans = 0
for _ in range(N):
	K += input().split()[1:]
S = set(K)
for s in S:
	if K.count(s) == N:
		ans += 1
print(ans)


I = lambda : map(int, input().split())
(N, M) = I()
R = set(range(1, M + 1))
for _ in [0] * N:
	(_, *A) = I()
	R &= set(A)
print(len(R))


(N, M) = map(int, input().split())
K = []
for i in range(N):
	K.append(list(map(int, input().split())))
K_list = []
for x in range(N):
	K[x].remove(K[x][0])
	K_list.extend(K[x])
cnt = 0
for j in range(1, M + 1):
	if K_list.count(j) == N:
		cnt += 1
print(cnt)


import functools
print(len(functools.reduce(lambda x, y: x & y, [set(input().split()[1:]) for _ in [0] * int(input().split()[0])])))


print(len(set.intersection(*[set(s.split()[1:]) for s in open(0).readlines()[1:]])))


I = lambda : map(int, input().split())
(n, m) = I()
F = [n] * (m + 1)
for _ in range(n):
	(k, *A) = I()
	for a in A:
		F[a] -= 1
print(F.count(0))


(a, b) = map(int, input().split())
L = list(map(str, input().split()))
L.pop(0)
for i in range(a - 1):
	c = list(map(str, input().split()))
	c.pop(0)
	L = list(set(L) & set(c))
print(len(L))


(N, M) = map(int, input().split())
s = set(range(1, M + 1))
for _ in range(N):
	s &= set(list(map(int, input().split()))[1:])
print(len(s))


(N, M) = map(int, input().split())
Set = set(range(1, M + 1))
for i in range(N):
	Set = Set & set(list(map(int, input().split()))[1:])
print(len(Set))


(n, m) = map(int, input().split())
x = [list(map(int, input().split())) for i in range(n)]
f = x[0]
g = set(f[1:])
for i in range(1, n):
	f = x[i]
	g = g & set(f[1:])
print(len(g))


I = lambda : set(input().split()[1:])
n = int(input()[:2]) - 1
s = I()
for _ in [0] * n:
	s &= I()
print(len(s))


(n, m) = map(int, input().split())
l = [set(list(map(int, input().split()))[1:]) for _ in range(n)]
print(len(l[0].intersection(*l[1:])))


(N, M) = map(int, input().split())
like = [0] * M
for i in range(N):
	(k, *A) = map(int, input().split())
	for j in A:
		like[j - 1] += 1
print(like.count(N))


(N, M) = map(int, input().split())
A_list = []
for _ in range(N):
	A = list(map(int, input().split()))
	del A[0]
	A_list.extend(A)
ans = 0
for i in range(1, M + 1):
	if A_list.count(i) == N:
		ans += 1
print(ans)


(N, M) = map(int, input().split())
S = set(range(1, M + 1))
for _ in range(N):
	ka = list(map(int, input().split()))
	A = set(ka[1:])
	S = S & A
print(len(S))


(n, m) = map(int, input().split())
l = [0] * m
for _ in range(n):
	(k, *a) = map(int, input().split())
	for i in a:
		l[i - 1] += 1
print(l.count(n))


(N, M) = map(int, input().split())
S = set(range(1, M + 1))
for _ in range(N):
	(k, *a) = map(int, input().split())
	S &= set(a)
print(len(S))


(n, m) = map(int, input().split())
k = []
cnt = 0
for i in range(n):
	tmp = input().split()
	tmp.pop(0)
	k += tmp
for i in range(m):
	if k.count(str(i + 1)) == n:
		cnt += 1
print(cnt)


(n, m) = list(map(int, input().split()))
(_, *A) = list(map(int, input().split()))
food = set(A)
for _ in range(n - 1):
	(k, *A) = list(map(int, input().split()))
	food &= set(A)
print(len(food))


import numpy as np
(n, m) = map(int, input().split())
k = np.zeros(n, dtype=int)
a = np.zeros((n, m), dtype=int)
for i in range(n):
	p = list(map(int, input().split()))
	k[i] = p[0]
	for j in range(1, len(p)):
		a[i][j - 1] = p[j]
ans = np.zeros(n + m, dtype=int)
for i in range(n):
	for j in range(m):
		if a[i][j] != 0:
			s = a[i][j] - 1
			ans[s] += 1
an = 0
for i in range(n + m):
	if ans[i] == n:
		an += 1
print(an)


(N, M) = map(int, input().split())
A = [set(list(map(int, input().split()))[1:]) for i in range(N)]
for i in range(1, N):
	A[0] &= A[i]
print(len(A[0]))


(n, _) = map(int, input().split())
print(len(set.intersection(*[set(input().split()[1:]) for _ in range(n)])))


(N, M) = map(int, input().split())
K = [set(input().split()[1:]) for _ in range(N)]
T = K[0]
for k in K:
	T = T & k
print(len(T))


(N, M) = map(int, input().split())
all_set = set.intersection(*map(set, (list(map(int, input().split()))[1:] for i in range(N))))
print(len(all_set))


(n, m) = map(int, input().split())
a = [set(input().split()[1:]) for _ in range(n)]
like = a[0]
for i in range(1, n):
	like = like & a[i]
print(len(like))


(n, m) = map(int, input().split())
m_s = set(range(1, m + 1))
for i in range(n):
	(K, *A) = map(int, input().split())
	m_s = m_s & set(A)
print(len(m_s))


(N, M) = map(int, input().split())
S = set([_ + 1 for _ in range(M)])
for i in range(N):
	(l, *A) = map(int, input().split())
	S &= set(A)
print(len(S))


import sys
input = sys.stdin.readline

def main():
	interview = []
	(n, m) = map(int, input().split())
	interview = [list(map(int, input().split())) for _ in range(n)]
	set_data = {}
	for data in interview:
		if len(set_data) == 0:
			set_data = set(data[1:])
		else:
			set_data = set_data & set(data[1:])
	print(len(set_data))

def __starting_point():
	main()
__starting_point()


(n, m) = [int(x) for x in input().split()]
print(len(set.intersection(*[set(input().split()[1:]) for _ in range(n)])))


(N, M) = map(int, input().split())
se = set(range(M + 1))
for i in range(N):
	A = [int(x) for x in input().split()]
	se &= set(A[1:])
print(len(se))


(n, m) = map(int, input().split())
dic = {}
for i in range(n):
	k_list = [int(i) for i in input().split()]
	k = k_list[0]
	a_list = k_list[1:]
	for j in a_list:
		if j in dic:
			dic[j] += 1
		else:
			dic[j] = 1
value_list = list(dic.values())
ans = value_list.count(n)
print(ans)


(N, M) = map(int, input().split())
ans = set()
for i in range(N):
	A = list(map(int, input().split()))
	a = set(A[1:])
	if not ans:
		ans = a
	else:
		ans = ans & a
print(len(ans))


import sys
import copy
import math
import itertools
import numpy as np
l = [int(c) for c in input().split()]
N = l[0]
M = l[1]
KA = [list(map(int, input().split())) for c in range(N)]
F = [0] * M
for i in range(N):
	for j in range(1, KA[i][0] + 1):
		F[KA[i][j] - 1] += 1
print(F.count(N))


(N, M) = map(int, input().split())
L = [0] * 31
for n in range(N):
	(K, *A) = map(int, input().split())
	for a in A:
		L[a] += 1
print(L.count(N))


(n, m) = list(map(int, input().split()))
for i in range(n):
	a = list(map(int, input().split()))
	if i == 0:
		answer = set(a[1:])
	else:
		answer = answer & set(a[1:])
print(len(answer))


(N, M) = map(int, input().split())
m = [0] * M
for i in range(N):
	k = list(map(int, input().split()))
	for a in k[1:]:
		m[a - 1] += 1
print(m.count(N))


(N, M) = map(int, input().split())
f = set(range(1, M + 1))
for _ in range(N):
	f = f & set([int(x) for x in input().split()][1:])
print(len(f))


import collections
(n, m) = list(map(int, input().split()))
l = [list(map(int, input().split())) for l in range(n)]
tmp = []
for i in range(n):
	for a in range(l[i][0]):
		tmp.append(l[i][a + 1])
c = collections.Counter(tmp)
ans = []
for x in list(c.items()):
	if x[1] == n:
		ans.append(x[0])
print(len(ans))


(n, m) = map(int, input().split())
c = [0] * m
for i in range(n):
	a = list(map(int, input().split()))
	for e in a[1:]:
		c[e - 1] += 1
print(c.count(n))


def main():
	(n, m) = list(map(int, input().split()))
	(k, *a) = list(map(int, input().split()))
	ans = set(a)
	for i in range(n - 1):
		(k, *a) = list(map(int, input().split()))
		ans = ans & set(a)
	print(len(ans))

def __starting_point():
	main()
__starting_point()


(n, m) = map(int, input().split())
r = set(range(1, m + 1))
for i in range(n):
	(_, *b) = map(int, input().split())
	r = set(r) & set(b)
print(len(r))


(N, M) = map(int, input().split())
foods = [0] * M
for i in range(N):
	KA = list(map(int, input().split()))
	for a in KA[1:]:
		foods[a - 1] += 1
cnt = 0
for j in foods:
	if j == N:
		cnt += 1
print(cnt)


(n, m) = map(int, input().split())
res = [0] * m
for _ in [0] * n:
	(_, *o) = map(int, input().split())
	for x in o:
		res[x - 1] += 1
ans = res.count(n)
print(ans)


(n, m) = map(int, input().split())
l = [0] * m
for i in range(n):
	(k, *f) = map(int, input().split())
	for j in range(k):
		l[f[j] - 1] += 1
print(l.count(n))


(N, M) = map(int, input().split())
A = [set(map(int, input().split()[1:])) for _ in range(N)]
for a in A:
	A[0] &= a
print(len(A[0]))


(n, m) = map(int, input().split())
k = [list(map(int, input().split())) for i in range(n)]
c = 0
for i in range(1, m + 1):
	for j in range(n):
		if i not in k[j][1:]:
			break
	else:
		c += 1
print(c)


import math
import collections
from itertools import product
ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(map(int, input().split()))
(n, m) = mi()
ka = [li() for _ in range(n)]
food = [0] * m
for i in range(n):
	for j in range(1, ka[i][0] + 1, 1):
		food[ka[i][j] - 1] += 1
print(food.count(n))


import sys
sys.setrecursionlimit(10 ** 7)

def I():
	return int(sys.stdin.readline().rstrip())

def MI():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def LI():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def LI2():
	return list(map(int, sys.stdin.readline().rstrip()))

def S():
	return sys.stdin.readline().rstrip()

def LS():
	return list(sys.stdin.readline().rstrip().split())

def LS2():
	return list(sys.stdin.readline().rstrip())
(N, M) = MI()
X = LI()
ANS = set(X[1:])
for i in range(N - 1):
	X = LI()
	ANS &= set(X[1:])
print(len(ANS))


(n, m) = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
dp = [0] * m
for i in range(n):
	for j in range(ab[i][0]):
		k = ab[i][j + 1]
		dp[k - 1] += 1
print(dp.count(n))


(N, M) = map(int, input().split())
L = [0] * M
for _ in range(N):
	KA = list(map(int, input().split()))
	for i in KA[1:]:
		L[i - 1] += 1
print(L.count(N))


import collections
import itertools
(N, M) = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]
for x in A:
	n = x.pop(0)
A = list(itertools.chain.from_iterable(A))
C = collections.Counter(A)
ct = 0
for i in range(1, M + 1):
	if C[i] == N:
		ct += 1
print(ct)


(n, m) = list(map(int, input().split()))
s = 0
for i in range(1, m + 1):
	s |= 1 << i
for i in range(n):
	a = list(map(int, input().split()))
	a = list(a)
	t = 0
	for j in range(1, len(a)):
		t |= 1 << a[j]
	s &= t
ans = 0
for i in range(1, m + 1):
	if s & 1 << i != 0:
		ans += 1
print(ans)


(N, M) = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]
for x in A:
	n = x.pop(0)
I = set(A[0])
for i in range(1, N):
	I = I.intersection(A[i])
print(len(I))


(N, M) = map(int, input().split())
l = []
for i in range(N):
	l.append(list(map(int, input().split())))
ans = [0] * (M + 1)
for i in range(N):
	n = l[i]
	for j in range(1, n[0] + 1):
		ans[n[j]] += 1
cnt = 0
for i in range(M + 1):
	if ans[i] == N:
		cnt += 1
print(cnt)


(n, m) = map(int, input().split())
l = [0 for i in range(m)]
for i in range(n):
	ka = [int(x) for x in input().split()]
	k = ka[0]
	for j in range(1, k + 1):
		l[ka[j] - 1] += 1
ans = 0
for i in l:
	if i == n:
		ans += 1
print(ans)


(n, m) = map(int, input().split())
ka = [list(map(int, input().split())) for _ in range(n)]
flg = [0] * (m + 1)
for i in range(n):
	for j in range(1, ka[i][0] + 1):
		food = ka[i][j]
		flg[food] += 1
result = 0
for i in range(m + 1):
	if flg[i] == n:
		result += 1
print(result)