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:
import sys
def input(): return sys.stdin.readline().strip()


def main():
    N, M = map(int, input().split())
    food = {i: 0 for i in range(1, M + 1)}
    for _ in range(N):
        arr = list(map(int, input().split()))
        for i in range(1, arr[0] + 1):
            food[arr[i]] += 1
    ans = 0
    for key in food:
        if food[key] == N: ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict

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

food_dict = defaultdict(int)

for loved_foods in loved_food_list:
    for food in loved_foods[1:]:
        food_dict[food] += 1

ans = 0
for food, num in food_dict.items():
    if num == n:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ls=[]
count,cnt=0,0
a=0

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

Submission status: Accepted

Solution code:
import math
import copy

neko = 0
n,m = map(int,input().split())
b = [0] * m
for i in range(n):
    a = [int(x) for x in input().split()]
    for j in range(1,len(a)):
        b[a[j]-1] += 1
for i in range(m):
    neko = (neko+1 if b[i]==n else neko)
print(neko)

Submission status: Accepted

Solution code:
import sys
import math
import bisect

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
List = []
for i in range(M):
  List.append(0)
for k in range(N):
  tmp = list(map(int,input().split()))
  for n in range(tmp[0]):
    tmp2 = tmp[n+1]
    List[tmp2-1] += 1
print(str(List.count(N)))

Submission status: Accepted

Solution code:
from collections import defaultdict

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

memo = defaultdict(int)

for n in range(N):
    _, *tmp = list(map(int, input().split()))
    for t in tmp:
        memo[t] += 1

print(list(memo.values()).count(N))

Submission status: Accepted

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

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n, m = mi()
    liked = set(range(1, m+1))
    for _ in range(n):
        L = lmi()
        liked = liked.intersection(L[1:])
        # print(liked)
    print(len(list(liked)))




if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    f = set(range(1,M+1))
    for _ in range(N):
        a = set(list(map(int, input().split()))[1:])
        f.intersection_update(a)
    print(len(f))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    ans = 0
    N, M = map(int, input().split())
    f = set(range(1,M+1))
    for _ in range(N):
        a = set(list(map(int, input().split()))[1:])
        f.intersection_update(a)
    print(len(f))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import collections as c

input = sys.stdin.readline

def main():
    ans = 0
    N, M = map(int, input().split())
    a = []
    for _ in range(N):
        a += list(map(int, input().split()))[1:]
    co = c.Counter(a)
    for k, v in co.items():
        if v == N:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n, m = Is()
KA = LIR(n)
A = []
for i in range(n):
    A.append(set(KA[i][1:]))
ans = 0
for i in range(1, m+1):
    for j in range(n):
        if i not in A[j]:
            break
    else:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
l = [0] * m
for i in range(n):
    a = list(map(int, input().split()))
    for j in range(1, a[0] + 1):
        l[a[j] - 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())
cnt = [0]*m
for i in range(n):
    ka = list(map(int, input().split()))
    for j in range(1, ka[0]+1):
        cnt[ka[j]-1] += 1
print(sum(i == n for i in cnt))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(d.count(N))

Submission status: Accepted

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

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

print(d.count(N))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
E = []
for i in range(N):
  S = list(map(int,input().split()))
  S.remove(S[0])
  L = list(set(S))
  
  E.extend(L)
p = 0
for j in range (M):
  if E.count(j+1) == N:
    p += 1
print(p)

Submission status: Accepted

Solution code:
import collections

N, M = map(int, input().split())
x = []
for n in range(N):
  l = list(set(list(map(int, input().split()))[1:]))
  #print(l)
  x.extend(l)
  
c = collections.Counter(x)

ans = 0
for k in c.keys():
  if c[k] == N:
    ans += 1
print(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()))
  b = a.pop(0)
  for j in range(b):
    ans[a[j] - 1] += 1

print(ans.count(n))

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, len(a)):
        L[a[j]] += 1
print(L[1:].count(n))

Submission status: Accepted

Solution code:
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
hoge_list = [list(map(int,input().split())) 
             for nesya in range(n)]
f =[0]*m
for hoge in hoge_list:
  for i in range(len(hoge)-1):
    s = i + 1
    f[(hoge[s]-1)] += 1
ans = 0
for num in f:
  if num == n:
    ans += 1
print(ans)

Submission status: Accepted

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

counter = [0]*M

for i in KA:
    like = i[1:]
    for j in range(i[0]):
        counter[like[j]-1] += 1

print(counter.count(N))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ans=set()
b=set(range(1,m+1))
#print(b)
ans=ans.union(b)
for n in range(n):
  #print(ans)
  s=list(map(int,input().split()))
  ex=b - set(s[1:])
  ans=ans-ex
print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code

def resolve():
    N,M=pin()
    ans=set(range(1,M+1))
    for i in range(N):
          k,*a=pin()
          A=set(a)
          ans=ans&A
    print(len(ans))
#%%submit!    
resolve()

Submission status: Accepted

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

Submission status: Accepted

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

for k in K:
    for like in k[1:]:
        likes[int(like)-1] += 1

print(likes.count(N))

Submission status: Accepted

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

for i in tmp:
    if i == n:
        ans += 1
print(ans)

Submission status: Accepted

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

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

ans = sum([c == n for c in check])
print(ans)

Submission status: Accepted

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

check = [0]*m

for i in range(n):
  for a_i in tuple(map(int,input().split()))[1:]:
    check[a_i-1]+=1
    
print(check.count(n))

Submission status: Accepted

Solution code:
import itertools
n,m=map(int,input().split())
a=[]
for i in range(0,n):
  a.append(list(map(int,input().split())))
  del a[i][0]
a=list(itertools.chain.from_iterable(a))
count=0
for i in range(0,m):
  if a.count(i+1)==n:
    count=count+1
print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
n, m = map(int, input().split())
li = [0] * m
for i in range(n):
    tmp = list(map(int, input().split()))
    for j in range(len(tmp)):
        if j == 0:
            continue
        li[tmp[j] - 1] += 1
cnt = 0
for i in li:
    if (i == n):
        cnt += 1
print(cnt)

Submission status: Accepted

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

from functools import reduce


def main():
    N, M = [int(x) for x in input().split()]
    A = [[int(x) for x in input().split()[1:]] for _ in range(N)]
    print(len(reduce(lambda a, b: a & b, map(lambda a: set(a), A))))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

D = {}
for i in range(N):
    K, *A = map(int, input().split())
    for a in A:
        if a not in D:
            D[a] = 0
        D[a] += 1
        
ans = 0
for v in D.values():
    if v == N:
        ans += 1
        
print(ans)

Submission status: Accepted

Solution code:
import itertools
import math

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

dic = {}
for i in range(len(a)):
    for j in range(len(a[i])):
        if a[i][j] not in dic:
            dic[a[i][j]] = 1
        else:
            dic[a[i][j]] += 1

count = 0
for i in range(len(dic.keys())):
    if list(dic.values())[i] == n:
        count += 1

print(count)

Submission status: Accepted

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

# A = [int(input()) for _ in range(3)]

m_list = [n] * m
# print(m_list)

for i in range(n):
    ka = list(map(int,input().split(" ")))
    # print(ka)
    k = int(ka[0])
    # print(k)
    for j in range(k):
        m_list[ka[j+1]-1] -= 1
        # print(m_list)
# print(m_list)
count0 = m_list.count(0)
print(count0)

Submission status: Accepted

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

for k in K:
    for like in k[1:]:
        likes[int(like)-1] += 1

print(likes.count(N))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=[0 for z in range(M)]
for i in range(N):
    K=[int(s) for s in input().split()]
    for t in range(1,len(K)):
        A[K[t]-1]+=1
ans=A.count(N)
print(ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
N,M=map(int, input().split())
res=[]
for _ in range(N):
  data=list(map(int, input().split()))
  K=data.pop(0)
  A=data
  res.append(A)
flatten_list = list(itertools.chain.from_iterable(res))
cnt=0
for i in range(1, M+1):
  if flatten_list.count(i) == N:
    cnt +=1
print(cnt)

Submission status: Accepted

Solution code:
from collections import Counter

B=[]
n,m=map(int,input().split())
for _ in range(n):
	A=list(map(int,input().split()))
	B+=A[1:]													#listの結合

C=list(Counter(B).values())					#values()をlistに戻す必要がある

print(C.count(n))

Submission status: Accepted

Solution code:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,M = map(int,input().split())
AA = []
for _ in range(N):
    KA = list(map(int,input().split()))
    AA.append(KA[1::])

from collections import defaultdict
dic = defaultdict(int)
for A in AA:
    for a in A:
        dic[a] += 1

ans = 0
for v in dic.values():
    if v==N:
        ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(m):
    flag = True
    for j in range(n):
        if i+1 not in k[j]:
            flag = False
            break
    if flag:
        ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
k = [0]*n
a = [[0]]*n
for i in range(n):
  temp = list(map(int,input().split()))
  k[i] = temp[0]
  a[i] = temp[1:].copy()
lfood = set(range(1,m+1))
for i in range(n):
  tpset = set(a[i])
  lfood = lfood.intersection(tpset)
print(len(lfood))

Submission status: Accepted

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

for j in li:
    like = set(j[1:])
    food_list = food_list & like

print(len(food_list))

Submission status: Accepted

Solution code:
from collections import defaultdict

n,m = map(int, input().split())
dic = defaultdict(lambda:0)
for _ in range(n):
  ar = list(map(int, input().split()))
  for i in range(1,len(ar)):
    dic[ar[i]] += 1

ans = 0
for i,v in dic.items():
  if v == n:
    ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

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

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

ans=0  
for result in results:
    if result==n:
        ans+=1

print(ans)

Submission status: Accepted

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

l = [0 for _ in range(m)]

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

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

Submission status: Accepted

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

count_set = set(range(1, m + 1))
for _ in range(n):
    temp_list = [int(x) for x in input().split()]
    temp_list[0] = 0
    count_set &= set(temp_list)
print(len(count_set))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,m=map(int, input().split())
    checkl=[0]*m
    for i in range(n):
        a=list(map(int,input().split()))
        b=a[1:]
        for i in range(len(b)):
            checkl[b[i]-1]+=1
    print(checkl.count(n))

resolve()

Submission status: Accepted

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

F = [0]*M
for i in range(N):
  for j in range(1, K[i][0] + 1):
    F[K[i][j] - 1] += 1

print(F.count(N))

Submission status: Accepted

Solution code:
from collections import Counter as counter

ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########
def main(n,m,k):
    res = []
    a = []
    for i in k:
        a.extend(i[1:])
    c = counter(a)
    for i in range(1,m+1):
        if c[i] == n : res.append(i)
    return len(res)
    
n,m = mi()
k = mix(n)
print(main(n,m,k))

Submission status: Accepted

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

Submission status: Accepted

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

favorite = [0 for i in range(M)]
child = [input().split() for i in range(N)]

for i in range(N):
    for j in range(1, int(child[i][0]) + 1):
        favorite[int(child[i][j]) - 1] += 1


print(favorite.count(N))

Submission status: Accepted

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

syoki = [] 
for i in range(1,m+1):
    syoki.append(i)
nasi = []
for i in arrk:
    for j in syoki:
        
        if j not in i[1:]:
            nasi.append(j)
            

print(len(syoki)-len(set(nasi)))

Submission status: Accepted

Solution code:
import numpy as np


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

    flag = np.array([1]*M)

    for l in KA:
        tmp = np.array([0]*M)
        for i in range(1, l[0]+1):
            tmp[l[i]-1] = 1
        flag *= tmp

    print(sum(flag))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon May  4 20:56:04 2020
"""

import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]
mod = 10**9+7

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

foods = [0 for _ in range(M)]
for i in range(N):
    for j in range(1,len(A[i])):
        foods[A[i][j]-1] += 1
#        print(i,j,A[i][j])

ans = 0
for f in foods:
    if f == N:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
menu = set(range(1, m+1))
for _ in range(n):
  l = list(map(int, input().split()))
  l.pop(0)
  l = set(l)
  menu = menu & l

print(len(menu))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
cnt = [0 for _ in range(M)]
for _ in range(N):
    K, *A = list(map(int, input().split()))
    for a in A:
        cnt[a - 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())
ans = M
A = set(list(map(int, input().split()))[1:])
for i in range(N-1):
  tmp = set(list(map(int, input().split()))[1:])
  A = A & tmp
print(len(A))

Submission status: Accepted

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

cnt = 0
for i in li:
    if i >= n:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import numpy as np
n, m = map(int, input().split())
k = [0] * n
for i in range(n):
    k[i] = list(map(int, input().split()))

b = np.zeros((n, m))
for i in range(n):
    w = k[i]
    for j in range(1, len(w)):
        b[i, int(w[j])-1] = 1
print(sum(b.sum(axis=0) == n))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
KA = [LIST() for _ in range(N)]

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

print(len(S))