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())
cl = [0 for i in range(m+1)]
for i in range(n):
    a = list(map(int,input().split()))
    k = a[0]
    for i in range(1,k+1):
        cl[a[i]] += 1
ans = 0
for i in range(m+1):
    if cl[i] == n:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
def main():
    N,M=map(int,input().split())
    like=[0]*M
    for _ in range(N):
        K,*A=map(int,input().split())
        for num in A:
            like[num-1]+=1
    print(like.count(N))

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

food = list(range(1, m+1))

for _ in range(n):
    A = list(map(int, input().split()))
    A.pop(0)
    for i in range(1, 31):
        if not i in A and i in food:
            food.remove(i)

print(len(food))

Submission status: Accepted

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

Submission status: Accepted

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

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

ka = []

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

common = [i for i in range(1,m+1)]
#print(common)

for i in range(n):
    #commonとka[1:]の共通項をcommonに格納
    temp = common + ka[i][1:]
    common = [x for x in set(temp) if temp.count(x) > 1]

print(len(common))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
set_list=[]
sets=set()
for i in range(N):
    s=input().split()
    s.pop(0)
    set_list.append(set(s))
for set in set_list:
    if len(sets)==0:
        sets=set
    else:
        sets=sets.intersection(set)
print(len(sets))

Submission status: Accepted

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

Submission status: Accepted

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

print(num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
like=[0]*(m+1)#like[j]がj番目の食べ物を好きな人の人数
for i in range(n):
    k,*a=map(int,input().split())
    for j in a:
        like[j] += 1
print(like.count(n))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N, M = map(int, input().split())
    like = [0]*(M+1)
    
    for i in range(N):
        row = list(map(int, input().split()))
        for j in range(1,len(row)):
            like[row[j]] += 1
    count = 0
    for l in like:
        if l == N:
            count += 1
    print(count)

Submission status: Accepted

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

like = set()

K, *A = map(int, input().split())
like = set(A)

for i in range(1, N):
    K, *A = map(int, input().split())
    like = like & set(A)

print(len(like))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
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())
like = [0]*M
for i in range(N):
  k,*A = map(int,input().split())
  for j in A:
    like[j-1] += 1
print(like.count(N))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = []
K = []
for i in range(N):
	k, *A_i = map(int, input().split())
	K.append(k)
	A.append(A_i)
cnt = 0
for i in range(M):
	flg = 0
	for j in range(N):
		if not i + 1 in A[j]:
			flg = 1
	if flg == 1:
		continue
	cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from collections import defaultdict
n, m = map(int, input().split())
cand = defaultdict()
for i in range(n):
    x = list(map(int, input().split()))
    for j in range(1, x[0] + 1):
        if x[j] in cand.keys():
            cand[x[j]] += 1
        else:
            cand[x[j]] = 1
count = 0
for index, key in enumerate(cand):
    if cand[key] == n:
        count += 1
print(count)

Submission status: Accepted

Solution code:
n,m = map(int, input().split()) #n person, m pieces
 
counter = []
ans = 0
for i in range(m):
  counter.append(0)
 
for i in range(n):
  ls = list(map(int, input().split()))
  kazu = ls[0]
  for i in range(1, kazu+1):
    num = counter[ls[i] - 1]
    counter[ls[i]-1] = num + 1
for i in range(m):
  if counter[i] == n:
    ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
lis = []
for i in range(n):
  lis += input().split()[1:]
  
import collections as cl
dic = cl.Counter(lis)
counter = 0
for num in dic.values():
  if num == n:
    counter += 1
print(counter)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
k=[]
a=[input().split()for _ in range(n)]
a.sort()
for i in range(n):
  k.append(a[i].pop(0))

ans=0
count=1

for j in range(int(k[0])):
  for h in range(n-1):
    if a[0][j] in a[h+1]:
      count+=1
  if count==n:
    ans+=1
  count=1

print(ans)

Submission status: Accepted

Solution code:
h,m=map(int,input().split())
l=[0]*(m+1)
for i in range(h):
  a,*b=map(int,input().split())
  for f in b:
    l[f]+=1
ls=sorted(l,reverse=True)
asd=1
fg=0
while True:
  de=ls.pop(0)
  if de==h:
    fg+=1
  else:break
print(fg)

Submission status: Accepted

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

li=[]
for i in range(n):
  temp=list(map(int,input().split()))
  del temp[0]
  li.append(temp)

for i in(mlist):
  judge=0
  for x in(li):
    if i not in x:
      judge=1
  if judge==0:
    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):
  As = list(map(int, input().split()))
  K = As.pop(0)
  s = s&set(As)
r = len(s)
print(r)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
k = [list(map(int, input().split())) for _ in range(n)]
dic = {x:0 for x in range(1,m+1)}
ans = 0
for i in range(n):
  for j in range(1, k[i][0] + 1):
    dic[k[i][j]] += 1

for a,b in dic.items():
  if b == n:
    ans += 1
print(ans)

Submission status: Accepted

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

food =[0]*(m+1)

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

print(food.count(n))

Submission status: Accepted

Solution code:
import numpy as np

N, M = map(int, input().split())
foods = np.zeros(M)
for i in range(N):
    a = list(map(int, input().split()))
    K = a[0]
    a = a[1:]
    for k in range(K):
      foods[a[k]-1] += 1

ans = np.count_nonzero(foods == N)
print(ans)

Submission status: Accepted

Solution code:
import collections

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

counter = collections.Counter()
for _ in range(n):
    k, *la = map(int, input().split())
    for x in la:
        counter[x] += 1
res = 0
for x in counter.values():
    if x == n:
        res += 1
print(res)

Submission status: Accepted

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

for i in range(n):
  for food in list(map(int, input().split()))[1:]:
    likes[food] += 1
print(len(list(filter(lambda x: x==n, likes))))

Submission status: Accepted

Solution code:
N, M = map(int, input().split()) #N:人数、M:種類数
a = [] #好きなものの個数と何番目か。最初は空
for _ in range(N):
    a.append(list(map(int, input().split())))
b = [0] * M
for i in range(N): #i番目の人
    for j in range(1, a[i][0]+1): #j番目の食べ物
        b[a[i][j]-1] += 1 #j番目の食べ物が好きな人をカウント
ans = 0
for k in range(M):
    if b[k] == N:
        ans += 1
print(ans)

Submission status: Accepted

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

K, *A_row_first = map(int, input().split())
set_A           = set(A_row_first)

for _ in range(N-1):

    K, *A_row = map(int, input().split())
    set_A     = set_A & set(A_row)

print(len(set_A))

Submission status: Accepted

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

Submission status: Accepted

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

A = []
for i in range(N):
	A.append(list(map(int,input().split())))
ans = 0
for j in range(1,M+1):
	n = 0
	for i in range(N):
		if j in A[i][1:]:
			n +=1
		if n == 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())))
for i in range(n):
  del(K[i][0])
l = 0
for j in range(1, m+1):
  k = 0
  for i in range(n):
     if K[i].count(j) == 1:
        k += 1
  if k == n:
    l += 1
print(l)

Submission status: Accepted

Solution code:
import numpy as np

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

tastes = np.zeros((n, m), dtype=np.int8)
for i in range(n):
    ka = list(map(int, input().split()))
    for j in range(ka[0]):
        # print(i, ka[j + 1] - 1)
        tastes[i][ka[j + 1] - 1] = 1
    
    # for t in tastes:
    #     print(t)
    # print("---")

# tastes = np.array(tastes)
# print(tastes)

score = np.sum(np.sum(tastes == 1, axis=0) == n)
print(score)

Submission status: Accepted

Solution code:
N,M  = map(int,input().split())
d = {}
for _ in range(N):
    tmp = list(map(int,input().split()))
    for i in range(1, len(tmp)):
        if tmp[i] not in d:
            d[tmp[i]] = 0
        d[tmp[i]] += 1
ans = 0
for v in d.values():
    if v == N:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
el = list(range(1, M + 1))
for _ in range(N):
    A = [int(x) for x in input().split()[1:]]
    for i, f in enumerate(el):
        if f not in A:
            el[i] = -1
print(len([x for x in el if x >= 1]))

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_set = {i for i in range(1,m+1)}
for i in range(n):
  a = list(map(int,input().split()))
  del a[0]
  a_set = set(a)
  ans_set = ans_set & a_set
print(len(ans_set))

Submission status: Accepted

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

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

print(cnt.count(N))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
A = list(map(int,input().split()))
leng = A[0]
nums = set(A[1:leng+1])

for i in range(n-1):
  B = list(map(int,input().split()))
  leng = B[0]
  new = set(B[1:leng+1])
  nums = nums & new 
print(len(nums))

Submission status: Accepted

Solution code:
"""#################################################################
【ABC118】
B_Foods_Loved_by_Everyone
#################################################################"""

#インポート
import sys

#入力用
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def IS(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def SS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()

lst = []
cnt = 0
N, M = IS()
for i in range(N):
    lst += (LI()[1:])
for i in range(1, M+1):
    if lst.count(i) == 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):
    _,*a = map(int,input().split())
    s &= set(a) # 集合の積
print(len(s))

Submission status: Accepted

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

Submission status: Accepted

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

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

count = [0]*(M+1)
for i in range(N):
    for j in range(KA[i][0]):
        count[KA[i][j+1]] += 1
ans=0
for i in range(1,M+1):
    if count[i] == N:
        ans+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
like = set()
for _ in range(n):
    k, *a = map(int, input().split())
    if like:
        like &= set(a)
    else:
        like = set(a)
print(len(like))

Submission status: Accepted

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

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

print(len(ans))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N)]
ALL = sum(list(map(lambda x: x[1:], L)), [])

ans = 0
for i in set(ALL):
    if ALL.count(i) is N:
        ans += 1

print(ans)

Submission status: Accepted

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

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:
import collections
N,M=map(int,input().split())

counter=collections.defaultdict(int)
for _ in range(N):
  text = list(input().split())
  for x in text[1:]:
    counter[x]+=1
ans=0
for x in counter:
  if counter[x]== N:
    ans+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

N, M = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(N)]
dic = set(a[0][1::])
tmp = {}

for i in range(1, N):
    tmp = set(a[i][1::])
    dic = dic & tmp
print(len(dic))

Submission status: Accepted

Solution code:
import collections
n,m=map(int,input().split())
A=[]
for i in range(n):
    a=list(map(int,input().split()))
    for k in range(a[0]):
        A.append(a[k+1])
B=collections.Counter(A)
c=0
for j in B.keys():
    if B[j]==n:
        c+=1
print(c)

Submission status: Accepted

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

for i in range(n):
  DD = list(map(int, input().split()))
  DD.pop(0)
  DB.append(DD)

fav = set(DB[0])
for i in range(n):
  fav = fav & set(DB[i])
print(len(fav))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
Alist = []
for _ in range(N):
    K, *A = map(int, input().split()) # *の付いたアンパックはリストになる
    Alist += A # 1次元配列に格納

Aset = list(set(Alist)) # セットはインデックスを取れないのでリストにしておく
ans = 0

for i in range(len(Aset)):
    if Alist.count(Aset[i]) == N: # Alistにある個数がNこなら全員が好き
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict


n, m = map(int, input().split())
d = defaultdict(int)
for i in range(n):
    tmp = list(map(int, input().split()))
    for a in tmp[1:]:
        d[a] += 1
cnt = 0
for value in d.values():
    if value == n:
        cnt += 1
print(cnt)

Submission status: Accepted

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

for i in range(N):
  for j in range(1, len(A[i])):
    like[A[i][j]] += 1

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

print(count)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
ans = [0]*m
i = j = 0
for i in range(n):
  a = list(map(int,input().split()))
  for j in range(1,a[0]+1):
    ans[a[j]-1] += 1
print(ans.count(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())
  S&=set(A)
print(len(S))

Submission status: Accepted

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

answer=[0]*M

for i in range(len(A)):
    for j in range(1, len(A[i])):
        answer[A[i][j]-1]+=1

count=0
for i in range(len(answer)): 
        if answer[i]/N==1:
            count+=1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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:
n,m=map(int,input().split())
l=[]
count=0
for i in range(n):
    k=[]
    k+=(map(int,input().split()))
    del k[0]
    l.extend(k)
for j in range(1,m+1):
    if l.count(j)==n:
        count+=1
print(count)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
Data = [0]*M
for _ in range(N):
    fabList = list(map(int,input().split()))
    fabList.pop(0)
    for f in fabList:
        Data[f-1] += 1
ans = 0
for i in range(M):
    if Data[i] == 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 = S & set(A)
print(len(S))

Submission status: Accepted

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

for i in range(1,len(kx[0])):
  for j in range(1,n):
    if kx[0][i] in kx[j][1:]:
      c1 += 1
  if c1 == n-1:
    c2 += 1
  c1 = 0

print(c2)

Submission status: Accepted

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

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 a[1:]:
    l[i-1]+=1
print(l.count(n))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

L = [0] * (M + 1)

for i in range(N):
    A = list(map(int, input().split()))
    for j in range(1, A[0] + 1):
        L[A[j]] += 1

print(L.count(N))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, M = map(int, input().rstrip().split())
li = [[int(_) for _ in input().rstrip().split()] for _ in range(N)]
for i in range(N):
    del li[i][0]

ans = 0
for i in range(M):
    Flag = "OK"
    for j in range(N):
            if not i+1 in li[j]:
                Flag = "NG"
    if Flag == "OK":
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

 
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n, m = na()

food = [1] * (m + 1)

for i in range(n):
    a = na()
    for f in range(1, len(food)):
        if f not in a[1:]:
            food[f] = 0

print(sum(food[1:]))

Submission status: Accepted

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

print(len(s))

#I refered the answer...

Submission status: Accepted

Solution code:
def test():
    n,m = map(int,input().split())
    d = list(map(int,input().split()))
    b = set(d[1:])
    for i in range(n-1):
        a = list(map(int,input().split()))
        c = set(a[1:])
        b = b & c

    print(len(b))


if __name__ == "__main__":
    test()

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
like =[]
for i in range(n):
    ka = list(map(int,input().split()))
    ka.pop(0)
    for j in range(m):
        if (j+1 in ka) and i == 0:
            like += [j+1]
        elif j+1 not in ka and j+1 in like and i != 0:
            like.remove(j+1)
print(len(like))

Submission status: Accepted

Solution code:
import collections

def main():
    N, M = map(int, input().split())
    d = collections.defaultdict(int)
    for _ in range(N):
        kA = list(map(int, input().split()))
        for i in range(1, kA[0]+1):
            d[kA[i]] += 1

    count = 0
    for A in d:
        if d[A] == N: count += 1
    return count

if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
import collections
n, m = map(int, input().split())
ls = [0] * m
for i in range(n):
    a = list(map(int, input().split()))
    for j, v in enumerate(a):
        if j != 0:
            ls[v-1] += 1
cnt = 0
for i in ls:
    cnt += 1 if i == n else 0
print(cnt)

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
S = set(range(1, M+1)) # 種類の集合　M >= 1
for i in range(N):
    K, *A = map(int, input().split())
    S &= set(A) # SとAに共通しているものを残す
print(len(S))

Submission status: Accepted

Solution code:
# B - Foods Loved by Everyone(ABC118)
N,M=map(int, input().split())
D=set()

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

Submission status: Accepted

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

food=[]

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

for i in food:
    del i[0]
#print(food)

if n==1:
    print(len(food[0]))

else:

    ans=0
    for i in range(1,m+1):
        cnt=0
        for sfood in food:
            if i in sfood:
                cnt+=1

        if cnt==n:
            ans+=1
    print(ans)

Submission status: Accepted

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

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

print(sum([1 for i in count if i == N]))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
ans = set(range(1,M+1))
for i in range(N):
    k,*a, = map(int,input().split())
    ans = ans & set(a)

print(len(ans))

Submission status: Accepted

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

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

Submission status: Accepted

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

S = set(range(1, m + 1))
for a in A:
    S &= set(a)

print(len(S))

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 = [0]*M

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

count = 0

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

print(count)

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())  # *を使ってAのリストを作成
    S &= set(A)  # 集合の演算を繰り返し行う
print(len(S))

Submission status: Accepted

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

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())
s = set(range(1, m+1))

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