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:
K = [None]*30
A = [None]*30
Ms = [0]*31
def main():
    N, M = map(int, input().split())
    for i in range(N):
        K[i], *A[i], = map(int, input().split())
    for i in A:
        if i == None:
            break
        for j in i:
            Ms[j] += 1
    print(Ms.count(N))

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(n, m, A):
    count = [0] * (m + 1)
    for a in A:
        for i in range(1, len(a)):
            count[a[i]] += 1
    ret = 0
    for c in count:
        if c == n:
            ret += 1
    print(ret)
    return

def main():
    n, m = map(int, input().split())
    a = []
    for i in range(n):
        a.append(list(map(int, input().split())))
    solve(n, m, a)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
input = sys.stdin.readline

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

ans = [0] * (M + 1)

for __ in range(N):
    for like in list(map(int, input().split()))[1:]:
        ans[like] += 1

print(ans.count(N))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
B - Foods Loved by Everyone
https://atcoder.jp/contests/abc118/tasks/abc118_b

"""
import sys


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


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
K_A = [0]*N
for i in range(N):
    K_A[i] = list(map(int, input().split()))
for i in range(len(K_A)):
    del K_A[i][0]
and_set = set(K_A[0])
for i in range(len(K_A)-1):
    and_set = and_set & set(K_A[i+1])
print(len(and_set))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(result.count(N))

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
number_list = []
for _ in range(n):
	KA = input().split()
	number_list.extend(KA[1:])
count = 0
for i in range(m + 1):
	if number_list.count(str(i)) == n:
		count += 1

print(count)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())  # N人の人に聞く, M種類の食べ物の好きかどうか

menew = set(range(1, M+1))  # 食べ物の番号

for i in range(N):
    k, *a = map(int, input().split())
    menew = menew & set(a)

print(len(menew))

Submission status: Accepted

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

s = set()
for i in range(1, M + 1):
    s.add(i)
for KA in KAs:
    As = KA[1:]
    for i in range(1, M + 1):
        if not i in As and i in s:
            s.remove(i)
ans = len(s)

print(ans)

Submission status: Accepted

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

all_results = []

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

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


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

counters_list = list(counters.values())
ans = 0
for i in range(len(counters)):
    if counters_list[i] == N:
        ans += 1


print(ans)

Submission status: Accepted

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

food=[0]*m
ans=[]
for _ in range(n):
    a=list(map(int,input().split()))
    for j in range(a[0]):
        ans.append(a[j+1])
temp=0
for i in range(m+1):
    b=ans.count(i)
    if b==n:
        temp+=1
print(temp)

Submission status: Accepted

Solution code:



import numpy as np
N,M=input().split()
N=int(N)
M=int(M)

l=np.array([1 for i in range(M)])
for i in range(N):
	tmp=input().split()
	K=int(tmp[0])
	
	prefer=np.array([0 for j in range(M)])
	for k in range(K):
		prefer[int(tmp[k+1])-1]=1
	l*=prefer
print(np.sum(l))

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    a,b = LI()
    if a%b == 0:
        print(a+b)
    else:
        print(b-a)
    return

#B
def B():
    n,m = LI()
    d = defaultdict(int)
    for i in range(n):
        l = LI()
        for j in range(1,len(l)):
            d[l[j]] += 1
    ans = 0
    for i in d.values():
        if i == n:
            ans += 1
    print(ans)
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    B()

Submission status: Accepted

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

Submission status: Accepted

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

A = set()
for i in range(N):
    a = list(map(int, input().split()))
    B = set()
    for j in range(a[0]):
        B.add(a[j+1])
    A = A & B if i > 0 else B

print(len(A))

Submission status: Accepted

Solution code:
N,M=list(map(int,input().split()))
a=[list(map(int,input().split()))[1:] for _ in range(N)]
s={i for i in a[0]}
for l in a[1:]:
    for i in list(s):
        if not i in l:s.remove(i)
print(len(s))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
NM = [int(i) for i in input().split()]
check = [0] * NM[1]
index = 0
N = NM[0]
while(NM[0] > 0):
    KA = [int(i) for i in input().split()]
    A = KA[1:]
    for i in A:
        check[i - 1] += 1
    NM[0] -= 1
count = 0
for i in check:
    if i == N:
        count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(list_a.count(N))

Submission status: Accepted

Solution code:
n,m=map(int,input().split());d=[i+1 for i in range(m)]
def listdup(a,b):
  x=[]
  for i in a:
    if i in b:x.append(i)
  return sorted(x)
for i in range(n):
  a=list(map(int,input().split()));a=a[1:];a.sort()
  d=listdup(a,d)
print(len(d))

Submission status: Accepted

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

for i in range(N):
    favorite = [int(j)-1 for j in input().split()][1:]
    for f in favorite:
        food[f][i] = True

ans = 0
for f in food:
    if sum(f) == N:
        ans += 1

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

for i in range(m):
    if b[i] == n:
        count += 1

print(count)

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:
#encoding: utf-8

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

foods = [0] * M
ans = 0

for i in range(N):
    a = list(map(int, input().split()))
    for j in range(1, len(a)):
        foods[a[j] - 1] += 1
        if foods[a[j] - 1] == N:
            ans += 1

print(ans)

Submission status: Accepted

Solution code:
a,b=map(int, input().split())

cnt = [0]*b
r = 0
for i in range(a):
    li = list(map(int, input().split()))
    #print(li)
    for j in range(1,len(li)):
        cnt[li[j]-1] +=1
        #print(cnt)
        
for k in range(b):
    if(cnt[k] == a):
        r += 1
print(r)

Submission status: Accepted

Solution code:
import sys
n, m = map(int, input().split())
likes = [list(map(int, input().split())) for _ in range(n)]
if n == 1:
    print(len(likes[0]) - 1)
    sys.exit(0)
common = set(likes[0][1:]) & set(likes[1][1:])
for i in range(2, len(likes)):
    common = common & set(likes[i][1:])
print(len(common))

Submission status: Accepted

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

def main():
    cnts = [0]*M
    ans = 0

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

    for cnt in cnts:
        if cnt == N:
            ans += 1
    return ans


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

Submission status: Accepted

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

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

all_a = []
for i in range(1,n+1):
    all_a += a[i]

all_a.sort()
rev_a = all_a[:]
rev_a.reverse()
ans = 0

for i in range(1,m+1):
    try:
         if n == (len(all_a) - rev_a.index(i)) - all_a.index(i):
             ans += 1
    except ValueError:
         pass

print(ans)

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split(' '))
    Ks = [list(map(int, input().split(' ')))[1:] for _ in range(N)]
    
    duplicated = set(Ks[0])
    for i in range(1, len(Ks)):
        a = set(Ks[i])
        duplicated = duplicated & a

    print(len(duplicated))


    
main()

Submission status: Accepted

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

count=[0]*M

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

Submission status: Accepted

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

tmp = [0]*(M+1)
for a in A:
  for aa in a[1:]:
    tmp[aa] += 1
ans = 0
for t in tmp:
  if t == N:
    ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
ans = 0
l = [0] * (M+1)
for i in range(N):
    k,*ks =[int(k) for k in input().split()]
    for j in ks:
      l[j] += 1

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

def main():
    n, m = map(int, input().split())
    cand = {j + 1 for j in range(m)}
    for i in range(n):
        ka = list(map(int, input().split()))
        cand &= set(ka[1:])
    print(len(cand))

main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ls=[0]*m
for i in range(n):
  A=list(map(int,input().split()))[1:]
  for j in A:
    ls[j-1]+=1
print(sum(list(map(lambda x:x//n,ls))))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
K = [list(map(int,input().split())) for i in range(N)]
cnt = 0
for i in range(1,M+1):
    for j in range(N):
        K_tmp = K[j]
        K_tmp = K_tmp[1:]
        if K_tmp.count(i) == 0:
            break
    else:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
from itertools import chain

N, M = map(int, input().split())
l = [list(map(int, input().split()))[1:] for i in range(N)]
l = list(chain.from_iterable(l))

food_counts = 0
for i in range(1, M+1):
    if l.count(i) == N:
        food_counts += 1
print(food_counts)

Submission status: Accepted

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

Submission status: Accepted

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

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

V = {i for i in range(1, M+1)}

for i in range(N) : 
    A = [int(i) for i in input().split()][1:]
    S = set(A)
    V = V & S

print(len(V))

Submission status: Accepted

Solution code:
n,m = list(map(int, input().split()))
counter = [0]*m
#min = m

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

Submission status: Accepted

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

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

for v in like_total:
    cnt += v==N
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np

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

like_total = np.zeros(M)
cnt = 0
for _ in range(N):
    l = [v for v in map(int, input().split())]
    #print(l)
    for i in range(1, l[0]+1, 1):
        like_total[l[i]-1] += 1

#print(like_total, N)
#print(like_total[4], like_total[9], like_total[-1])
ans = len(np.where(like_total==N)[0])

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

for _ in range(n):
    res = list(map(int, input().split()))
    for j in res[1:]:
        dict[j] = dict[j]+1

for k in dict:
    if dict[k] == n:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
INFO=input().split(" ")

row=int(INFO[0])

for r in range(row):
    temp=input().split(" ")[1:]
    temp = set(map(int, temp))
    if r !=0:
        output = output & temp
    else:
        output = temp
print(len(output))

Submission status: Accepted

Solution code:
# Foods Loved By Everyone
N, M = map(int, input().strip().split())

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

Submission status: Accepted

Solution code:
# 入力
N, M = map(int, input().split())
K, A = zip(*(
    (int(t[0]), list(map(int, t[1].split())))
    for t in (input().split(maxsplit=1) for _ in range(N))
))

# 素直にカウント
ans = sum(
    all(k in a for a in A)
    for k in range(1, M + 1)
)

# 出力
print(ans)

Submission status: Accepted

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

for i in range(n):
    k = list(map(int,input().split()))
    first_k = k.pop(0)
    for j in range(m):
        counter[j] = counter[j] + k.count(j+1)
    k.clear

print(counter.count(n))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
K = []
for i in range(N):
    K.append(A[i][0])
    del A[i][0]
    
ans = A[0]
for i in range(N-1):
    ans = set(ans) & set(A[i+1])

print(len(ans))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[input().split() for _ in range(n)]
s={}
for h in a:
    for r in h[1:]:
        if r in s:
            s[r]+=1
        else:
            s[r]=1
cnt=0
for r in s.values():
    if r==n:
        cnt+=1

print(cnt)

Submission status: Accepted

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


def and_array(As,Bs):
    res = []
    for a in As:
        if a in Bs:
            res.append(a)

    return res


tmp = list(map(int, input().strip().split()))[1:]
for i in range(0,N - 1):
    tmp = and_array(tmp, list(map(int, input().strip().split()))[1:])

print(len(tmp))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce as red

def p(a, b):
    return a&b 

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

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

print(len(red(p, a)))

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
favorite_lists = []
merged = []
count = 0
for _ in range(0, N):
    favorite_lists.append(input().split()[1:])
for l in favorite_lists:
    merged.extend(l)
for key in range(0, M+1):
    if merged.count(str(key))==N:
        count+=1
print(count)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N, M= map(int, input().split())
ans = set(range(1, M+1)) # it would be a list!?
for i in range(N):
	a, *b = map(int, input().split()) # b=[A11, A12, ...]
	ans &= set(b) # intersection
print(len(ans))

Submission status: Accepted

Solution code:
numbers = [int(x) for x in input().split(" ")]
foods = []
for i in range(numbers[0]):
  foods.append([int(x) for x in input().split(" ")])
  foods[i].pop(0)
number = 0
for i in range(numbers[1]+1):
  if all(i in e for e in foods):
    number += 1
print(number)

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
if N == 1:
    alpha = list(map(int,input().split()))
    print(len(alpha)-1)
    exit()
li = [list(map(int,input().split())) for i in range(N)]
for i in range(0,N,1):
    del li[i][0]
for i in range(1,N,1):
    if i == 1:
        ans = set(li[i-1]) & set(li[i])
    else:
        ans = set(ans) & set(li[i])
print(len(ans))

Submission status: Accepted

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

kinds = 0
for food in loved_by_everyone:
    kinds += 1 if food == N else 0
print(kinds)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

L = []
cnt = 0

for _ in range(n):
    tmp = input().split()
    a = tmp[1:]
    L.extend(a)
    
c = Counter(L)
for k, v in c.items():
    if v==n:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
a=[]
for i in range(N):
  x = input().split()
  z = x[1:]
  a += list(map(int,z))
cnt=0
for k in range(1,M+1):
  n = a.count(k)
  if n==N:
    cnt +=1
  else:
    cnt = cnt
print(cnt)

Submission status: Accepted

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

L = []

for i in range(N):
    L += K[i][1:]
    
cnt = 0
for i in range(M+1):
    if L.count(i) == N:
        cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M=map(int, input().split())
#N人，全M種類
A=[]
for i in range(N):
  a=list(map(int, input().split()))
 # k = a[0]
  a = a[1:]
  #a[0]=K(K種類好きなものがある）
  #a[1,2,3,...]=好きな食べ物の種類
  A.append(a)

ans = 0
for i in range(1,M+1): #[1-M] アイテムi : 1,2,3,...,M

  # パターン1
  found = True
  for j in range(N): # human j : 0,...,N-1
      if (not i in A[j]): # [1,2,3]
          found = False
          break
  if found == True:
      ans += 1

print (ans)

Submission status: Accepted

Solution code:
import collections
N, M = list(map(int,input().split()))
loves = []
for i in range(N):
    love = list(map(int,input().split()))
    loves.append(love[1:])
lx = []
for l in loves:
    lx.extend(l)
c = collections.Counter(lx)
cnt = 0
for k, v in c.items():
    if v == len(loves):
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
nm=input().split()
N=int(nm[0]);M=int(nm[1])
dict={}
for i in range(N):
    list=input().split()
    del list[0]
    dict[i]=[int(l) for l in list]
st={}
for j in range(N):
    if j==0:
        st=set(dict[j])
    else:
        st=st&set(dict[j])
print(str(len(st)))

Submission status: Accepted

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

Submission status: Accepted

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

currSet = favFood[0]

for i in favFood:
    currSet = currSet & i

print(len(currSet))

Submission status: Accepted

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

for _ in range(N):
    K, *A = map(int, input().split())
    for i in range(M):
        if (i+1) not in A:
            flags[i] = False

print(flags.count(True))

Submission status: Accepted

Solution code:
from collections import Counter
N,M = map(int,input().split())
l = []
for _ in range(N):
    l += list(map(int,input().split()))[1:]
c1 = Counter(l)
c2 = Counter(c1.values())
if N in c2.keys():
    print(c2[N])
else:
    print(0)

Submission status: Accepted

Solution code:
from collections import Counter


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


print(sum(count == N for count in ctr.values()))

Submission status: Accepted

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

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

for n in range(N):
  input_list=[int(x) for x in input().split()]
  Ans_list = input_list[1:]
  
  Check_list=[x for x in Ans_list if x in food_list]
  food_list = Check_list
  
print(len(Check_list))

Submission status: Accepted

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

A = [0] * M
for i in xrange(N):
    K = map(int, raw_input().split())
    for j in xrange(1, len(K), 1):
        A[K[j]-1] += 1

count = 0
for a in A:
    if a == N: count += 1

print count

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
lss = []
for i in range(N):
    ls = list(map(int,input().split()))
    lss.append(ls[1:])
s = set(range(1,M+1))
for i in range(N):
    s = s.intersection(set(lss[i]))
print(len(s))

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
  a = input().split()
  a.pop(0)
  if(i == 0):
    ans = set(a)
  else:
    ans = ans&set(a)
    
len_ans = len(list(ans))
print(len_ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces

n,m = na()
a = [0]*40
for i in range(n):
  for j in na()[1:]:
    a[j] += 1

print(a.count(n))

Submission status: Accepted

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

for i in range(N):
    new_answer_cand = []
    food_list = []
    food_list.extend(list(map(int, input().split())))

    if i == 0:
        answer_cand.extend(food_list)
        answer_cand = answer_cand[1:]
    else:
        for j in range(0, len(answer_cand)):
            for k in range(1, len(food_list)):
                if answer_cand[j] == food_list[k]:
                    new_answer_cand.append(answer_cand[j])
        answer_cand = new_answer_cand

print(len(answer_cand))

Submission status: Accepted

Solution code:
###B - Foods Loved by Everyone
N, M = map(int, input().split())
kaito = []
for i in range(N):
    kaito.append([int(i) for i in input().split()])

cnt = 0
for i in range(1, M+1):
    jlist = []
    for j in range(N):
        if i in kaito[j][1:]:
            jlist.append(True)
        else:
            jlist.append(False)
    if all(jlist):
        cnt += 1
        
print(cnt)

Submission status: Accepted

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

k = [0] * n
a = [0] * n

for i in range(0,n):
    info = input().split()
    k[i] = info[0]
    a[i] = info[1:]

l = a[0][:]
for k in range(1,n):
    new = []
    for x in l:
        if x in a[k]:
            new.append(x)
    l = new[:]

print(len(l))

Submission status: Accepted

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

Submission status: Accepted

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

l = []

for i in range(N):
  l = [int(j) for j in input().split()]
  K = l.pop(0)
  l = set(l)
  if i > 0:
    l = l & pre_l
  pre_l = l
  
print(len(l))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
people =[]
food=[]
for i in range(n):
    people.append(list(map(int, input().split())))
common = {k for k in range(1, 31)}
for j in range(n):
    people[j].pop(0)
    common = common & set(people[j])
print(len(common))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    foods_list = get_params()
    print(count_common(foods_list))


def get_params():
    n, _ = map(int, input().split())
    return [
        {a for a in input().split()[1:]}
        for _ in range(n)
    ]


def count_common(foods_list):
    return len(set.intersection(*foods_list))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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())
    A &= set(B)
print(len(A))