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

Submission status: Accepted

Solution code:
# ABC 118 B

import sys
import itertools

def resolve():
    N, M = map(int, input().split())
    arr = [0] * (M+1)
    for i in range(N):
        tmp = list(map(int, input().split()))
        for j in range(1, tmp[0]+1):
            arr[tmp[j]] += 1
    ans = 0
    for e in arr:
        if e == N:
            ans += 1
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
l = [int(i) for i in input().split(" ")]
n = l[0]
m = l[1]
foods = set(range(1,m+1))

for i in range(n):
    i_like_list = [int(i) for i in input().split(" ")[1:]]
    i_like_set = set(i_like_list)
    foods = foods & i_like_set
print(len(foods))

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
c = {i + 1: 0 for i in range(b)}
for i in range(a):
    d = list(map(int, input().split()))
    for j in range(1, len(d)):
        c[d[j]] += 1
d = 0
for k in c.keys():
    if c[k] == a:
        d += 1
print(d)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
cnt = [0] * m
for _ in range(n):
  _, *a = map(int,input().split())
  for ai in a:
    cnt[ai-1] += 1
sum_ = 0
for c in cnt:
  if c == n:
    sum_ += 1
print(sum_)

Submission status: Accepted

Solution code:

n,m=map(int,input().split())
s = set(range(1,m+1))

for _ in range(n):
    _, *a = map(int,input().split())
    s &= set(a)

print(len(s))

Submission status: Accepted

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

count = [0] * M 

for i in range(N):
    for j in range(K[i]):
        tmp = A[i][j]
        count[tmp-1] += 1

print(count.count(N))

Submission status: Accepted

Solution code:
import collections

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

a = []
for i in range(N):
    tmp = list(map(int, input().split()))
    a += tmp[1:]
    
c = collections.Counter(a)

ans = 0

for val in c.values():
  if val== N:
    ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,t=map(int,input().split())
x=list(list(map(int,input().split())) for _ in range(n))

from itertools import chain

y=[]

for i in range(n):
	y.append(x[i][1:])

z=list(chain.from_iterable(y))
v=list(set(z))

cnt=0
for i in range(len(v)):
	if z.count(v[i])==n:
		cnt+=1

print(cnt)

Submission status: Accepted

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

print(sum(ans))

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
L = [0]*M
for n in range(N):
    KA = list(map(int, input().split()))
    for a in KA[1:]:
        L[a-1]+=1

print(L.count(N))

Submission status: Accepted

Solution code:
people, foods = map(int, input().split(' '))
ls = []
for p in range(0, people):
    ls.append(set(x for i, x in enumerate(list(map(int, input().split(' ')))) if i > 0))

populer = ls[0]
for l in ls:
    populer = populer & l

print(len(populer))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
#各数字の個数をカウントするlist
cnt=[0]*(m+1)
for i in range(n):
    for j in list(map(int,input().split()))[1:]:
        cnt[j]+=1
res = 0
#もし数字の個数が人数に一致したならカウント
for i in range(1,m+1):
    if cnt[i] == n:
      res += 1
print(res)

Submission status: Accepted

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

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

print(len(fav))

Submission status: Accepted

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

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

print(sum(fav))

Submission status: Accepted

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

Submission status: Accepted

Solution code:


def main():
    A,B = map(int,input().split())
    
    originalList = set(list(map(int,input().split()))[1:])
    for i in range(A-1):
        list1=set(list(map(int,input().split()))[1:])
        originalList = originalList & list1

    print(len(originalList))


if __name__== "__main__":
    main()

Submission status: Accepted

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

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

print(a.count(N))

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 j in A[1:]:
        cnt[j-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())
cnt = [0]*m
for i in range(n):
    like = list(map(int, input().split()))
    k = like.pop(0)
    for j in like:
        cnt[j-1] += 1

all_like=0
for _ in cnt:
    if _ == n:
        all_like += 1
print(all_like)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import collections as co
n,m=map(int,input().split())
l=[]
for i in range(n):
    j,*k=map(int,input().split())
    l.extend(k)
count_num=0
for p,q in co.Counter(l).items():
    if q==n:count_num+=1
print(count_num)

Submission status: Accepted

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

k = [0] * (M + 1)
for i in range(N):
    a = [int(x) for x in input().split()]
    del a[0]
    for j in a:
        k[j] += 1
print(k.count(N))

Submission status: Accepted

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

li = [list(map(int, input().split()))[1:] for _ in range(n)]
ans = 0
for i in range(1, m+1):
    tf = True
    for j in li:
        if i not in j:
            tf = False
            break
    if tf:
        ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = set(range(1,m+1))

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

print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(N, M, inputs):
    likes = [string_to_int(i) for i in inputs]
    everyone_likes = {n for n in range(1, M+1)}

    for l in likes:
        like_set = set()
        for i, f in enumerate(l):
            if i == 0:
                continue
            like_set.add(f)

        everyone_likes = everyone_likes & like_set
    return len(everyone_likes)


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    [N, M] = string_to_int(input())
    ret = solve(N, M, inputs(N))
    print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ans = {i for i in range(1, M+1)}
for i in range(N):
    tmp = list(map(int, input().split()))
    K, A = tmp[0], tmp[1:]
    ans = ans.intersection(set(A))
print(len(ans))

Submission status: Accepted

Solution code:
# ABC 118, B - food loved by everyone
from collections import Counter

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

C_total = Counter()
for i in range(n):
    A = input().split(' ')
    del A[0]
    C = Counter(A)
    C_total += C

count = 0
for val in C_total.values():
    if val == n:
        count += 1
print(count)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
info=[]
for i in range(n):
    info.append(list(map(int,input().split())))
common=[info[0][i] for i in range(1,info[0][0]+1)] #最初は共通集合が１だけ
for i in range(1,n): #1～n-1
    data=[info[i][j] for j in range(1,info[i][0]+1)]
    common=set(common) & set(data)
print(len(common))

Submission status: Accepted

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

mcount = [0]*(m+1)
for mi in range(1,m+1):
  for ai in a:
    if mi in ai:
      mcount[mi] += 1
print(mcount.count(n))

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
c = [0] * b
for i in range(a):
    d = list(map(int, input().split()))
    for j in range(1, len(d)):
        c[d[j]-1] += 1
print(sum(1 if c[i] == a else 0 for i in range(b)))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
foods = []
for i in range(0, M):
	foods.append(True)
for i in range(0, N):
	inpt = list(map(int, input().split()))
	lst = []
	for j in range(0, M):
		lst.append(False)
	for j in range(0, inpt[0]):
		lst[inpt[1:][j]-1] = True
	for j in range(0, M):
		foods[j] = foods[j] and lst[j]
cnt = 0
for i in range(0, M):
	if foods[i]:
		cnt += 1
print(cnt)

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

Submission status: Accepted

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

for food in foods:
    if food == N:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    a = [0 for _ in range(m)]
    for _ in range(n):
        *aa, = map(int, input().split())
        for b in aa[1:]:
            a[b-1] += 1
    print(len([aa for aa in a if aa == n]))


main()

Submission status: Accepted

Solution code:
from collections import Counter
N, M = map(int, input().split())
A = []
for i in range(N):
    a = [int(i) for i in input().split()]
    A.append(Counter(a[1:]))
b = Counter()
for i in A:
    b += i
ans = 0
for i in b.values():
    if i == N:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import functools

def inter(a,b):
    return list(set(a)&set(b))


def resolve():
    n,m=map(int,input().split())
    a=[list(map(int,input().split())) for i in range(n)]
    a=[i[1:] for i in a]
    print(len(list(functools.reduce(inter,a))))    

resolve()

Submission status: Accepted

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

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

ans = len(list(filter(lambda x: x == N, memo)))
print(ans)

Submission status: Accepted

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

for _ in range(n):
    l = list(map(int, input().split()))
    s = set(l[1:])
    foods = s & foods

print(len(foods))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
food_dic = {}
for i in range(n):
    k_a = list(input().split())
    foods = k_a[1:]
    for food in foods:
        if food in food_dic:
            food_dic[food] += 1
        else:
            food_dic[food] = 1
count = 0
for food_count in food_dic.values():
    if food_count == n: count += 1

print(count)

Submission status: Accepted

Solution code:
N, M = list(map(int,input().split()))
C = [0 for _ in range(M)]
for _ in range(N):
    A = list(map(int, input().split()))
    A.pop(0)
    for a in A:
        C[a-1] += 1

ans = 0
for c in C:
    if c == N:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
d = defaultdict(int)
n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]
for val in l:
    for i in range(1, len(val)):
        d[val[i]] += 1
count = 0
for k in d.keys():
    if d[k] == n:
        count += 1
print(count)

Submission status: Accepted

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

ans = [0]*m
food = 0
for i in range(n):
    k = l[i][0]
    for j in range(k):
        food = l[i][j+1]-1
        ans[food] += 1
#print(ans)
print(ans.count(n))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
list1=list(map(int,input().split()))
del list1[0]
set1=set(list1)
for i in range(N-1):
  list2=list(map(int,input().split()))
  del list2[0]
  set2=set(list2)
  set1=set1&set2
ans=len(set1)
print(ans)

Submission status: Accepted

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

li2 = [0]*m
for i in range(len(li)):
    for j in range(1,li[i][0]+1):
        li2[li[i][j]-1] += 1

if max(li2) == n:
    print(li2.count(max(li2)))
else:
    print(0)

Submission status: Accepted

Solution code:
print(len(set.intersection(*[set(input().split()[1:]) for _ in [0]*int(input().split()[0])])))

Submission status: Accepted

Solution code:
import functools
print(len(functools.reduce(lambda x, y: x&y,[set(input().split()[1:]) for _ in [0]*int(input().split()[0])])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
#n = int(input())
#b = list(map(int,input().split()))
ls = [list(map(int,input().split()))[1:] for i in range(n)]
#s = input()
ans = 0

for i in range(1,m+1):
  tmp = [1 if j.count(i) == 1 else 0 for j in ls]
  if sum(tmp) == n:
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
erase = set()
for i in range(N):
    a = list(map(int, input().split())) 
    
    if i == 0:
        food = a[1:]
    for j in range(len(food)): 
        
        if food[j] not in a[1:]:
            erase.add(j)

print(len(food)-len(erase))

Submission status: Accepted

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

print(sum(l))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(len(ans))

Submission status: Accepted

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

li = []

for i in range(n):
  for j in input().split()[1:]:
    li.append(j)

s = set(li)

print(len([i for i in s if li.count(i) == n]))

Submission status: Accepted

Solution code:
#カツサンドくんはオムライスが好きです。
#他にも明太子や寿司、クリームブリュレやテンダーロインステーキなどが好きで、これらの食べ物は全て、誰もが好きだと信じています。
#その仮説を証明するために、N 人の人に M 種類の食べ物について好きか嫌いかの調査を行いました。
#調査の結果、i 番目の人は Ai1 番目, Ai2 番目, ..., AiKi 番目の食べ物だけ好きだと答えました。N 人全ての人が好きだと答えた食べ物の種類数を求めてください。
N, M = map(int, input().split())

l = []

for i in range(N):
    A = [int(x) for x in input().split()] 
    
    for j in range(1, A[0] + 1):
        l.append(A[j])
        
ans = 0

for i in range(M + 1):
    if l.count(i) == N:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split()) # 横に2個

for i in range(N):
    ob = set(list(map(int, input().split()))[1:])
    if i == 0:
        ans = ob
    else:
        ans = ans & ob

print(len(ans))

Submission status: Accepted

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

favo_count_of_food = [0 for _ in range(M)]

for i in range(N):
    answers = list(map(int,input().split()))
    for answer in answers[1:]:
        favo_count_of_food[answer-1] += 1
        
print(favo_count_of_food.count(N))

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

a = [] #1つのリストに格納
for i in range(n):
    tmp = list(map(int,input().split()))
    a += tmp[1:]

c = collections.Counter(a) #それぞれの要素の個数を辞書にして返す

ans = 0
for val in c.values():
    if val == n: #value値が人数に一致した場合を選択
        ans += 1

print(ans)

Submission status: Accepted

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

for i in range(n):
    l = list(map(int,input().split()))
    s_each = set(l[1:])
    s = s & s_each

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):
    l = list(map(int,input().split()))
    s_new = set(l[1:])
    s = s&s_new
print(len(s))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=[]
for j in range(N):
    A.append([int(i) for i in input().split()])
    A[j].pop(0)
ans=0

for i in range(1,M+1):
    for j in range(N):
        if not i in A[j]:
            break
        if j==N-1 and i in A[j]:
            ans+=1

print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
food = [0] * M
K_list = []
for _ in range(N):
    K_list.append(list(map(int, input().split())))

for i in range(N):
    for j in range(1, K_list[i][0]+1):
        food[K_list[i][j]-1] += 1


print(food.count(N))

Submission status: Accepted

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


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

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

    c = collections.Counter(a)
    ans = 0
    for val in c.values():
        if val == N:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000)
input=sys.stdin.readline
def intinput():return map(int,input().split())

n,m=intinput()
s={i+1 for i in range(m)}
for i in range(n):
    l=list(intinput())
    r=set(l[1:])
    s&=r
print(len(s))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
d = {str(i + 1): 0 for i in range(m)}
for _ in range(n):
  for item in input().split()[1:]:
    d[item] += 1

ans = 0
for key in d:
  if d[key] == n:
    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)]
ans = 0
tmp = 0
u = []
for i in range(n):del a[i][0]
for i in range(n):
    for j in range(len(a[i])):
        if not(a[i][j] in u):u.append(a[i][j])
for i in range(len(u)):
    for j in range(n):
        if u[i] in a[j]: tmp += 1
    if tmp == n: ans += 1
    tmp = 0
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
k = [i[1:] for i in [list(map(int, input().split())) for i in range(N)]]
k_1 = [flatten for inner in k for flatten in inner]
count_k = 0
for i in range(1, M + 1):
    if k_1.count(i) == N:
        count_k += 1

print(count_k)

Submission status: Accepted

Solution code:
from collections import Counter;N, M = map(int, input().split());print(len([i for i in Counter([flatten for inner in [i[1:] for i in [[int(i) for i in input().split()] for i in range(N)]] for flatten in inner]).most_common() if i[1] == N]))

Submission status: Accepted

Solution code:
from collections import Counter
N, M = map(int, input().split())
print(len([i for i in Counter([flatten for inner in [i[1:] for i in [[int(i) for i in input().split()] for i in range(N)]] for flatten in inner]).most_common() if i[1] == N]))

Submission status: Accepted

Solution code:
from collections import Counter

N, M = map(int, input().split())
K = [i[1:] for i in [[int(i) for i in input().split()] for i in range(N)]]
k = Counter([flatten for inner in K for flatten in inner]).most_common()
print(len([i for i in k if i[1] == N]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()

like = set([i for i in range(1, M+1)])
for i in range(N):
    As = nl()
    K = As[0]
    As = As[1:]
    like = like & set(As)
print(len(like))

Submission status: Accepted

Solution code:
n1, n2  = [int(i) for i in input().split()]

na3 = []

for i4 in range(n1):
    na3.append([int(j) for j in input().split()])

na5 = [0] * (n2 + 1)

for i6 in range(n1):
    for i7 in range(na3[i6][0] + 1):
        if i7 != 0:
            na5[na3[i6][i7]] += 1

r8 = 0
for i9 in range(n2 + 1):
    if na5[i9] == n1:
        r8 += 1

print(r8)

Submission status: Accepted

Solution code:
N = int()
M = int()

N,M=(int(x) for x in input().split())

lis = []
for a in  range(M):
    lis.append(0)

for i in range(N):
    answer = [int(x) for x in input().split()]
    for x in range(1,answer[0]+1):
        lis[answer[x]-1] += 1

print(lis.count(N))

Submission status: Accepted

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

foods = []
for a in range(m):
	foods.append(0)

for i in range(n):
	answer = [int(x) for x in input().split()]
	for x in range(1,answer[0]+1):
		foods[answer[x]-1] += 1

print(foods.count(n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N, M = map(int, input().split())
K = [0] * N
A = []
popular = [1] * M
count = 0

for i in range(N):
	tmp = list(map(int, input().split()))
	K[i] = tmp[0]
	A.append(tmp[1:])
	
for i in range(N):
	dislike = [1] * M
	for j in range(K[i]):
		dislike[A[i][j] - 1] = 0
		
	for k in range(M):
		if dislike[k] == 1:
			popular[k] = 0

for i in range(M):
	if popular[i] == 1:
		count += 1
		
print(count)

Submission status: Accepted

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

for i in range(N):
    A.append([int(m) for m in input().split()])
    A[i].pop(0)
cnt =0
for i in range(1,M+1):
    flag = 1
    for k in range(N):
        if i not in A[k]:
            flag = 0
    if flag == 1:
        cnt += 1
        

print(cnt)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
s = set(range(1, M+1))

for _ in range(N):
    s &= set(list(map(int, input().split()))[1:])

print(len(s))

Submission status: Accepted

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

cnt = [0]*M

for i in range(N):
    for j in range(1, List[i][0]+1):
        cnt[List[i][j]-1]+=1

print(cnt.count(N))

Submission status: Accepted

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

cnt = [0]*M

for i in range(N):
    K = List[i][0]
    for j in range(1, K+1):
        cnt[List[i][j]-1]+=1

print(cnt.count(N))

Submission status: Accepted

Solution code:
from collections import defaultdict
N,M = list(map(int,input().split(" ")))
di = defaultdict(lambda :0)
for i in range(N):
    temp= list(map(int,input().split(" ")))
    temp = temp[1:]
    for i in temp:
        di[i] += 1
ans = 0
for v in di.values():
    if v == N :
        ans+= 1
print(ans)

Submission status: Accepted

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

tlist = [True]*M
for i in range(N):
  alist = list(map(int,input().split()))[1:]
  
  llist = [False]*M
  for a in alist:
    llist[a-1] = True
  for j in range(M):
    if not llist[j]:
      tlist[j] = False
      
#print(tlist)
print(tlist.count(True))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections

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

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

c = collections.Counter(a)
#print(c)
ans = 0
for key,val in c.items():
    if val == N:
        ans += 1
    #print(key)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
foods = [0] * m
answers = [list(map(int, input().split()))[1:] for i in range(n)]

for answer in answers:
    for i in answer:
        foods[i - 1] = foods[i - 1] + 1

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

print(ans)

Submission status: Accepted

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

dct = {}
for i in range(1, M+1):
  dct[i] = 0
for i in range(N):
  lst = list(map(int, input().split()))
  for j in lst[1:]:
    dct[j] += 1
ans = 0

for v in dct.values():
  if (v == N):
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
N,M = list(map(int,input().split(' ')))
konomi = []
for i in range(N):
  K,*A =list(map(int,input().split(' ')))
  konomi.append(A)
  
#import numpy as np
#print(konomi)
#konomi = sum(konomi,[])
n = konomi[0]
for i in konomi:
  x = set(i) & set(n)
  n = x
  
print(len(x))

Submission status: Accepted

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

se = set(range(m+1))
for _ in range(n):
    lst = [int(i) for i in input().split()]
    se &= set(lst[1:])
answer = len(se)
print(answer)

Submission status: Accepted

Solution code:
def abc():
    n, m = map(int, input().rstrip().split())
    fav = {}
    for i in range(n):
        f = list(map(int, input().rstrip().split()))
        for x in f[1:]:
            fav[x] = fav.get(x, 0) + 1
    print(len([k for k, v in fav.items() if v == n]))


abc()