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())
List = [list(map(int,input().split())) for i in range(n)]

food = [0]*(m+1)

for i in range(n):
    for j in range(1, List[i][0]+1):
        food[List[i][j]] += 1

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

print(cnt)

Submission status: Accepted

Solution code:
from collections import defaultdict
N, M = map(int, input().split())
tmp = [list(set(list(map(int, input().split()))[1:])) for _ in range(N)]

d = defaultdict(int)
for i in range(N):
    for j in range(len(tmp[i])):
        d[tmp[i][j]] += 1
print(list(d.values()).count(N))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

a = [0]*31

for i in range(N):
    questionary = list(map(int,input().split()))
    for i in range(1,questionary[0]+1):
        a[questionary[i]] += 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,a=[],[]
for _ in range(N):
    a=list(map(int,input().split())) 
    del a[0]
    A.extend(a)

ans=0
for i in range(1,M+1):
    if A.count(i)==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())))

dict = {}

for i in range(n):
    for j in range(1, len(k[i])):
        if(str(k[i][j]) in dict):
            dict[str(k[i][j])] += 1
        else:
            dict[str(k[i][j])] = 1

cnt = 0

for value in dict.values():
    if(value == n):
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
k=[]
zisyo={}

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

for i in range(n):
    for j in range(1,k[i][0]+1):
        if  str(k[i][j]) in zisyo:
            zisyo[str(k[i][j])]+=1
        else:
            zisyo[str(k[i][j])]=1

count=0

for key,val in zisyo.items():
    if val==n:
        count+=1
print(count)

Submission status: Accepted

Solution code:
import numpy as np
n, m = map(int, input().split())
ans = np.zeros(m)
for _ in range(n):
    result = np.array(list(map(int, input().split())))
    k = result[0]
    foods = result[1:] - 1
    for i in range(k):
        index = foods[i]
        ans[index] += 1

ans -= n-1
ans = np.maximum(ans, 0)
print(int(np.sum(ans)))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
list=[]
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())
c,*a,=map(int,input().split())
for i in range(n-1):
    x,*y,=map(int,input().split())
    a=list(set(a) & set(y))
print(len(a))

Submission status: Accepted

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

all_like_list = a_list[0]
for i in range(1, len(a_list)):
    all_like_list = all_like_list.intersection(a_list[i])
print(len(all_like_list))

Submission status: Accepted

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

food = [0] * M

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

print(food.count(N))

Submission status: Accepted

Solution code:
#118 b
n,m=map(int,input().split())
a=[]
for i in range(n):
    x=list(map(int,input().split()))
    a.append(x)
ans=dict()
cnt=0
for i in a:
    for j in range(1,len(i)):
        z=i[j]
        if z not in ans:
            ans[z]=1
        else:
            ans[z]+=1
for x in ans.values():
    if x==n:
        cnt+=1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = []
foods = set(range(1, m+1))
for i in range(n):
  ki, *ai = list(map(int, input().split()))
  a.append(set(ai))
for i in range(n):
  foods &= a[i]
print(len(foods))

Submission status: Accepted

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

    liked_count = [0] * m
    for i in range(n):
        liked_list = [int(x) for x in input().split()[1:]]
        for liked_id in liked_list:
            liked_count[liked_id - 1] += 1

    print(liked_count.count(n))

if __name__ == "__main__":
    main()

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())
x=[[int(j) for j in input().split()][1:] for i in range(n)]
cnt=0
for i in range(1,m+1):
    for j in range(n):
        if i not in x[j]:
            break
    else:
        cnt+=1
print(cnt)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

for i in range(1, 31):
    ans.append(i)

for i in range(n):
    inp[i] = [int(x) for x in input().split()]
    ans = set(ans) & set(inp[i][1:])

print(len(ans))

Submission status: Accepted

Solution code:
import numpy as np

N,M=map(int,input().split())
K=[list(map(int,input().split())) for _ in range(N)]
count=0
matrix=np.zeros(M)
for i in range(N):
    for j in range(K[i][0]):
        matrix[K[i][j+1]-1]=matrix[K[i][j+1]-1]+1
#print(matrix)
matrix=matrix.tolist()
matrix.sort(reverse=True)
#print(matrix)
for i in range(M):
    if (int(matrix[i])==N):
        count=count+1
    else:
        break
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:
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n,m = map(int,input().split())
query = list(map(int,input().split()))[1:]
#print(query)
ans = 0
cnt = [0]*len(query)
if n == 1: 
    print(len(query))
    exit(0)
for j in range(n-1):
    a_j  = list(map(int,input().split()))[1:]
    for i in range(len(query)):
        if query[i] in a_j: cnt[i] += 1
        if cnt[i] == n-1: ans += 1
print(ans)

Submission status: Accepted

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

s = []
for i in a:
  s += i[1:]

ans = 0
for i in range(1, 31):
  if s.count(i)==n:
    ans += 1
    
print(ans)

Submission status: Accepted

Solution code:
import sys

INPUT = lambda: sys.stdin.readline().rstrip()
MAP = lambda: map(int, INPUT().split())

sys.setrecursionlimit(10 ** 9)


def main():
    N, M = MAP()

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

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
dic = {}
for i in range(n):
	x = list(map(int, input().split()))
	for i in range(x[0]+1):
		if i == 0:
			continue
		if x[i] in dic:
			dic[x[i]] += 1
		else:
			dic[x[i]] = 1
cnt = 0
for i in dic.keys():
	if dic[i] == n:
		cnt += 1
print (cnt)

Submission status: Accepted

Solution code:
import sys
import math
import itertools

n,k=list(map(int,input().split()))
count=0
num=[i for i in range(1,k+1,1)]
for j in range(n):
	a=list(map(int,input().split()))
	del a[0]
	num=list(set(a)&set(num))
print(len(num))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

K = []
A = []
for i in range(n):
    k,*a = input().split()
    K.append(k)
    A.append(a)

ans = 0

for i in range(m):
    sum = 0
    for j in range(n):
        sum += str(i+1) in A[j]
    if sum == n:
        ans+=1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

l = []
for i in range(n): #Kを除く好きな食べ物を取得
    a = [int(_) for _ in input().split()]
    l.append(a[1:a[0]+1])

y = [] #全部好きな人を要素’1’として格納
for j in range(1,m+1):
    x = 0
    for k in range(n):
        if j in l[k]:
            x += 1
    if x == n: #これが全部好きの条件
        y.append(1)
        
print(len(y))

Submission status: Accepted

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

l = []
for i in range(n): #Kを除く好きな食べ物を取得
    a = [int(_) for _ in input().split()]
    l.append(a[1:a[0]+1])

y = [] #全部好きな人を要素’1’として格納
for j in range(1,m+1):
    x = 0
    for k in range(n):
        if j in l[k]:
            x += 1
    if x == n:
        y.append(1)
        
print(len(y))

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
#print(n, m)
l = []
for i in range(n):
    a = [int(_) for _ in input().split()]
    l.append(a[1:a[0]+1])
#print(l)
y = []
for j in range(1,m+1):
    x = 0
    for k in range(n):
        if j in l[k]:
            x += 1
    if x == n:
        y.append(1)
print(len(y))

Submission status: Accepted

Solution code:
N, M = [int(n) for n in input().split()]
o = {}
for i in range(N):
    T = [int(n) for n in input().split()]
    K = T[0]
    A = T[1:]
    c = 0
    for j in range(K):
        c = o.setdefault(A[j], 0)
        c += 1
        o[A[j]] = c
ans = 0
for k,v in o.items():
    if v == N:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n , m = map(int,input().split())
M =set(range(m+1))
for _ in range(n):
    table = list(map(int,input().split()))
    M &= set(table[1:])

answer = len(M)
print(answer)

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split(" "))
    foods = [0] * (M + 1)
    result = 0
    for _ in range(N):
        tmp = list(map(int, input().split(" ")))
        for t in tmp[1:]:
            foods[t] += 1
    for food in foods:
        if food == N:
            result += 1
    print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

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

food = [0] * (m + 1)

for i in range(n):
    for j in range(1, a[i][0] + 1):
        food[a[i][j]] += 1

print(food.count(n))

Submission status: Accepted

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

NOT_LIKE = []
T = [i for i in range(1,M+1)]
for i in range(N):
    A = list(map(int, input().split()))
    tmp = [i for i in range(1,M+1)]
    for j in range(1, len(A)):
        tmp.remove(A[j])
    for t in tmp:
        if t in T:
            T.remove(t)

print(len(T))

Submission status: Accepted

Solution code:
#coding:utf-8
#カツサンドくん

n, m = map(int, input().split())
#各食べ物ごとの解答集計用
count = [0] * m

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

ans = 0
for item in count:
    if item == 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)]
ans = 0

for j in range(1, A[0][0] + 1):
    flag = True

    for i in range(1, N):
        if A[0][j] not in A[i][1:]:
            flag = False
            break

    if flag:
        ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
author : halo2halo
date : 9, Jan, 2020
"""

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, M = map(int, readline().split())
se = set(range(M + 1))
for _ in range(N):
    enquete = [int(x) for x in readline().split()]
    se &= set(enquete[1:])

print(len(se))

Submission status: Accepted

Solution code:
N, M = [int(i) for i in input().split()]
d = {i+1: 0 for i in range(M)}
for _ in range(N):
  for j in [int(i) for i in input().split()][1:]:
    d[j] += 1
ans = 0
for k in d.values():
  if k == N:
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
d = {}
for _ in range(n):
  k = input().split()
  for j in k[1:]:
    if j not in d:
      d[j] = 0
    d[j] += 1
print(len([v for v in d.values() if v == n]))

Submission status: Accepted

Solution code:
from collections import defaultdict
(n, k), *D,  = [list(map(int, s.split())) for s in open(0)]
di = defaultdict(int)
cnt = 0
for l in D:
    for i in range(1, len(l)):
        di[l[i]] += 1
for v in di.values():
    if v == n:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
dic = {}
for i in range(N):
    A = list(map(int, input().split()))
    for i in A[1:]:
        if i not in dic:
            dic[i] = 1
        else:
            dic[i] += 1

ans = 0
for i in dic.values():
    if i % N == 0:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import collections

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

answers = []
for i in range(N):
    answers.extend([int(i) for i in input().split()][1:])
    
c = collections.Counter(answers)

cnt = 0
for k, v in c.items():
    if v == N:
        cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

n, m = map(int, sys.stdin.readline().split())
g = [[int(x) for x in sys.stdin.readline().split()[1:]] for _ in range(n)]

def main():
    res = set(range(1, m+1))
    for a in g:
        res &= set(a)
    
    return len(res)

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = [0]*(m+1)
for i in range(n):
	k, *s = map(int, input().split())
	for _ in range(k):
		a[s[_]] += 1
ans = 0
for i in range(m+1):
	if a[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 i in range(n):
   k = [int(x) for x in input().split()]
   k.pop(0)
   tmp = [check[i]+1 if i+1 in k else 0 for i in range(m)]
   check = tmp

print(len([x for x in check if x == n]))

Submission status: Accepted

Solution code:

n,m = map(int,input().split())
ans = [0] * m
info = []

for i in range(n):
    info = list(map(int,input().split()))
    for j in range(1,info[0]+1):
        ans[info[j]-1] += 1
#    print(ans)

print(ans.count(n))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def examA():
    A, B = LI()
    if B%A==0:
        ans = A+B
    else:
        ans = B-A
    print(ans)
    return

def examB():
    N, M = LI()
    Flag = [0]*M
    for i in range(N):
        K = LI()
        for j in range(1,K[0]+1):
            Flag[K[j]-1] +=1
    ans = 0
    for i in Flag:
        if i==N:
            ans +=1
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examB()

Submission status: Accepted

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

print(ans.count(n))

Submission status: Accepted

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

ans = [0] * m

for i in range(n):
    for j in range(1, l[i][0]+1):
        ans[l[i][j]-1] += 1

print(ans.count(n))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, m = list(map(int, input().split()))
k = [list(map(int, input().split())) for _ in range(n)]
ser = min(k)[1:]
ans = 0
for i in ser:
    for j in range(n):
        if i in k[j][1:]:
            pass
        else:
            break
    else:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = []
d = [0]*m
for _ in range(n):
    tmp = list(map(int,input().split()))
    a.append(tmp[1:])
for b in a:
    for c in b:
        d[c-1] += 1
cnt = 0
for p in d:
    if p == n:
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,M=map(int,input().split())
    b=[0]*M
    for i in range(N):
        l=list(map(lambda x:int(x)-1,input().split()))
        for x in l[1:]:
            b[x]+=1
    ans=0
    for x in b:
        if x==N:
            ans+=1
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

s = set(As[0])
for A in As[1:]:
    s = s.intersection(set(A))
print(len(s))

Submission status: Accepted

Solution code:
# 入力
N, M = [int(i) for i in input().split()]

# カウント用の配列
count = [0] * M

for i in range(N):  # 入力しながら
    _, *A = [int(i)-1 for i in input().split()]
    for j in A:     # 数える
        count[j] += 1

res = 0
for i in count:
    if i == N: res += 1

print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, M = map(int,input().split())
A = []
for i in range(N):
    A.append([int(i) for i in input().split()])

K = []
for i in range(N):
    K.append(A[i][0])
    del A[i][0]
#print(A)


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

"""
tmp = A[0]
for i in range(1, N):
    for j in range(len(tmp)):
        if not (tmp[j] in A[i]):
            del tmp[j]
print(len(tmp))
"""

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
    k[i].pop(0)

cnt = 0

for i in range(1, m+1):
    flag = True
    for j in range(n):
        if i not in k[j]:
            flag = False
    if flag == True:
        cnt += 1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
data=[0]*(M+1)
for i in range(N):
    lst=list(map(int,input().split()))
    for u in lst[1:]:
        data[u]+=1
cnt=0
for u in data:
    if u==N:
        cnt+=1
print(cnt)

Submission status: Accepted

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

sum = [0]*M
for i in range(N):
    for j in range(len(A[i])):
        sum[A[i][j]-1] += 1

print(sum.count(N))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=[0]*(m+1)
s=0
for _ in range(n):
    t=list(map(int,input().split()))
    for e in t[1:]:
        l[e]+=1
for e in l:
    if e==n:
        s+=1
print(s)

Submission status: Accepted

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

mat = [[False] * m for _ in range(0, n)]
for i in range(0, n):
  v = list(map(int, input().split()))
  for x in v[1:]:
    mat[i][x-1] = True

ans = 0
for i in range(0, m):
  ok = True
  for j in range(0, n):
    ok &= mat[j][i]
  if ok:
    ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(len(a[0])):
    b=0
    for j in range(1,n):
        if a[j].count(a[0][i])>=1:
               b+=1
    if b==n-1:
        ans+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(len(s))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
lst = set([])
for i in range(n):
    A = list(map(int, input().split()))[1:]
    s = set(A)
    if i == 0:
        S = s
    else:
        S = S & s

print(len(S))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
a=set([i+1 for i in range(M)])
for i in range(N):
  b=[int(i) for i in input().split()]
  del b[0]
  s=a & set(b)
  a=s
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())
data = [0 for i in range(m)]
for i in range(n):
    k,*a = map(int,input().split())
    for x in a:
        data[x-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 _ in range(N):
    t = set()
    value = list(map(int, input().split()))
    for i in range(1, value[0] + 1):
        t.add(value[i])
    s = t & s

print(len(s))

Submission status: Accepted

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

    for j in a[1:]:
        c[j-1] += 1
 
print(c.count(N))

Submission status: Accepted

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

for i in range(N-1):
    l_t = set(input().split()[1:])
    l = set.intersection(l,l_t)

print(len(l))

Submission status: Accepted

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

A = [i for i in range(1, m+1)]
ANS = []
for i in range(n):
    B = list(map(int, input().split()))
    n = B[0]
    B = sorted(B[1:])
    T = []
    for i in B:
        if i in A:
            T.append(i)
    ANS = T
    A = ANS

print(len(ANS))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
k = [list(map(int, input().split())) for _ in range(n)]
lst = []
lst2 = []
cnt = 0

for i in range(n):
    for j in range(k[i][0]):
        lst.append(k[i][j+1])

for i in range(m):
    if lst.count(i+1) == n:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N, M = list(map(int, sys.stdin.buffer.readline().split()))
ok = set(list(range(1, M + 1)))

for _ in range(N):
    row = list(map(int, sys.stdin.buffer.readline().split()))
    row = set(row[1:])
    ok &= row
print(len(ok))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
def counter(li, n):
    count = Counter()
    count.update(li)
    return count[n]


import sys
input = sys.stdin.readline
N, M = map(int, input().split())
li_food = [0]*M
for i in range(N):
    li_input = list(map(int, input().split()))
    li_input = li_input[1:]
    for j in li_input:
        li_food[j-1] += 1
print(counter(li_food, N))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = list(map(int,input().split()))
ans = set([])
for i in range(N[1]+1):
	ans.add(i)
for i in range(N[0]):
	receive = list(map(int,input().split()))
	sub_ans = set(receive[1:])
	ans = ans & sub_ans
print(len(ans))

Submission status: Accepted

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

for i in range(1,m+1):
    for j in a:
        if i in j[1:]:
            cnt += 1
    if cnt == n:
        ans += 1
    cnt = 0

print(ans)

Submission status: Accepted

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

for i in range(1,m+1):
    for j in range(n):
        for k in range(1,a[j][0]+1):
            if a[j][k] == i:
                cnt += 1
                break
    if cnt == n:
        ans += 1
    cnt = 0

print(ans)