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())
arr = []
for _ in range(n):
    arr.append(list(map(int, input().split()[1:])))

ans = 0
tmp = 0
for i in range(31):
    for j in arr:
        if i in j:
            tmp += 1
        else:
            break
    if tmp == n:
        ans += 1
    tmp = 0

print(ans)

Submission status: Accepted

Solution code:
import collections
N,M = list(map(int,input().split()))
L=[]
def flatten(nested_list):
    return [e for inner_list in nested_list for e in inner_list]


for i in range(N):
  K = list(map(int,input().split()))
  K=K[1:]
  L.append(K)
# print(flatten(L))
cnter=collections.Counter(flatten(L))
print(len([i[0] for i in cnter.items() if i[1] >= N]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import numpy as np
N, M = list(map(int, input().split()))

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

cnt = {}
for i in range(1, M+1):
    cnt[i] = 0

for A_row in A:
    for a in A_row:
        cnt[a] += 1
ans = 0
for i in range(1, M+1):
    if N == cnt[i]:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

n_person, n_food = map(int, input().split(' '))

array = [1] * n_food

for i in range(n_person):
    li = list(map(int, input().split(' ')))
    li_sub = np.zeros(n_food)
    for j in li[1:]:
        li_sub[j-1] = 1
    array = array * li_sub

print(int(np.sum(array)))

Submission status: Accepted

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

lst = [list(map(int, input().split()))[1:] for _ in range(n)]

ans = 0
for i in range(1, m+1):
    val = True
    for l in lst:
        if i not in l:
            val = False
    if val:
        ans += 1
print(ans)

Submission status: Accepted

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

food = [0] * M

for i in range(0,N):
    Ks =  list(map(int, input().split()))
    K = Ks[0]
    for j in range(1,K+1):
        food[Ks[j]-1] += 1

cnt=0
for i in range(0,M):
    if food[i] == N:
        cnt+=1

print(cnt)

Submission status: Accepted

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

ans = set([x for x in range(1,M+1)])

for i in range(N):
    l = [int(x) for x in input().split()]
    l.pop(0)
    l = set(l)

    ans = ans & l

print(len(ans))

Submission status: Accepted

Solution code:
import numpy as np
N, M = map(int, input().split())

num_class = []
foodlist = np.zeros(M)

for n in range(N):
    tmplist = list(map(int, input().split()))
    num_class.append(tmplist[0])
    for i in range(tmplist[0]):
        foodlist[tmplist[i+1]-1] += 1

count = 0
for m in range(M):
    if foodlist[m] == N:
        count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
import numpy as np
N, M = (int(i) for i in input().split())

A=[]
for i in range(N):
    A_tmp = np.array([int(i) for i in input().split()[1:]])
    A.extend(A_tmp)

c = Counter(A)
values, counts = zip(*c.most_common())
print(np.sum(np.array(counts)==N))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
Likes = [N for _ in range(M)] 
for _ in range(N): 
    temp = [int(i) for i in input().split()]    
    for k in range(1,len(temp)):
        Likes[temp[k]-1] -= 1
print(Likes.count(0))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

sum = 0
for i in range(m):
    if(s[i]==n):
        sum += 1

print(sum)

Submission status: Accepted

Solution code:
import collections
def main():
	n, m = map(int, input().split())
	count = collections.defaultdict(int)
	for _ in range(n):
		nums = list(map(int, input().split()))
		for i in range(nums[0]):
			count[nums[i+1]] += 1
	ans = 0
	for v in count.values():
		if v == n:
			ans += 1

	print(ans)

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
# coding: utf-8
N, M = list(map(int, input().split()))
l = [0 for _ in range(M)]
for _ in range(N):
    s = list(map(int, input().split()))
    for i in s[1:]:
        l[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(' '))
food = set(range(1, m+1))
for i in range(n):
    li = [int(x) for x in input().split(" ")]
    ki = li[0]
    ai = li[1:]
    food = food.intersection(ai)
print(len(food))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
M=[0]*m
for nn in range(n):
  s=input().split()
  for i in range(int(s[0])):
    M[int(s[i+1])-1]+=1
a=0
for mm in range(m):
  if M[mm]==n:
    a+=1
print(a)

Submission status: Accepted

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

res = A[0]
for i in range(1,N):
    res = res & A[i]

print(len(res))

Submission status: Accepted

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

N, M = map(int, input().split())
cnt = [0]*(M+1)

for i in range(N):
    l = [int(i) for i in input().split()]
    for a in l[1:]:
        cnt[a] += 1
res = sum([1 for c in cnt if c == N])
print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, M = list(map(int, input().split()))

s = set(range(1, M+1))
for i in range(N):
    t = set(list(map(int, input().split()))[1:])
    s = s.intersection(t)

print(len(s))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
suki_list = list(map(int, input().split()))
suki_list = suki_list[1:]
suki_set = set(suki_list)
for i in range(N-1):
    suki_list = list(map(int, input().split()))
    suki_list = suki_list[1:]
    remove_list = []
    for num in suki_set:
        if num not in suki_list:
            remove_list.append(num)
    for i in remove_list:
        suki_set.remove(i)

print(len(suki_set))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
foods = [n for food_syurui in range(m+1)]
for i in range(n):
	question = list(map(int, input().split()))
	for syurui in question[1:]:
		foods[syurui] -= 1
print(foods.count(0))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [[0] * M for _ in range(N)]
for i in range(N):
    A[i] = [int(x) for x in input().split()[1:]]
food = [0] * M
for x in A:
    for f in x:
        food[f-1] += 1
ans = 0
for f in food:
    if f == N:
        ans += 1
print(ans)

Submission status: Accepted

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

allset = set()
for i in range(n):
    l_raw = input().split()
    l_new = l_raw[1:]
    if i != 0:
        allset = allset & set(l_new)
    else:
        allset = set(l_new)


print(len(allset))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
Fav = [list(map(int,input().split()))[1:] for i in range(N)]
Sum = 0
for i in range(M):
    Flag = True
    for j in range(N):
        if not i+1 in Fav[j]:
            Flag = False
    if Flag:
        Sum += 1
print(Sum)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
love = set(range(1, m + 1))
for _ in range(n):
    k, *aaa = map(int, input().split())
    love.intersection_update(aaa)
print(len(love))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
series=[[] for N in range(N)]
for n in range(N):
	series[n]=list(map(int,input().split()))
ans = 0
for m in range(1,M+1):
	for n in range(N):
		if m not in series[n][1:]:
			break
	else:
		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())))
    

A = [0 for _ in [0]*M]

for i in range(N):
    for j in range(K[i][0]):
        A[K[i][j+1]-1] += 1
        
print(A.count(N))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
# A[y][x]: y行目、x文字目
A = [list(map(int, input().split())) for _ in range(N)]

m = {}

for row in A:
    cnt = 0
    for num in row:
        cnt += 1
        if cnt == 1:
            continue
        m.setdefault(num, 0)
        m[num] += 1

cnt = 0
for num in m.values():
    if num == N:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
A = []
for i in range(N):
    A.append(list(map(int, input().split()))[1:])
ans = 0
for a in A[0]:
    flag = True
    for i in range(1, N):
        if not a in A[i]:
            flag = False
            break
    if flag==True:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

n, m = map(int, input().split())
lst = [list(map(int, input().split()))[1:] for _ in range(n)]

array = np.zeros([n,m])
for k1, i in enumerate(lst):
    for k2, j in enumerate(i):
        array[k1][j-1] += 1

print(sum(array.sum(axis=0)==n))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
likes = [[int(i) for i in input().split()] for _ in range(N)]
seki = {}
for i in range(N):
    if seki == {}:
        seki = {likes[i][j] for j in range(1, likes[i][0]+1)}

    tag={likes[i][j] for j in range(1, likes[i][0]+1)}
    seki= seki & tag

print(len(seki))

Submission status: Accepted

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

d = defaultdict(int)
n, m = map(int, input().split())
for i in range(n):
    a = list(map(int, input().split()))
    count = 0
    for j in a:
        if count == 0:
            count += 1
            continue
        d[j] += 1
count = 0
for i in d:
    if (d[i] == n):
        count += 1

print(count)

Submission status: Accepted

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

l = []
m = []
for j in range(n):
    k,*a = [int(i) for i in input().split()]
    l.append(a)
    m.append(k)

count = 0
for i in l[0]:
    flag = 0
    for j in range(len(l)):
        if i not in l[j]:
            flag = 1

    if flag == 0:
        count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def main():
    n, m = map(int,input().split())

    lst = [0 for i in range(n)]
    for i in range(n):
        lst[i] = list(map(int,input().split()))[1:]


    tmp = [i for i in range(1,m+1)]
    for i in lst:
        tmp = set(tmp) & set(i)

    print(len(tmp))


if __name__ == "__main__":
        main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3

N, M = [int(x) for x in input().strip().split()]

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

Submission status: Accepted

Solution code:
a,b=list(map(int,input().split()))
L=[]
for i in range(a):
    L.append(list(map(int,input().split())))

l={i for i in range(1,b+1)}    
for i in range(a):
    l=l&set(L[i][1:])
print(len(l))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 16 19:31:10 2019
ABC118B
@author: maezawa
"""

n, m = list(map(int, input().split()))
a0 = list(map(int, input().split()))
k = a0.pop(0)
common = set(a0)
for i in range(1, n):
    ai = list(map(int, input().split()))
    k = ai.pop(0)
    common = common & set(ai)
    
print(len(common))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
K=[]
for _ in range(n):
    A=list(map(int,input().split()))
    A.pop(0)
    K.append(A)
ans=0
for i in range(1,31):
    flag=True
    for j in range(n):
        if i not in K[j]:
            flag=False
    if flag:
        ans+=1
print(ans)

Submission status: Accepted

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

result = set([t for t in range(1,M+1)])
#print(result)

for n in range(N):
    A = list(map(int, input().split()))
    A.pop(0)
    result &= set(A)
    #print(result)

print(len(result))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n,m = map(int, input().split())
a=[0]*(m+1)
for i in range(0,n):
  ka=list(map(int, input().split()))
  for j in range(1,len(ka)):
    a[ka[j]]=a[ka[j]]+1
r=0
for i in range(0,m+1):
  if a[i]==n:
    r=r+1
print(r)

Submission status: Accepted

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

l = []

for i in range(N):
    A = [int(x) for x in input().split()]

    for j in range(1, A[0] + 1):
        l.append(A[j])

ans = 0

for i in range(M + 1):
    if l.count(i) == N:
        ans += 1

print(ans)

Submission status: Accepted

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

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

    ans = 0
    for y in x:
        if sum(y) == N:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
dic = {}
dic[0] = 1
N, M = map(int, input().split())
for i in range(N):
  for j, a in enumerate(list(map(int, input().split()))):
    if j == 0:
      continue
    if dic.get(a):
      dic[a] += 1
    else:
      dic[a] = 1
cnt = 0
for i in dic.keys():
  if i == 0:
    continue
  if dic[i] == N:
    cnt += 1
print(cnt)

Submission status: Accepted

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

cnt = 0
for i in range(m):
    flag = True
    for a in A:
        if i + 1 not in a:
            flag = False
    if flag:
        cnt += 1

print(cnt)

Submission status: Accepted

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

dict = {}
for n in range(N):
    k_a = [int(_) for _ in input().split()]
    for k in range(k_a[0]):
        if k_a[k+1] in dict:
            dict[k_a[k+1]] += 1
        else:
            dict[k_a[k+1]] = 1

count = 0
for key in dict:
    if dict[key] == N:
        count += 1

print(count)

Submission status: Accepted

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

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

ans_list=[i+1 for i in range(M)]

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

print(len(ans_list))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = [int(x) for x in input().split()]
cnt_list = [0] * m
for idx in range(n):
  for k in [int(x) for x in input().split()][1:]:
    cnt_list[k-1] += 1
print(sum([1 if x==n else 0 for x in cnt_list]))

Submission status: Accepted

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

l = []
for _ in range(M):
    l += [0]
aa=[]
for i in range(N):
    aa.append([int(i) for i in input().split()])
    aa[i].pop(0)

for line in aa:
    for i in line:
        l[i - 1] += 1

ans = 0
for index, s in enumerate(l):
    if s == N:
        ans += 1

print(ans)

Submission status: Accepted

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

food_list = [list(map(int, input().rstrip().split())) for _ in range(n)]
answer = [0]*m

for food in food_list:
    food.pop(0)
    for tmp in food:
        answer[tmp-1] += 1

print(answer.count(n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
  N, M = map(int, input().split())
  l = [int(i) for i in input().split()]
  l.pop(0)
  s = set(l)
  for i in range(N - 1):
    l = [int(i) for i in input().split()]
    l.pop(0)
    s = s & set(l)
  return len(s)

print(solve())

Submission status: Accepted

Solution code:
import numpy as np

(N,M) = map(int,input().split())
B = np.ones(M,dtype=np.int)

for _ in range(N):
    A = np.array(list(map(int,input().split())))[1:]
    for i in range(M):
        if not i+1 in A:
            B[i] = 0
print(B.sum())

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
s=set([i for i in range(0,M+1)])
for i in range(N):
  l=list(map(int,input().split()))
  l.pop(0)
  s1=set(l)
  s=s&s1
print(len(s))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = [list(map(int,input().split())) for i in range(n)]
li = set(a[0][1:])
for x in a:
    li = li & set(x[1:])
b = list(set(li))
print(len(b))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
aa = []
kk=[]
for i in range(n):
    tmp = list(map(int,input().split()))
    kk.append(tmp[0])
    aa.append(tmp[1:])

aaa = []
for a in aa:
    for ai in a:
        aaa.append(ai)
ans=0
for i in range(m):
    if aaa.count(i+1)==n:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
N,M = [int(_) for _ in input().split()]
K = []
c = 0
for i in range(1,N+1):
    I = [int(_) for _ in input().split()]
    K = K + I[1:]
for j in range(1,M+1):
    if K.count(j)==N:
        c +=1
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

l = []
for i in KA:
    l.append(i[1:])
    
ans = set(l[0])

for i in range(N):
    ans = ans & set(l[i])

print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
people, foods = map(int, input().split(' '))
buckets = [0] * (foods + 1)
for i in range(people):
  a = list(map(lambda x: int(x), input().split(' ')))
  favorite_foods = a.pop(0)
  for food_num in a:
    buckets[food_num] += 1

count = 0
for food in buckets:
  if food == people:
    count += 1

print (count)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n,m = input().split()
n = int(n)
m = int(m)
list = [[] for i in range(n)]
for i in range(n):
    list[i] = input().split()
    for j in range(int(list[i][0])):
        list[i][j] = int(list[i][j+1])
ans = 0
for i in range(m):
    flag = 1
    for j in range(n):
        if i+1 not in list[j]:
            flag = 0
    if flag == 1:
        ans += 1
print(ans)

Submission status: Accepted

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

inputs = [[i for i in input().split()] for _ in range(N)]

ans = set(inputs[0])
for item in range(N):
    ans = ans & set(inputs[item][1:])

print(len(ans))

Submission status: Accepted

Solution code:
import collections


def main():
    n, m = (int(z) for z in input().split())
    ctr = collections.Counter()
    for _ in range(n):
        xs = [int(z) for z in input().split()][1:]
        ctr.update(xs)
    print(sum(v == n for k, v in ctr.items()))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=[0]*m
for i in range(n):
    L=[int(i) for i in input().split()]
    del L[0]
    for i in range(len(L)):
        l[L[i]-1]+=1
ans=0
for i in range(m):
    if l[i]==n:ans+=1
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
K = {}
like = [0] * M
for i in range(1, N + 1):
    inp = list(map(int, input().split()))
    for j in inp[1:]:
        like[j - 1] += 1
ans = 0
for i in like:
    if i == N:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    food_list = [set(map(int, input().split()[1:])) for _ in range(N)]

    ans = food_list[0]
    for idx in range(len(food_list) - 1):
        ans = ans & food_list[idx + 1]
    print(len(ans))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
like = []
for i in range(n):
    k = list(map(int, input().split()))
    like.extend(k[1:])
ans = 0
for i in range(m):
    if like.count(i+1) == n:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n,m = [int(i) for i in input().split()]
like = {i:True for i in range(1,m+1)}
for i in range(n):
  a = [int(i) for i in input().split()[1:]]
  s = list(like.keys())
  for i in s:
    if i not in a:
      like.pop(i)

print(len(like.keys()))

Submission status: Accepted

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

L = [ list(map(int, input().split())) for i in range(N)]
ans = 0
res = [0 for i in range(M)]

for l in L:
    for i in range(len(l)):
        if i != 0:
            res[l[i]-1] += 1
        
for i in range(M):
    if res[i] == N:
        ans += 1
        
print(ans)

Submission status: Accepted

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

for i in range(N):
  s = set(list_n[i][1:])
  if i == 0:
    s_inter = s
  else:
    s_inter = s_inter & s

print(len(s_inter))

Submission status: Accepted

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


count = m*[0]
for i in a:
    tmp = 0
    for j in range(m):
        if(i[j] == 1): count[j] += 1


ans = 0
for i in count:
    if(i == n): ans += 1

print(ans)

Submission status: Accepted

Solution code:
N , M = map(int,input().split())
L = []
for _ in range(N):
    l = list(map(int,input().split()))
    tmp =l.pop(0)
    L.append(l)
cnt = 0
for i in range(1,1+M):
    for x in L:
        if i in x:
            pass
        else:
            break
    else:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
# B Foods Loved by Everyone

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

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

Submission status: Accepted

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

typ = set(range(1, M+1))

for i in range(N):
    A = map(int, raw_input().split())[1:]
    typ = typ & set(A)

print len(typ)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
lst = input().split()
s1 = set(lst[1:])
for _ in range(N - 1):
    lst = input().split()
    s2 = set(lst[1:])
    s1 = s1 & s2
    
print(len(s1))

Submission status: Accepted

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

c = []
for i in b:
    for j in i:
        c.append(j)
cco = 0

for k in b[0]:
    if c.count(k) == a[0]:
        cco = cco + 1

print(cco)

Submission status: Accepted

Solution code:
#coding:utf-8
N, M = map(int,input().split())
for n in range(N):
    L = list(map(int,input().split())) 
    if n == 0:
        s = set(L[1:])
    else:
        s = s&set(L[1:])
print (len(s))

Submission status: Accepted

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

m_lis= [0 for i in range(M+1)]
for i in range(N):
    for j in range(a[i][0]):
        m_lis[a[i][j+1]]+=1
        
        

count=0
for i in range(M+1):
    if m_lis[i]==N:
        count+=1
        
print(count)

Submission status: Accepted

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

for i in range(1,M+1):
    isLike = True
    for j in k:
        if not i in j[1:]:
            isLike = False
    if isLike:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:

n, k = map(int, input().split())
t = [[int(x) for x in input().split()] for _ in range(n)]
#print(t)
n = 0
for i in range(k+1):
    #1 ~ k
    flag = True
    for j in t:
        if i not in j[1:]:
            flag = False
    if flag == True:
        n += 1
print(n)

Submission status: Accepted

Solution code:
n, m = input().split()
fav_foods = {}
for i in range(0, int(n)):
    foods = input().split()
    for food in foods[1:]:
        if not food in fav_foods:
            fav_foods[food] = 1
        else:
            fav_foods[food] += 1

res = 0
for food in fav_foods.keys():
    if fav_foods[food] == int(n):
        res += 1
print(res)

Submission status: Accepted

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

likes = [0 for x in range(M)]

for n in range(N):
    s = [int(x) for x in input().split()]
    K = s[0]
    for k in range(K):
        likes[s[1+k] - 1] += 1

print(likes.count(N))

Submission status: Accepted

Solution code:
import collections
N,M = map(int,input().split())
listed = []
ans = 0
for i in range(N):
    listed.extend(list(map(int,input().split()))[1:])
a = collections.Counter(listed)
for num,count in a.items():
    if count == N:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
N, M = [int(n) for n in input().split()]
K = []
A = []
for i in range(N):
    L = [int(n) for n in input().split()]
    K.append(L[0])
    A.append(L[1:])

counter = [0] * M

for i in range(N):
    L = A[i]
    for l in L:
        counter[l - 1] += 1

indices = [i for i, c in enumerate(counter) if c == N]

print(len(indices))

Submission status: Accepted

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

lv = []
for i in range(N):
    a = [int(i) for i in input().split()] 
    lv.append(set(a[1:]))

res = lv[0]
for i in lv:
    res = res & i

print(len(res))

Submission status: Accepted

Solution code:
n, m = [int(i) for i in input().split()]
ans = set(i for i in range(1, m+1))

for i in range(n):
    k, *S = [int(i) for i in input().split()]
    ans &= set(S)

print(len(ans))

Submission status: Accepted

Solution code:
def main():
    n, m = [int(x) for x in input().rstrip("\n").split(" ")]

    from collections import defaultdict
    favorites = defaultdict(int)

    for i in range(n):
        k , *foods = [int(x) for x in input().rstrip("\n").split(" ")]
        for food in foods:
            favorites[food] += 1

    count = 0
    for food in range(1, m+1):
        if favorites[food] == n:
            count += 1
    print(count)

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M] = [int(input_raw[0]), int(input_raw[1])]
    dic = {}
    for m in range(1, M + 1):
        dic[m] = 0

    for i in range(N):
        input_raw = read_func().strip().split()
        K = int(input_raw[0])
        for j in range(K):
            dic[int(input_raw[j + 1])] += 1

    count = 0
    for m in dic:
        if dic[m] == N:
            count += 1
    print count


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
all_like = set([i for i in range(1, M + 1)])

for i in range(N):
    A = set(list(map(int, input().split()))[1:])
    all_like = all_like.intersection(A)

print(len(all_like))

Submission status: Accepted

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

cnt = [0]*m
for i in range(n):
    l = list(map(int,input().split()))
    l = l[1:]
    for k in l:
        cnt[k-1] += 1
print(len([item for item in cnt if item>=n]))

Submission status: Accepted

Solution code:
def main():
    # N=int(input())
    N,M = list(map(int,input().split()))
    ary = [[0 for _ in range(M)] for _ in range(N)]
    for i in range(N):
        a = list(map(int,input().split()))
        for j,elem in enumerate(a):
            if j == 0:
                continue
            ary[i][elem-1] = 1
    cnt = 0
    for j in range(M):
        ok = True
        for i in range(N):
            ok = ok and (ary[i][j]==1)
        if ok:
            cnt += 1
    print(cnt)
    return 0

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
favorite_foods = []
for i in range(N):
    favorite_foods.extend(list(map(int, input().split()))[1:])
count = 0
for i in range(1, M + 1):
    if favorite_foods.count(i) == N:
        count += 1
print(count)