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())

A=[]
K=[]
for i in range(N):
    tmp = list(map(int, input().split() ))
    K.append(tmp.pop(0))
    A.append(tmp)
    # print(K)
    # print(A)

sum=0
for i in range(M):
    for j in range(N):
        if (not((i+1) in A[j])):
            break
        if (j==N-1):
            sum+=1
            # print(i+1,A[j])
            # print(i)

print(sum)

Submission status: Accepted

Solution code:
#-*- coding: utf-8 -*-
"""
https://yahoo-procon2019-qual.contest.atcoder.jp/tasks/yahoo_procon2019_qual_a
"""

from collections import defaultdict
def sol(n, m, Ss):
    stack = defaultdict(int)
    all_like = 0

    for S in Ss:
        #print("S: %s," % S)
        for i, s in enumerate(S):
            if i == 0: continue
            #print("i:%s, s:%s" % (i, s))
            stack[s] += 1
            #print("stack: %s" % stack)
            if stack[s] == n:
                all_like +=1
    return all_like



test = False
#test = True
if test:
    n, k = 3, 4
    Ss = [
        [2, 1, 3],
        [3, 1, 2, 3],
        [2, 3, 2]
    ]
    #S =list( map(int, "1 6 3".split()))
    print(sol(n, k, Ss))


else:
    n, k = map(int, input().split())
    #print("%s %s %s %s" % (type(n), type(k), n, k))
    Ss = []
    for i in range(n):
        S =list( map(int, input().split()))
        Ss.append(S)
    print(sol(n, k, Ss))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(n)]
s = None
for d in data:
    if s is None:
        s = set(d[1:])
    else:
        s = s & set(d[1:])
print(len(s))

Submission status: Accepted

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

for i in range(n):
    fav_list.append(list(map(int,input().split())))
    
common = fav_list[0][1:]
for i in range(len(fav_list) ):
    common = set(common) & set(fav_list[i][1:])
    
print(len(common))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n,m=map(int, input().split())
lst = [list(map(int, input().split())) for i in range(n)]
cnt = 0
for i in range(1,m+1):
    tmp = 0
    for j in range(n):
        if i in lst[j][1:]:
            tmp += 1
    if tmp == n:
        cnt +=1
print(cnt)

Submission status: Accepted

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

init = set(range(1, m+1))
for i in range(n):
	l = list(map(int,input().split()))
	l.pop(0)
	ls = set(l)
	init = init & ls

print(len(init))

Submission status: Accepted

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

for i in range(m):
    f = 0
    for j in range(n):
        if not i+1 in k[j][1:]:
            f = 1
            #print(i+1)
            #print(k[j][1:])
    if f == 0:
        c += 1

print(c)

Submission status: Accepted

Solution code:
n, m = map(int, raw_input().split())
ln = []
for k in range(n):
    a = map(int, raw_input().split())
    ln.append(a[1:])
clist = []
for j in range(1, m+1):
    c = 0
    for i in range(len(ln)):
        if j in ln[i]:
            c += 1 
        else:
            break
    clist.append(c)
print clist.count(n)

Submission status: Accepted

Solution code:
import numpy as np
N, M =map(int,input().split())
search = np.zeros(M+1)
for i in range(N):
   K = list(map(int,input().split()))
   for j in range(1,K[0]+1):
       search[K[j]]+=1
place = np.where(search==N)
print(len(place[0]))

Submission status: Accepted

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

ans = set(list(map(int, input().split()))[1:])

for i in range(n-1):
    ans &= set(list(map(int, input().split()))[1:])
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)]
cnt = 0

like = []
for i in range(m):
  like.append(0)

for i in range(n):
  for j in range(a[i][0]):
    like[a[i][j + 1] - 1] += 1
    
for i in range(m):
  if like[i] == n:
    cnt += 1
    
print(cnt)

Submission status: Accepted

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

set_ = [set(tab[i][1:]) for i in range(N)]
for i in range(N):
    if i==0:
        new_set = set_[i]
    if i == N:
        break
    new_set = new_set & set_[i]

print(len(new_set))

Submission status: Accepted

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


for i in range(n):
  lis.append(list(map(int,input().split())))
  lis[i].pop(0)
   
for i in range(m):
  for k in range(n):
    if not i+1 in lis[k]:
      break
  else:
    count += 1

print(count)

Submission status: Accepted

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

a=[]
cnt=[0]*m
ans=0

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

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
K_A = []
M_A  =[0 for _ in range(M)]
ans = 0
for i in range(N):
	k_a = map(int, input().split())
	K_A.append(list(k_a))
for i in range(N):
	for j in range(1, len(K_A[i])):
		M_A[K_A[i][j]-1] += 1
for i in range(len(M_A)):
	if M_A[i] == N:
		ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(len(lst)):
    for j in range(len(lst[i])):
        cnt_idx = lst[i][j]
        cnt_lst[cnt_idx] += 1

for cnt in cnt_lst:
    if cnt == n:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
#ABC118B-FoodsLovebyEveryone.py

from sys import stdin

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

kind = 0
box = []
for i in range(M):
    box.append(0)

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

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

print(count)

Submission status: Accepted

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

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

cnts = [0 for _ in range(m + 1)]

for _ in range(n):
    for like_no in map(int, input().strip().split()[1:]):
        cnts[like_no] += 1

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

print(ans)

Submission status: Accepted

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

if N == 1:
    print(res[0][0])
    exit()

s = [0 for i in range(M)]
for i in res:
    for j in i[1:]:
        #print(j)
        s[j-1] += 1

#print(s)

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

print(count)

Submission status: Accepted

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

B = []
for j in range(n):
    for k in range(A[j][0]):
        B.append(A[j][k+1])

score = 0
for l in range(m+1):
    if B.count(l) == n:
        score += 1

print(score)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000)
input = sys.stdin.readline

def chkprint(a):
	a_name = ''
	for k, v in globals().items():
		if id(v) == id(a):
			a_name = k
			break
	print(a_name+' = '+str(a), file=sys.stderr)

def mt(f):
	import time
	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		print(e - s, 'sec', file=sys.stderr)
		return ret
	return wrap

@mt
def slv():
	
	
	return 
	
N, M = [int(i) for i in input().split()]
K = [[int(i) for i in input().split()] for _ in range(N)]

count = 0
for i in range(1, M+1):
	a = True
	for Ki in K:
		if not i in Ki[1:]:
			a = False
	if a:
		count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

print(len(se))

Submission status: Accepted

Solution code:
def read():
    return int(input())

def reads():
    return list(map(int, input().split()))

n,m = reads()
a = []
r = []
for i in range(n):
    a.append(reads())
for i in range(n):
    for j in range(1,a[i][0]+1):
        r.append(a[i][j])
ans = 0
for i in set(r):
    if r.count(i) == n:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
x=[]
answer=0
for i in range(n):
    x.append(list(map(int,input().split())))
    del x[i][0]
for i in range(m):
    cnt=0
    for j in range(n):
        if i+1 in x[j]:
            cnt+=1
        else:
            break
    if cnt==n:
        answer+=1
print(answer)

Submission status: Accepted

Solution code:
n ,m = map(int, input().split())
a = [[int(j) for j in input().split()] for i in range(n)]
need = []
for i in range(n):
    need.append(a[i][1:])
ans = set(need[0])
for i in range(n):
    d = set(need[i])
    ans = ans & d
print(len(ans))

Submission status: Accepted

Solution code:
n,m=list(map(int,input().split(" ")))
ka=[]
for i in range(n):
    ka.append(list(map(int,input().split(" "))))
for i in range(n):
    ka[i].pop(0)
counter=0
i=1
while i<=m:
    j=0
    while j<=n-1:
        if i in ka[j]:
            j+=1
        else:
            break

        if j==n:
            counter+=1
    i+=1
print(counter)

Submission status: Accepted

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

[n, m] = map(int, input().split(' '))
food_loved = []

for i in range(0, n):
    tmp = input().split(' ')
    food_loved.append(set(tmp[1:len(tmp)]))

result = food_loved[0]

for i in range(1, n):
    result = result & food_loved[i]

print(len(result))

Submission status: Accepted

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

Submission status: Accepted

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

a = []
for i in range(n):
    a.append(list(map(int, input().split())))
    
check = [0 for i in range(m)]
for i,j in enumerate(a):
    for k in range(j[0]):
        check[a[i][k+1] - 1] += 1
        
print(check.count(n))

Submission status: Accepted

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

N,M = map(int,input().split())
lst = [list(map(int,input().split())) for i in range(N)]
tmp=[]
for i in lst:
    l = i[1:]
    for p in l:
        tmp.append(p)

ct = collections.Counter(tmp)
values, counts = zip(*ct.most_common())
ans = 0
for i in counts:
    if i == N:
        ans+=1
print(ans)

Submission status: Accepted

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

persons = [input() for i in range(N)]

cnt = [0 for i in range(M)]

for i_person in persons:
    l = list(map(int, i_person.split(" ")))
    

    for f in l[1:]:

        cnt[f-1] += 1

print(sum(list(map(lambda x:x==N, cnt))))

Submission status: Accepted

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

A = [flatten for inner in A for flatten in inner[1:]]
#print(A)
import collections
A_cnt = collections.Counter(A)
print(sum([l[1]==N for l in A_cnt.most_common()]))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = {i for i in range(1,m+1)}
for _ in range(n):
    li = list(map(int, input().split()))
    b = {li[i] for i in range(1,li[0]+1)}
    a = a.intersection(b)
    b = {}
    li = []
print(len(a))

Submission status: Accepted

Solution code:
# coding: utf-8
n, m = map(int, input().split())
like_food = [0 for i in range(m)]
for j in range(n):
    j_data = list(map(int, input().split()))
    for k in range(j_data[0]):
        like_food[j_data[k + 1] - 1] += 1
print(like_food.count(n))

Submission status: Accepted

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

A = []


for i in range(N):
    A.append(list(map(str, input().split())))
    del A[i][0]

if N != 1:
    ans = set(A[0]) & set(A[1])

if N >= 3:
    for i in range(2,N):
        ans = ans & set(A[i])

if N >= 2:
    print(len(ans))
else:
    print(len(A[0]))

Submission status: Accepted

Solution code:
(N ,M) =  (int(i) for i in input().split())
A =set(range(1,M+1))

for n in range(N):
	A = A.intersection(set([int(i) for i in input().split()][1:]))

print(len(A))

Submission status: Accepted

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

#人数分の入力
for i in range(N):
    #入力
    I = input().split()
    #好きな食べ物をlikeに加算
    K = int(I[0])
    for j in range(K):
        index = int(I[j+1])
        like[index - 1] += 1
    
#全員が好きと答えた食べ物の種類をカウント
C = like.count(N)

print(C)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
for i in range(N):
    if i == 0:
        lista = list(map(int,input().split()))
        del lista[0]
    else:
        listb = list(map(int,input().split()))
        del listb[0]
        lista = list(set(lista) & set(listb))
print(len(lista))

Submission status: Accepted

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

ma = K.index(max(K))

kinds = 0
for j in range(K[ma]):
    f = 0
    for i in range(N):
        if A[ma][j] in A[i]:
            f += 1
    if f == N:
        kinds += 1
print(kinds)

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
l = []
ans = 0
for i in range(a[0]):
    l.extend(list(map(int, input().split()))[1:])

for i in range(a[1]):
    if l.count(i + 1) == a[0]:
        ans = ans + 1
print(ans)

Submission status: Accepted

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

for k in range(0, n):
    a = [int(i) for i in input().split(" ")]
    for j in range (1, a[0] + 1):
        c[a[j] - 1] += 1

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

print(s)

Submission status: Accepted

Solution code:
import numpy as np
N, M =map(int,input().split())
search = np.zeros(M+1)
for i in range(N):
    K = list(map(int,input().split()))
    for j in range(1,K[0]+1):
        search[K[j]]+=1
place = np.where(search==N)
print(len(place[0]))

Submission status: Accepted

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

print(len(set.intersection(*map(set,lis))))

Submission status: Accepted

Solution code:
n,m=map(int, input().split())  #複数数値入力
list1 = [0] * n

for i in range(n):
    list1[i]=list(map(int, input().split()))  #リスト入力（数値）
    list1[i].pop(0)

ans = 0

for i in range(m):
    check = 0
    for j in range(n):
        if not i+1 in list1[j]:
            check =1
            break
    
    if check == 0:
        ans += 1


print(ans)

Submission status: Accepted

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

set_prev = set(like_foods[0])

for i in like_foods:
    set_prev = set_prev & set(i)
    
print(len(set_prev))

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

count = [0] * M

for n in range(N):
    A = list(map(int, input().split()))

    for a in A[1:]:
        count[a-1] += 1

ans = 0

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M=map(int, raw_input().split())
A=[ 1 for i in range(M+1) ] 

for i in range(N):
	X=map(int, raw_input().split())
	for j in range(1,M+1):
		if j not in X[1:]:
			A[j]&=0

print sum(A[1:])

Submission status: Accepted

Solution code:
import collections
n,m = map(int,input().split())
k_list = []
for _ in [0]*n:
    k_list.extend([int(i) for i in input().split()[1:]])
col = collections.Counter(k_list)
count = 0
for k,v in col.most_common():
    if v == n:
        count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
def li(): return map(int, stdin.readline().split())

N, M = tuple(li())
common = set(range(1,M+1))
for _ in range(N):
    answer = tuple(li())
    favs = set(answer[1:])
    common = common.intersection(favs)
print(len(common))

Submission status: Accepted

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

print(Kind.count(N))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
n,k = map(int, input().split())
l=[]
for i in range(n):
    x = list(map(int, input().split()))
    l+=x[1:]
c = collections.Counter(l)
s=0
for i in c.most_common():
    #print(i)
    if n == i[1]:
        s+=1
print(s)

Submission status: Accepted

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

for i in range(n):
  k[i] = k[i][1:]

ary = [1] * m
for i in range(n):
  for j in range(m):
    if(not j+1 in k[i]):
      ary[j] = 0
print(sum(ary))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from operator import itemgetter
import collections


def r(n, m, kl):
    nc = 0
    al = []
    for k in kl:
        al.extend(k[1:])
    c = collections.Counter(al)
    for v in c.values():
        if v == n:
            nc += 1
    return nc

def main():
    input = sys.stdin.readline
    n, m = list(map(int, input().split()))
    kl = [tuple(map(int, input().split())) for _ in range(n)]

    print(r(n, m, kl))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

summary = list(map(lambda x:x == n, questionary))
print(sum(summary))

Submission status: Accepted

Solution code:
#coding:utf-8
from collections import defaultdict

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


result = defaultdict(list)

for i in range(N):
    data = list(map(int, input().split()))
    K = data[0]
    data = data[1:]
    data = [d-1 for d in data]
    result[i]=data


count = 0
for food in range(M):
    break_flag = False
    for i in range(N):
        if not food in result[i]:
            break_flag = True
            break
    else:
        count+=1

print(count)

Submission status: Accepted

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

import numpy as np

def solve():
    N, M  = map(int, input().split())
    A = set.intersection(*(set(list(map(int, input().split()))[1:]) for _ in range(N)))
    res = len(A)

    return str(res)
if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
from collections import Counter

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

all_likes = []
for i in range(N):
    K,*As = map(int,input().split())
    all_likes.extend(As)

print(len([i for i in Counter(all_likes).values() if i==N]))

Submission status: Accepted

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

tmp = lst[0]
for i in range(1,N):
  tmp = tmp & lst[i]

ans = len(tmp)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

ans = list()
for _ in range(1,m+1):
    if all(_ in a[i] for i in range(0,n)):
        ans.append(_)

print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

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

all_suki_e = 0
for e in range(1, M + 1):
    for sukis in suki_lists:
        # print(e, sukis)
        if e in sukis:
            pass
        else:
            # print("out")
            break
    else:
        # print("pass")
        all_suki_e += 1

print(all_suki_e)

Submission status: Accepted

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

for i in range(n):
    s &= set([int(_) for _ in input().split()][1:])
print(len(s))

Submission status: Accepted

Solution code:
def main():
	N, M = map(int, input().split())
	food = [0 for i in range(M)]
	for i in range(N):
		K = input().split()
		hmt = int(K[0])
		for j in range(1, hmt + 1):
			food[int(K[j]) - 1] += 1
	count = 0
	for i in range(M):
		if food[i] == N:
			count += 1
	print(count)

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
import numpy as np

N,M = map(int ,input().split())
ans = np.array([0 for _ in range(M+1)])
for i in range(N):
    S = list(map(int,input().split()))
    for s in S[1:]:
        ans[s] += 1
cnt = 0
for a in ans:
    if a == N:
        cnt += 1

print(cnt)

Submission status: Accepted

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

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

count = 0
for item in a_list:
    if item == n:
        count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

foods = [0] * M
num = 0
for like in like_list:
    for elem in like[1:]:
        foods[elem-1] += 1
        if foods[elem-1] == N:
            num += 1

print(num)

Submission status: Accepted

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

Submission status: Accepted

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

menu = [0 for i in range(M)]

for i in range(N):
    love = list(map(int,input().split()))
    for idx,t in enumerate(love):
        if idx == 0:
            continue
        menu[t-1] += 1

ans = 0
for i in menu:
    if i == N:
        ans += 1
print(ans)

Submission status: Accepted

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

leftover = None
for i in range(n):
    k_a_list = list(map(int, input().split()))
    if i == 0:
        leftover = k_a_list[1:]
    else:
        k = k_a_list[0]
        leftover = [a for a in k_a_list[1:] if a in leftover]
    if leftover == []:
        print(0)
        exit()

print(len(leftover))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
K = []
A = []
for n in range(N):
    INPUT = list(map(int, input().split()))
    K.append(INPUT[0])
    A.append(INPUT[1:])
intersection=set(A[0])
for a in A:
    intersection=intersection&set(a)
print(len(intersection))

Submission status: Accepted

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

# n:人の数
# m:食べものの種類

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

for _ in range(n):
    ans = list(map(int, input().split()))[1:]

    new_foods = []
    for a in ans:
        if a in foods:
            new_foods.append(a)

    foods = new_foods

print(len(foods))

Submission status: Accepted

Solution code:
from sys import stdin

n, m = list(map(int, stdin.readline().rstrip().split()))
stack = set(range(1, m+1))
for i in range(n):
	a = list(map(int, stdin.readline().rstrip().split()))
	k = a.pop(0)
	stack = set(a) & stack

print(len(stack))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest 118：B - Foods Loved by Everyone


def main():
    N, M = [int(i) for i in raw_input().strip().split(' ')]
    A = []
    for _ in range(N):
        a = [int(i) for i in raw_input().strip().split(' ')][1:]
        A.append(a)
    Hantei = [True for _ in range(M)]

    for a in A:
        # print a
        for i in range(1, M+1):
            if i in a:
                pass
            else:
                Hantei[i-1] = False

    # print Hantei
    print Hantei.count(True)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
N,M = [int(n) for n in input().split()]
# N = int(input())
A = [set()]*N
anns = set([ i+1 for i in range(M)])
for i in range(N):
    tmp = [int(n) for n in input().split()]
    A[i] = set(tmp[1:])
    anns = anns & A[i]
print(len(anns))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

n, m = map(int, input().split())
k = []
for i in range(n):
    a = list(map(int, input().split()))
    k.extend(a[1:])
ans = 0
c = collections.Counter(k)
for i in range(1, m + 1):
    if c[i] >= n:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans_list = list(map(int, input().split()))[1:]
for _ in range(1, n):
    a = list(map(int, input().split()))[1:]
    tmp_list = []
    for ans in ans_list:
        if ans in a:
            tmp_list.append(ans)
    ans_list = tmp_list

print(len(ans_list))