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())
f=[]
for i in range(n):
    y=input().split()
    for g in range(len(y)):
        y[g]=int(y[g])
    f.append(y)
    f[i].remove(f[i][0])
for j in range(n):
    f[j]=set(f[j])
for k in range(n):
    if k==0:
        x=f[k]
    else:
        x=x&f[k]
print(len(x))

Submission status: Accepted

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

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

Submission status: Accepted

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

in_list = []
for i in range(N):
    in_list.append(list(map(int, input().split())))

k_list = []
for i in range(N):
    num = in_list[i][0]
    k_list = k_list + in_list[i][1: num + 1]

count = 0
for i in range(1, M + 1):
    if k_list.count(i) == N:
        count += 1
    else:
        pass

print(count)

Submission status: Accepted

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

for i in range(N):
	for A in map(int, input().split()[1:]):
		cnt[A - 1] += 1

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

print(ans)

Submission status: Accepted

Solution code:
import itertools

N, M = map(int, input().split())
K_A = []
A = []
X = []
ans = 0

for _ in range(N):
    K_A.append(list(map(str, input().split())))

for _ in range(N):
    A.append(K_A[_][1:])

A = list(itertools.chain.from_iterable(A))

for m in range(1, M+1):
    count = A.count(str(m))
    if count == N:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n,m=map(int, input().split())
# 好きな種類の全食べ物の番号を含む配列Sを作成する
S=set(range(1, m+1))
# Forループを作成する
for i in range(n):
    # Kと、Aをアンパックしながら配列へ入力する
    K,*A=map(int,input().split())
    # Aリストの中から重複を取り除き、SとのANDをとる　
    S&=set(A)
# 最終的の残ったリスト2つどうしでANDをとる
print(len(S))

Submission status: Accepted

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

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

total = 0

for i in range(1,len(A[0])):
	con = 1
	for j in range(1,N):
		a = A[0][i]

		if a in A[j][1:]:
			con *= 1
		else:
			con *= 0
	total += con
	
if N != 1:
	print(total)
else:print(A[0][0])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
k = [list(map(int, input().split())) for i in range(n)]
food_list = [0] * m
for i in range(n):
    for j in range(len(food_list)):
        if j+1 in k[i][1:]:
            food_list[j] += 1
        else:
            continue
cnt = 0
for i in range(len(food_list)):
    if food_list[i] == n:
        cnt += 1
    else:
        continue
print(cnt)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
bins = (m + 1) * [0]
for i in range(n):
    inputs = list(map(int, input().split()))
    for j in range(1, len(inputs)):
        bins[inputs[j]] += 1

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

Submission status: Accepted

Solution code:
from sys import stdin, exit
from math import factorial
input = stdin.readline
lmi = lambda: list(map(int, input().split()))
mi = lambda: map(int, input().split())
si = lambda: input().strip('\n')
ssi = lambda: input().strip('\n').split()

n, m = mi()
foods = [0 for i in range(m+1)]
for i in range(n):
    arr = lmi()
    for j in arr[1:]:
        foods[j] += 1
cnt= 0
for i in range(1, m+1):
    if foods[i] == n:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
freq = [0 for i in range(m+1)]
counter = 0
for i in range(n):
    foods = list(map(int, input().split()))
    foods = foods[1:]
    for j in foods:
        freq[j] += 1
for i in range(1,m+1):
    if freq[i] == n:
        counter += 1
print(counter)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
k=[list(map(int,input().split())) for i in range(n)]
k.sort(key=lambda x: x[0])
cnt=0
#print(k[0][1:])
for i in k[0][1:]:
    #print(i)
    c=0
    for j in range(n):
        if i in k[j][1:]:
            c+=1
    #print(c)
    if c==n:
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
# ABC118B - Foods Loved by Everyone
from collections import defaultdict


def main():
    N, M = map(int, input().split())
    cnt = defaultdict(int)
    for _ in range(N):
        _, *A = map(int, input().split())
        for a in A:
            cnt[a] += 1
    ans = sum(i == N for i in cnt.values())
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np

N,M = map(int,stdin.readline().strip().split())

A = np.zeros((N,M))

for i in range(N):
    inp = list(map(int,stdin.readline().strip().split()))
    for j in range(inp[0]):
        A[i,inp[j+1]-1] = 1

B = np.sum(A,axis=0)
print(np.count_nonzero(B==N))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
K = []
A = []
for _ in range(n):
  k, *a = map(int, input().split())
  K.append(k)
  A.append(a)
C = 0
for a in A[0]:
  c = 0
  for i in range(1,n):
    if A[i].count(a):
      c += 1  
  if c==n-1:
    C += 1  
print(C)

Submission status: Accepted

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

ans = {i+1 for i in range(m)}
for a in A:
    ans = ans & set(a[1:])

print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N , M = map(int,input().split())
food_list = np.zeros(M)
for i in range(N):
    work = list(map(int,input().split()))
    work.pop(0)
    for idx in work:
        food_list[idx - 1] += 1
cnt = 0
for food in food_list:
    if food == N:
        cnt += 1
print(cnt)

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())
k_list = []
a_list = []
for _ in range(n):
    k, *a = map(int, input().split())
    k_list.append(k)
    a_list.append(a)
    
ans = [0]*m
for i in range(m):
    for j in range(len(k_list)):
        if i+1 in a_list[j]:
            ans[i] += 1
if max(ans) == n:
    print(ans.count(n))
else:
    print(0)

Submission status: Accepted

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

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

for i in range(m):
    if s.count(i+1)==n:
        c+=1
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[]
ans=0
for i in range(n):
    ii=0
    for j in map(int,input().split()):
        if ii > 0:
        	a.append(j)
        ii+=1
#print(a)
 
for k in range(1,m+1):
    if a.count(k) == 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 _ in range(N)]
cnt = {}
for i in A:
    for j in i[1:]:
        if j in cnt:
            cnt[j] += 1
        else:
            cnt[j] = 1
ans = len([k for k in cnt if cnt[k] == N])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = (int(x) for x in input().split())
c = [0 for _ in range(m)]
for _ in range(n):
    r = [int(x) for x in input().split()]
    for i in r[1:]:
        c[i-1] += 1
print(c.count(n)) if n in c else print(0)

Submission status: Accepted

Solution code:
import itertools

N, M = map(int, input().split())
K = []
A = []
for _ in range(N):
    k, *a = map(int, input().split())
    K.append(k)
    A.append(a)

A = [x-1 for x in list(itertools.chain.from_iterable(A))]

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

print(ans)

Submission status: Accepted

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

A = []
for i in range(N):
    for j in range(1,K[i][0] + 1):
        temp = K[i][j]
        A.append(temp)
ans = 0
for i in range(1,31): 
    if A.count(i) == N:
        ans +=1
    if N == 1:
        ans = K[0][0]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
_,*a=map(int,input().split())
a=set(a)
for i in range(n-1):
  _,*b=map(int,input().split())
  b=set(b)
  a=a.intersection(b)
print(len(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    ls = []
    for i in range(n):
        ka = list(map(int, input().rstrip('\n').split()))
        for j in range(1, ka[0] + 1):
            ls.append(ka[j])
    ls = collections.Counter(ls)
    cnt = 0
    for k, v in ls.items():
        if v == n:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

food = [0] * M
ans = 0

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

for i in range(M):
    if food[i] == N:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
L=[0]*M
for i in range(N) :
   X = [n for n in map(int,input().split())]
   for a in range(len(X)-1):
       L[X[a+1]-1] += 1
print(L.count(N))

Submission status: Accepted

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

for i in range(N):
    for j in range(1, KA[i][0]+1):
        cnt[KA[i][j]-1]+=1

ans = 0

for i in range(M):
    if cnt[i] == N:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
k=dict.fromkeys(range(1,31),0)
count=0
for i in range(N):
    x=list( map( int,input().split() ) )[1:]

    for j in x:

        k[j]+=1


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

        
    
        
print(count)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
likes = [0 for _ in range(M)]
for _ in range(N):
  for food in list(map(int,input().split()))[1:]:
    likes[food-1] += 1
ans = 0
for like in likes:
  if like == N:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=[]
c=0
mm=list(range(1,m+1))
for i in range(n):
    ll=list(map(int,input().split()))
    l.append(ll)
    del l[i][0]
for i in range(m):
    t=True
    for j in range(n):
        if mm[i] not in l[j]:
            t=False
    if t:
        c+=1
print(c)

Submission status: Accepted

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

ancket = []
list_like = []
menu = {}

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

for i in range(n):
  ancket = list(map(int, input().split()))
  k = ancket[0]
  list_like = ancket[1:k+1]
  for j in range(k):
      menu[list_like[j]] += 1
      
sum = 0
for i in range(m):
  if menu[i+1] == n:
    sum += 1

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

P=0
for i in range(M+1):
    if F.count(i)==N:
        P+=1

print(P)

Submission status: Accepted

Solution code:
import sys
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
# from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

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

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

if __name__ == '__main__':
    main()

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())
_,*ans=map(int,input().split())
for i in range(n-1):
    _,*k=map(int,input().split())
    ans=[i for i in k if i in ans]
print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#2019/09/30
std_input = open(0).readlines()
N, M = map(int, std_input[0].split())
#print(N, M)
A = [list(map(int, i.rstrip("\n").split())) for i in std_input[1:1+N]]
#print(A)
intersection = [i+1 for i in range(M)]
#print(intersection)
for i in A:
    intersection = set(intersection) & set(i[1:])
print(len(intersection))

Submission status: Accepted

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

for a in buf:
  if a == n:
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
M_dict = {i:0 for i in range(1, M+1)}
for _ in range(N):
    K, *A_list = map(int, input().split())
    for k in range(K):
        M_dict[A_list[k]] += 1

ans = 0
for j in range(1, M+1):
    if M_dict[j] == N:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n,m=[int(s) for s in input().split()]
ls=[0 for _ in range(m+1)]
for i in range(n):
  ls2=[int(s) for s in input().split()]
  for j in range(ls2[0]):
    ls[ls2[j+1]]+=1
x=0
for i in range(m+1):
  if ls[i]==n:
    x+=1
print(x)

Submission status: Accepted

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

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

Submission status: Accepted

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

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:
from collections import deque
import sys

n,m=map(int,input().split())

all_like=deque(list(map(int,input().split())))
all_like.popleft()

for _ in range(n-1):
    like=deque(list(map(int,input().split())))
    k=like.popleft()
    for _ in range(len(all_like)):
        eq=0
        al=all_like[0]
        for i in range(k):
            if al==like[i]:
                eq=1
                
        if eq==1:       
            all_like.append(all_like.popleft())
        else:
            all_like.popleft()
            if len(all_like)==0:
                print(0)
                sys.exit()
                
print(len(all_like))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
K = [list(map(int,input().split()))[1:] for _ in range(N)]
t = 0
for i in range(1,M+1):
    s = 0
    for l in K:
        if i in l:
            s += 1
    if s == N:
        t += 1
print(t)

Submission status: Accepted

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

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

for i in range(N):
    for j in range(a[i][0] + 1):
        if j == 0: continue
        c[a[i][j]] += 1

ans = 0
for i in range(len(c)):
    if c[i] == N:
        ans += 1

print(ans)

Submission status: Accepted

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

if n == 1:
    print(ka[0][0])
    exit()

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
cnt = 0
like = []
frag = 1
for i in range(n):
  s = list(map(int, input().split()))
  like.append(s[1:])
for i in range(m):
  for j in range(n):
    if(not(i+1 in like[j])):
      frag = 0
      break
  if(frag == 1):
    cnt += 1
  frag = 1
print(cnt)

Submission status: Accepted

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

L = []
for i in range(n):
      L2 = list(map(int,input().split()))
      L += L2[1:]

ans = 0
for i in range(1,m+1):
      if L.count(i) == n:
            ans += 1

print(ans)

Submission status: Accepted

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

n, m = map(int, raw_input().split())

like = [0] * m
for i in range(n):
    inpt = map(int, raw_input().split())
    for j in range(inpt[0]):
        like[inpt[j+1] - 1] += 1

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

print ans

Submission status: Accepted

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

like = {}

for i in range(n):
  ancket = list(map(int,input().split()))
  for j in range(1, ancket[0]+1):
    if ancket[j] in like:
      like[ancket[j]] += 1
    else:
      like[ancket[j]] =1
sum = 0
#print(like)
for i in range(0,m):
  if (i + 1) in like:
    if like[(i+1)] == n:
      sum += 1
  
print(sum)

Submission status: Accepted

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

everyone_loves = set(i for i in range(1, M+1))
for like in likes:
    everyone_loves = everyone_loves & set(like[1:])

print(len(everyone_loves))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
arr=[0]*M
for _ in range(N):
    l=list(map(int,input().split()))
    for i in range(l[0]):
        arr[l[i+1]-1]+=1
print(sum(map(lambda x: x==N, arr)))

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
  k=[int(x) for x in input().split()]
  for i in range(1,k[0]+1):
    l[k[i]-1] += 1

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

print(c)

Submission status: Accepted

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

a = []
for _ in range(n):
    _, *fav = map(int, input().split())
    a.append(set(fav))

common_fav = a[0]
for i in range(1, n):
    common_fav = common_fav & a[i]
print(len(common_fav))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())	
ka = sorted([list(map(int, input().split())) for _ in range(n)])
cnt={}
for i in range(n):
    for j in range(ka[i][0]):
        if ka[i][j+1] not in cnt:
            cnt[ka[i][j+1]]=1
        else:
            cnt[ka[i][j+1]]+=1
ans=0
for c in cnt:
    if cnt[c]==n:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[]
total=0
for i in range(n):
    k=list(input().split())
    ''.join(k)
    a.extend(k[1:len(k)])
for i in range(1,m+1):
    if a.count(str(i))==n:
        total+=1
print(total)

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
foods = [0 for m in range(M)]
for n in range(N):
    A = list(map(int, input().split()))
    for a in A[1:]:
        foods[a-1]+=1
print(len([f for f in foods if f == N]))

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
foods = [0 for m in range(M)]
for n in range(N):
    A = list(map(int, input().split()))
    for a in A[1:]:
        foods[a-1]+=1
foods_ans = [f for f in foods if f == N]
#print(foods)
#print(foods_ans)
print(len(foods_ans))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
src_all = [input().split() for _ in range(n)]
# src = [['2', '1', '3'], ['3', '1', '2', '3'], ['2', '3', '2']]
tmp = {}
for src in src_all:
    for i,s in enumerate(src):
        if i != 0:
            if s in tmp:
                tmp[s] += 1
            else:
                tmp[s] = 1
count = 0
for t in tmp.values():
    if t == n:
        count +=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
favorite = []
output = 0

for i in range(N):
    favorite.append(list(map(int, input().split())))

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

for k in favorite:
    for l in test.keys():
        if l in k[1::]:
            test[l] += 1

        if test[l] == N:
            output += 1

print(output)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ans = list(range(1, m+1))
for i in range(n):
  a = list(map(int, input().split()))
  a.pop(0)
  ans = list(filter(lambda x: x in a, ans))
print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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


print(sum([1 for k in pref if k == n]))

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())
    a = set(a)
    s &= a
print(len(s))

Submission status: Accepted

Solution code:
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(sum([1 for k in l if k == n]))

Submission status: Accepted

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

Submission status: Accepted

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

all_list = [i for i in range(1, M+1)]
res_set = set()

for i in range(len(KA)):
    diff_set = set(all_list) ^ set(KA[i][1:])
    res_set = res_set | diff_set

print(M - len(res_set))

Submission status: Accepted

Solution code:
N, M=map(int, input().split())
a=[0]*(M+1)

for i in range(N):
  temp=list(map(int, input().split()))
  k=len(temp)
  for j in range(1, k):
    a[temp[j]]+=1
    
counter=0
for i in range(1, M+1):
  if a[i]==N:
    counter+=1
    
print(counter)

Submission status: Accepted

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

res = set(KA[0][1:])
for a in KA[1:]:
    res = res & set(a[1:])
print(len(res))

Submission status: Accepted

Solution code:
# ABC118b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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

Submission status: Accepted

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

dict = {}
for i in range(N):
    for j in range(1,len(K[i])):
        if K[i][j] in dict:
            dict[K[i][j]] += 1
        else:
            dict[K[i][j]] = 1

cnt = 0
for v in dict.values():
    if v == N:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import collections

n, m = map(int, input().split())

res_list = []

for _ in range(n):
  temp_list = list(map(int, input().split()))
  for i in range(1, temp_list[0]+1):
    res_list.append(temp_list[i])


print(list(collections.Counter(res_list).values()).count(n))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.pop(0)
A = set(A)
for i in range(N-1):
    B = list(map(int,input().split()))
    B.pop(0)
    B = set(B)
    A = A.intersection(B)
print(len(A))

Submission status: Accepted

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

Submission status: Accepted

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

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

count=0
for k in range(1,M+1):
    if b.count(k) == N:
        count +=1
        
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
List=[]
for i in range(N):
  List.append(list(map(int,input().split())))
List_K=[]
List_A=[]
for j in range(N):
  List_K.append(List[j][0])
  List_A.append(List[j][1:])
count=0
for k in range(M+1):
  count1=0
  for l in range(N):
    if k in List_A[l]:
      count1+=1
  if count1==N:
    count+=1
print(count)

Submission status: Accepted

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

l = [[int(i) for i in input().split()] for _ in range(n)]

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