Problem:


Score : 200 points

Problem Statement

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 1

3 4
2 1 3
3 1 2 3
2 3 2

Sample Output 1

1

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

Sample Input 2

5 5
4 2 3 4 5
4 1 3 4 5
4 1 2 4 5
4 1 2 3 5
4 1 2 3 4

Sample Output 2

0

Katsusando's hypothesis turned out to be wrong.

Sample Input 3

1 30
3 5 10 30

Sample Output 3

3



Sample input:
3 4
2 1 3
3 1 2 3
2 3 2


Sample output:
1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
KA = [tuple(map(int, input().split())) for _ in range(N)]

mask = int("1" * M, 2)
flag = mask

for k, *al in KA:
	tf = 0
	for a in al:
		tf |= 1 << (M - a)
	#print(format(~tf & mask, "b").zfill(M))
	flag &= tf
	#print(format(flag, "b").zfill(M))
print(bin(flag).count("1"))

Submission status: Accepted

Solution code:
# ABC118B - Foods Loved by Everyone
n, m = list(map(int, input().rstrip().split()))
lst = [list(map(int, input().rstrip().split())) for _ in range(n)]
data = [0] * m
count = 0

for i in range(n):
    for j in range(1, lst[i][0] + 1):
        data[lst[i][j] - 1] += 1

for k in range(m):
    if data[k] == n:
        count += 1

print(count)

Submission status: Accepted

Solution code:
import copy

N, M = map(int, input().split())

like = list(map(int, input().split()))
like.pop(0)
all_like = set()
for l in like:
	all_like.add(l)
    
for i in range(N-1):
  like = list(map(int, input().split()))
  like.pop(0)
  tmp = copy.deepcopy(all_like)
  for l in all_like:
    if l not in like:
      tmp.remove(l);
  all_like = tmp
print(len(all_like))

Submission status: Accepted

Solution code:
N,K= map(int,input().split())
L=[]
for i in range(N):
    L.append([int(j) for j in input().split()][1:])
L=[flatten for inner in L for flatten in inner]
ans=[]
for i in set(L):
    if L.count(i)==N:
        ans.append(i)
print(len(ans))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ka = [list(map(int, input().split())) for _ in range(n)]

a = 0

for i in range(m):
    loved = True
    for j in range(n):
        if ka[j][1:].count(i+1) == 1:
            continue
        else:
            loved = False
            break

    if loved:
        a += 1

print(a)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
kLst = [list(map(int, input().split())) for i in range(N)]

ansLst = [0] * M
for i in range(N):
    for j in range(1, len(kLst[i])):
        ansLst[kLst[i][j] - 1] += 1

ansCnt = 0
for i in ansLst:
    if i == N:
        ansCnt += 1

print(ansCnt)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

N, M = map(int, input().split())
As = []
for _ in range(N):
    As += list(map(int, input().split()))[1:]

ans = 0
for i in range(1, M + 1):
    ans += 1 if sum([1 for A in As if A == i]) == N else 0

print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())

foods = list(range(1, M+1))

for i in range(N):
    fav_food = list(map(int, input().split()))
    fav_food = fav_food[1:]
    foods = [food for food in foods if fav_food.count(food) == 1]     
    

print(len(foods))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
c=[0]*m
for i in range(n):
    li=list(map(int,input().split()))
    for j in range(li[0]):
        c[li[j+1]-1]+=1
        ans=0
for i in range(m):
    if c[i]==n:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
#9:41〜9:52
N,M=map(int,input().split())
likelist=[]
for n in range(N):
	like=list(map(int,input().split()))
	likelist.extend(like[1:])
everyonelikes=0
for m in range(1,M+1):
	if likelist.count(m) == N:
		everyonelikes += 1
print(everyonelikes)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
cnt = [0] * 40
for _ in range(N):
    for a in list(map(int, input().split()))[1:]:
        cnt[a] += 1
ans = 0
for c in cnt:
    if c == N:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())

count = [0 for i in range(m)]

for j in range(n):
    check = list(map(int, input().split()))
    for k in range(check[0]):
        count[check[k+1] - 1] += 1

ans = 0
for l in range(len(count)):
    if count[l] == n:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
food = set(range(1, m+1))

for i in range(n):
    food &= set(list(map(int, input().split()))[1:])

print(len(food))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
listF=[]
for i in range(N):
    listF.append(list(map(int,input().split())))

listC=listF[0][1:]

for i in range(N-1):
    listC=list(set(listF[i+1][1:]) & set(listC))

print(len(listC))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
K = 0
list1 = []
list2 = []
list1 = list(map(int, input().split()))
list1 = list1[1:]
for i in range(N-1):
  list2 = list(map(int, input().split()))
  list1 = list(set(list2[1:]) & set(list1))
  if len(list1) == 0:
    break
print(len(list1))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())

dicFood = {}
for _ in range(N):
	food = list(map(int,input().split()))
	for k in food[1:]:
		if k not in dicFood:
			dicFood[k] = 1
		else:
			dicFood[k] +=1
		
count = 0	
for v in dicFood.values():
	if v == N:
		count += 1
		
print(count)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
listF = []
for i in range(N):
    listF.append(list(map(int, input().split())))

listC = listF[0][1:]
for i in range(N-1):
    listC = list(set(listF[i+1][1:]) & set(listC))


print(len(listC))

Submission status: Accepted

Solution code:
N,M=[int(i) for i in input().split()]
buf=[0]*M
for i in range(N):
  a=[int(i) for i in input().split()]
  for j in a[1:]:
    buf[j-1]+=1
c=0
for i in buf:
  if i==N:
    c+=1
print(c)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
like = []

for i in range(n):
    temp = list(map(int, input().split()))
    k = temp[0]
    like.append(temp[1:k + 1])

ans = 0

for j in range(1, m + 1):
    c = 1
    for i in range(n):
        if not(j in like[i]):
            c = 0
    if c == 1:
        ans = ans + 1

print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
KA = []
box = [0] * N
for i in range(N):
    KA.append(list(map(int, input().split())))
    box[i] = [0] * M
    for j in range(1, M+1):
        if j in KA[i][1:]:
            box[i][j-1] = 1

temp = [0] * M
for i in range(N):
    for j in range(M):
        temp[j] += box[i][j]
        
print(temp.count(N))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

N, M = list(map(int, input().split()))

# 行の先頭を除去するために[1:]をしてる｡
a = [list(map(int, input().split()))[1:] for i in range(N)]

# flatten
a = sum(a, [])

# print(a)

import collections

a = collections.Counter(a)

a = list(a.items())

# print(a)

count = 0

for i, j in a:
    if j >= N:
        count += 1

print(count)

Submission status: Accepted

Solution code:
n, m = [int(i) for i in input().split()]
liked = [0 for _ in range(m)]
for _ in range(n):
    _input = [int(i) for i in input().split()]
    for i in _input[1:]:
        liked[i-1] += 1
count = 0
for i in range(len(liked)):
    if liked[i] == n:
        count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
f = []

for i in range(n):
  f.append(list(map(int, input().split())))

num = [0 for i in range(m+1)]
  
for i in range(n):
  for j in range(1, len(f[i])):
    num[f[i][j]] += 1
    
    
cnt = 0
for i in num:
  if i == n:
    cnt += 1
    
    
print(cnt)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())

l = [0] * N
for i in range(N):
    l[i] = list(map(int, input().split()))

food = [0] * M
for i in l:
    for j in range(i[0]):
        food[i[j + 1] - 1] += 1

print(food.count(N))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
sum = {}
ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
sum = {}
ans = 0

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

Submission status: Accepted

Solution code:
# coding: utf-8

N, M = map(int, input().split())
sum = {}
ans = 0

for i in range(0, N):
    K = list(map(int, input().split()))
    for j in range(1, K[0] + 1):
        if K[j] not in sum:
            sum[K[j]] = 1
        else:
            sum[K[j]] += 1

for k in sum:
    if sum[k] == N:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = []
for _ in range(N):
    k_a = map(int, input().split())
    A.append(list(k_a)[:])

LIKE = [0 for _ in range(M + 1)]

for Ai in A:
    for a in Ai[1:]:
        LIKE[a] += 1

ans = 0
for x in LIKE:
    if x == N:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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)))

Submission status: Accepted

Solution code:
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]))

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
KA = []
a = []
ans = 0

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
count=[0]*m
ans=0
arr=[]
for i in range(n):
  arr.append(list(map(int,input().split())))
  for j in range(1,arr[i][0]+1):
    count[arr[i][j]-1]+=1
for i in range(m):
  if count[i]==n:
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
def main():
    n, m = [int(i) for i in input().split()]
    ans = [0 for i in range(m+1)]
    for i in range(n):
        k, *a = [int(i) for i in input().split()]
        for j in range(k):
            ans[a[j]] += 1
    print(ans.count(n))
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
K = [0] * N
A = [list(map(int, input().split())) for i in range(N)]
count = 0
for i in range(1, M+1, 1): 
    likecount = 0
    for j in range(N): 
        for k in range(1, A[j][0]+1, 1): 
            if A[j][k] == i:
                likecount += 1
    if likecount == N: 
        count += 1
print(count)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
K = [0] * N
A = [[0 for j in range(M)] for i in range(N)] 
for i in range(N):
    inpt = list(map(int, input().split())) 
    K[i] = inpt[0] 
    for j in range(1, K[i]+1, 1): 
        A[i][j-1] = inpt[j]
count = 0
for j in range(1, M+1, 1): 
    likecount = 0
    for i in range(N): 
        for k in range(K[i]): 
            if A[i][k] == j:
                likecount += 1
    if likecount == N: 
        count += 1
print(count)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = [list(map(int, input().split()))[1:] for i in range(n)]

ans = 0
for x in range(m):
    count = 0
    for i in range(n):
        if x + 1 in a[i]:
            count += 1
    if count == n:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())

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

Submission status: Accepted

Solution code:
N, M = [int(s) for s in input().split(' ')]
vote = [0] * M
for _ in range(N):
    answer = [int(s) for s in input().split(' ')][1:]
    for a in answer:
        vote[a-1] += 1
vote_all = 0
for v in vote:
    if v == N:
        vote_all += 1
print(vote_all)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
TOT=[0]*M
for i in range(N):
  List=[int(i) for i in input().split()]
  List.pop(0)
  List_N=[]
  for j in range (M):    
    if j+1 in List:
      List_N.append(1)
    else:
      List_N.append(0)
  TOTAL=[]
  for k in range(M):
    TOTAL.append(TOT[k]+List_N[k])
  TOT=TOTAL
print(TOT.count(N))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ka = [list(map(int, input().split())) for i in range(n)]
l = [0] * m

for i in range(n):
    for j in ka[i][1:]:
        l[j - 1] += 1

print(l.count(n))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
box =[]
for i in range(N):
    a = list(map(int,input().split()))
    box.append(a[1:])
    
ans = box[0]
for i in range(len(box)):
    ans = set(ans) & set(box[i])
print(len(ans))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
k = []
for i in range(N):
	l = list(map(int, input().split()))
	del l[0]
	k.append(l)
a = k[0]
for i in range(1, N, 1):
	a.extend(k[i])
	a = [x for x in set(a) if a.count(x) > 1]
print(len(a))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())

bag = {m+1: 0 for m in range(M)}

for n in range(N):
    all_list = list(map(int, input().split()))
    K = all_list[0]
    A = all_list[1:]
    for k in range(K):
        bag[A[k]] += 1

count = 0
for key, value in bag.items():
    if value == N:
        count += 1

print(count)

Submission status: Accepted

Solution code:
N, M = map(int,input().split())


like_count = [0 for _ in range(M+1)]

for _ in range(N):
    tmp = list(map(int,input().split()))
    like_list = tmp[1:]
    for like in like_list:
        like_count[like] += 1

count = 0
for value in like_count:
    if value == N:
        count += 1

print(count)

Submission status: Accepted

Solution code:
n,m=map(int, input().split())

ans = set(range(m+1))

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

print(len(ans))

Submission status: Accepted

Solution code:
N, M = map(int, raw_input().split())
menu = []
for i in range(0, M):
	menu.append(0)
for i in range(0, N):
	answer = map(int, raw_input().split())
	for j in range(1, answer[0]+1):
		menu[answer[j]-1] += 1
cnt = 0
for i in range(0, M):
	if menu[i] == N: cnt += 1

print cnt

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    like_count = [0 for _ in range(m + 1)]

    # time O(NM)
    for _ in range(n):
        tmp = list(map(int, input().split()))
        like_list = tmp[1:]
        for like in like_list:
            like_count[like] += 1

    # time O(M)
    count = 0
    for value in like_count:
        if value == n:
            count += 1

    print(count)


main()

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
l=[0]*M
for _ in range(N):
    a=list(map(int,input().split()))
    for i in range(1,len(a)):
        l[a[i]-1]+=1
ans=0
for i in l:
    if i==N:
        ans+=1

print(ans)

Submission status: Accepted

Solution code:
N,M=list(map(int,input().split(" ")))

r=set(list(map(int,input().split(" ")))[1:])
for z in range(N-1):
  r=r&set(list(map(int,input().split(" ")))[1:])

print(len(r))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())

KA = []
for i in range(N):
    if i == 0:
        lbe = list(map(int, input().split()))[1:]
    else:
        tmp = []
        for j in list(map(int, input().split()))[1:]:
            if j in lbe:
                tmp.append(j)
        lbe = tmp

print(len(lbe))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
l=[0]*M
for _ in range(N):
    a=list(map(int,input().split()))
    for i in range(1,len(a)):
        l[a[i]-1]+=1
        
ans=0
for i in l:
    if i==N:
        ans+=1

print(ans)

Submission status: Accepted

Solution code:
N,M = [int(i) for i in input().split()]

list_list = []
for i in range(N) :
    line = input().split()
    del line[0]
    list_list.append(line)

s = set(list_list[0])
for i in range(1,N) :
    s = s & set(list_list[i])

print(len(s))

Submission status: Accepted

Solution code:
n , m = map(int,input().split())
d = []
for i in range(n):
    a = list(input().split())
    a = a[1:]
    d.append(a)

d = sum(d,[])

import collections
c = collections.Counter(d)

keys = [k for k , v in c.items() if v == n]
print(len(keys))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
K = []
for i in range(N):
        A = list(map(int,input().split()))
        del A[0]
        K.append(A)
        result_list = K[0]
for j in range(1,N):
        result_list = set(result_list) & set(K[j])
        
print(len(result_list))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
truely_loved_food = {x for x in range(m + 1)}
for i in range(n):
    li = list(map(int, input().split()))
    k=li[0]
    loved_food = set(li[1:])
    truely_loved_food = truely_loved_food & loved_food
print(len(truely_loved_food))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import Counter

N, M = map(int, input().split())
KA_list = []
for i in range(N):
    for j in input().split()[1:]:
        KA_list.append(j)
c = Counter(KA_list)

ans = 0
for k, v in c.items():
    if v == N:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
nums = [list(map(int,input().split())) for i in range(n)]

l = [0] * m
for i in range(n):
    for elem in nums[i][1:]:
        l[elem-1] += 1

print(l.count(n))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
c = [0] * M
for i in range(N):
    a = [int(i) for i in input().split()]
    for j in a[1:]:
        c[j-1] += 1

print(c.count(N))

Submission status: Accepted

Solution code:
n,m = (int(x) for x in input().split())
k = []
a = []
for i in range(n):
    tmp = []
    for x in input().split():
        tmp.append(int(x))
    k.append(tmp[0])
    a.append(tmp[1:])

#hoge
x = [0 for i in range(m)]
for i in range(n):
    for j in range(k[i]):
        x[a[i][j]-1] += 1
ans = 0
for i in range(m):
    if x[i] == n:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
ans = [1] * M
li = [i for i in range(1,M+1)]
for i in range(N):
    a = [int(i) for i in input().split()[1::]]
    for i in set(li) - set(a):
        ans[i-1] = 0

print(sum(ans))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())

a = [list(map(int, input().split())) for i in range(n)]

x = [True] * m

for i in a:
    y = i[0]
    xx = [False] * m
    for j in range(y):
        xx[i[j + 1] - 1] = True
    for j in range(m):
        if xx[j] == False:
            x[j] = False

print(sum(x))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
import copy

n,m = [int(i) for i in input().split()]

common = list(range(1,m+1))
for i in range(n):
  like = [int(i) for i in input().split()][1:]
  for j in common[::-1]:
    if j not in like:
      common.remove(j)
  
print(len(common))

Submission status: Accepted

Solution code:
n, m = map(int, raw_input().split())
	
a0 = map(int, raw_input().split())
if n == 1:
	print a0[0]
else:
	a1 = map(int, raw_input().split())
	com = set(a0[1:]) & set(a1[1:])
	if n == 2:
		print len(list(com))
	else:
		for i in range(n-2):
			a1 = map(int, raw_input().split())
			com = com & set(a1[1:])
		print len(list(com))

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
A = []
counter = 0
ans = 0
for i in range(N):
    l = input().split()
    l.remove(l[0])
    A = A + l

for k in range(M):
    y = k+1
    counter = A.count(str(y))
    if counter == N:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
List = [list(map(int, input().split())) for i in range(N)]

def hantei(x):
  for j in range(N):
    if x not in List[j][1:]:
      return(0)
  return(1)

ans = 0
for i in range(1,M+1):
  ans = ans + hantei(i)
print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
l = [0] * m

for _ in range(n):
	a = list(map(int,input().split()))
	for i in range(1,len(a)):
		l[a[i] - 1]+=1

ans = 0
for i in l:
	if i == n:ans+=1

print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
lis = [[int(x) for x in input().split()] for _ in range(N)]
ans = 0
for item in range(1, M + 1):
  for i in lis:
    if not item in i[1:]:
      break
  else:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
K = [A[i][0] for i in range(N)]
for i in range(N):
    del A[i][0]
counter = [[] for i in range(N)]
counter[0] = A[0]

for i in range(1, N):
    for j in range(K[i]):
        if A[i][j] in counter[i-1]:
            counter[i].append(A[i][j])

print(len(counter[N-1]))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = []
for i in range(N):
    A.append(list(map(int, input().split()))[1:])

flags = [0 for _ in range(M)]
counter = 0
for i in range(M):
    i += 1
    for j in range(N):
        if not i in A[j]:
            flags[i-1] = 0
            break
        else:
            flags[i-1] = 1
    i += 1
print(flags.count(1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [''] * N
for i in range(N):
    A[i] = list(map(int, input().split()))
    
for i in range(len(A)):
    del A[i][0]

ans = 0
Alist = [flatten for inner in A for flatten in inner]
for i in set(Alist):
    if Alist.count(i) == N:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())

d = {}

for i in range(1, m + 1):
    d[i] = 0

for i in range(n):
    k, *a = map(int, input().split())

    for j in a:
        d[j] += 1

print(len(list(filter(lambda x: x == n, d.values()))))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
all_favourite = list(range(1,M+1))
for i in range(N):
  asking_people = list(map(int, input().split()))
  for j in range(M):
    if all_favourite[j] not in asking_people[1:]:
      all_favourite[j] = 0
count = 0
for k in range(M):
  if all_favourite[k] != 0:
    count += 1
    
print(count)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
all_like = list(range(1, m + 1))
for i in range(n):
    fav_list = list(map(int, input().split()))
    remove_list = []
    for j in all_like:
        if j not in fav_list[1:]:
            remove_list.append(j)
    for j in remove_list:
        all_like.remove(j)
print(len(all_like))

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
ninzu = [0]*M
kasetsu = False

A = []
for i in range(N):
    array = list(map(int,input().split()))
    del array[0]
    A.append(array)

for j in range(N):
    for cnt in A[j]:
        suki = int(cnt) - 1
        ninzu[suki] += 1

ans = ninzu.count(N)
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
pointlist = [0 for i in range(M + 1)]
for i in range(N):
    survey = [int(k) for k in input().split()]
    for j in range(survey[0]):
        pointlist[survey[j + 1]] += 1
print(pointlist.count(N))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
all_favorit = list(range(1,M+1))
for i in range(N):
    asking_people= list(map(int, input().split()))
    for j in range(M):
        if all_favorit[j] not in asking_people[1:]:
            all_favorit[j] = 0
count = 0
for i in range(M):
    if all_favorit[i]!= 0:
        count +=1

print(count)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ka = [map(int, input().split()) for _ in range(N)]

from collections import Counter
c = Counter()
for k, *a in ka:
    for b in a:
        c[b] += 1

print(sum(1 for n in c.values() if n == N))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys

def main():
	N, M = map(int, input().split(" "))
	ankete = []
	for _ in range(N):
		tmp = input().split(" ")
		tmp = [int(s) for s in tmp]
		ankete.append(tmp[1:])
	
	ans = {}
	for i, val in enumerate(ankete):
		for j in val:
			if j in ans:
				ans[j] += 1
			else:
				ans[j] = 1
	
	aaa = 0
	for i in ans.values():
		if i == N:
			aaa += 1
	print(aaa)
	
	
if __name__ == "__main__":
	main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
X = [N] * M
for i in range(N):
  tmp = list(map(int, input().split()))
  for j in range(tmp[0]):
    X[tmp[j+1]-1] -= 1

cnt = 0
for x in X:
  if x == 0:
    cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n, m = map(int, input().split())

array = [0 for i in range(m)]

for i in range(n):
    like = input().split()
    for j in range(1,len(like)):
        array[int(like[j])-1] += 1

print(array.count(n))

Submission status: Accepted

Solution code:
n, m= map(int,input().split())

le = [0]*n
for i in range(n):
    le[i] = list(map(int, input().split())) #ABCが数字の場合これで一発



p = []
for i in range(n):
    p+= le[i][1:]

cnt = 0

for i in range(1,m+1):
    if p.count(i)==n:
        cnt +=1


print(cnt)

Submission status: Accepted

Solution code:
n, m = list(map(int, input().split()))
ff_li = [0 for i in range(m)]
ans = 0
for i in range(n):
    ka = list(map(int, input().split()))
    for j in range(int(ka[0])):
        ff_li[ka[j+1] - 1] += 1
for i in ff_li:
    if i == n:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N,M = map(int, input().split())

m = [0]*M
ans = 0

for n in range(N):
    a = [int(i) for i in input().split()] 
    for i in a[1:]:
        #print('i',i)
        m[i-1] += 1
        if m[i-1] == N:
            ans +=1
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
K = []
for i in range(N):
    K.append(list(map(int, input().split())))

count1 = 0
for i in range(M+1):
    count2 = 0
    for j in range(N):
        if i in K[j][1:M+1]:
            count2 += 1
    if count2 == N:
        count1 += 1
print(count1)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
l=[list(map(int,input().split()))[1:] for i in range(n) ]
l=[a for b in l for a in b]
d = 0
for i in range(m+1):
    if l.count(i) == n:
        d += 1
print(d)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [[int(i) for i in input().split()] for i in range(N)]
l = [int(i)+1 for i in range(M)]
for a in A:
  l = list(set(l) & set(a[1:]))

print(len(l))

Submission status: Accepted

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