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())
common = set(range(1, m+1))
for _ in range(n):
    a = list(map(int, input().split()))
    common&=set(a[1:])
print(len(common))

Submission status: Accepted

Solution code:
# B - Foods Loved by Everyone

N, M = map(int, input().split())
F = [0] * (M+1)

for i in range(N):
    KA = list(int(x) for x in input().split())
    for j in range(1, len(KA)):
        F[KA[j]] += 1

print(F.count(N))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
A=list(map(int,input().split()))
A=A[1:]
for i in range(n-1):
    sub=A
    temp=list(map(int,input().split()))
    A=[]
    for j in range(0,len(sub)):
        if sub[j] in temp[1:]:
            A.append(sub[j])
print(len(A))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
lists=[list(map(int,input().split())) for x in range(n)]
ans=[0]*m
for x in range(n):
  k=lists[x][0]
  for t in range(k):
    ans[lists[x][t+1]-1]+=1
count=0
for y in range(m):
  if ans[y]==n:
    count+=1
print(count)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n,m=MI()
ans=0
vote=[0 for i in range(m)]
likes=[]
for i in range(n):
    likes.append(LI())
#print(likes)
for j in range(len(likes)):
    for k in range(1,len(likes[j])):
        #print(likes[j][k])
        vote[likes[j][k]-1]+=1
#print(vote)
for v in vote:
    if v==n:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
import copy
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.pop(0)
for i in range(n-1):
  t=list(map(int,input().split()))
  k=t.pop(0)
  b=copy.deepcopy(a)
  for j in range(0,len(a)):
    if not b[j] in t:
      a.remove(b[j])
print(len(a))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
K=[]
ans=0
for _ in range(N):
  K+=input().split()[1:]
S=set(K)
for s in S:
  if K.count(s)==N:
    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):
  K,*A=map(int,input().split())
  S&=set(A)
print(len(S))

Submission status: Accepted

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

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

for i in range(n):
    for j in range(ka[i][0]):
        ans[ka[i][j+1]-1]+=1
print(ans.count(n))

Submission status: Accepted

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

cnt = [0]*(m+1)

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

print(cnt.count(n))

Submission status: Accepted

Solution code:
import numpy as np
import sys

input = sys.stdin.readline

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

cnt = [1]*(M+1)
cnt[0] = 0

res = M
for _ in range(N):
    a = list(map(int,input().split()))
    a = a[1:]
    for x in range(1,M+1):
        if x not in a and cnt[x] == 1:
            cnt[x] = 0
            res-=1

print(res)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import collections
n, m = map(int, input().split())
l = []
ans = 0
for _ in range(n):
    l.extend(list(map(int, input().split()))[1:])
c = collections.Counter(l)
for k in c:
    if c[k] == n: ans += 1
print(ans)

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
A = set({i for i in range(1,m+1)})
for i in range(n):
    row = list(map(int, input().split()))
    k = row[0]
    A_i = row[1:]
    A = A & set(A_i)
print(len(list(A)))

Submission status: Accepted

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


for i in range(n):
  A = list(map(int,input().split()))
  
  for j in range(1,A[0]+1):
    Al[A[j]] += 1

print(Al.count(n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = []
for _ in range(N):
    *S, = map(int, input().split())
    A.append(S[1:])
unique_number = A[0]
for a in A[1:]:
    unique_number = set(unique_number) & set(a)
print(len(unique_number))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
A=[]
c=0
for i in range(n):
    a=list(map(str,input().split()))
    a.pop(0)
    A=A+a
for i in range(1,31):
    if A.count(str(i))==n:
        c+=1
print(c)

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
p = []
for i in range(n):
    p.append(list(map(int,input().split())))
s = set()
for i in range(p[0][0]):
    s.add(p[0][i+1])

for i in range(1,n):
    kar = set()
    for j in range(p[i][0]):
        kar.add(p[i][j+1])
    s = s & kar

print(len(s))

Submission status: Accepted

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

print(cnt)

Submission status: Accepted

Solution code:
import collections


def solve():

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

    a = []
    for i in range(N):
        tmp = list(map(int, input().split()))
        # 先頭のKは除外
        a += tmp[1:]

    # Counter({3: 3, 1: 2, 2: 2})になる
    c = collections.Counter(a)
    ans = 0
    for val in c.values():
        # 個数が一致したらプラス
        if val == N:
            ans += 1

    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Accepted

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

ans = set(K[0])
for ki in K[1:]:
    ans = ans.intersection(ki)

print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(n)] #n行にmつずつ入力される整数
ans_li = list(range(1, m+1))
for l in li:
    ans_li = set(ans_li) & set(l[1:])
print(len(ans_li))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
all = {int(i) for i in range(1, m + 1)}
for _ in range(n):
    k, *i_th = map(int, input().split())
    all &= set(i_th)
print(len(all))

Submission status: Accepted

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

l = list()

for a in range(0, N):
    L = list(map(int, input().split()))
    L.pop(0)
    l.append(L)

count = [0]*(M)

for a in l:
    for b in a:
        count[b-1] += 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#template
def inputlist(): return [int(k) for k in input().split()]
#template
N,M = inputlist()
ans = [0]*(M+1)
c =0
for i in range(N):
    A = inputlist()
    K = A[0]
    Aa = A[1:]
    for j in range(K):
        ans[Aa[j]] +=1
for i in range(1,M+1):
    if ans[i] == N:
        c+=1
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N,M=map(int, input().split())
tabelist = np.zeros(M)
for i in range(N):
  c=list(map(int, input().split()))
  for k in range(1,c[0]+1):
    tabelist[c[k]-1] = tabelist[c[k]-1] + 1
#    print(i,k,tabelist)
print(len([1 for x in tabelist if x==N]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

answer_set=set(range(1,M+1))
for i in range(N):
  k,*alist=map(int,input().split())
  answer_set&=set(alist)
  
print(len(answer_set))

Submission status: Accepted

Solution code:
import sys
import numpy as np
input = sys.stdin.readline
n,m= map(int,input().split())
A = [input().split() for i in range(n)]

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

Submission status: Accepted

Solution code:
from collections import deque, Counter
N, M = map(int, input().split())

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

ans = list(L[0][1:len(L[0])])
for i in range(N - 1):
    for j in range(L[i][0]):
        if L[i][j + 1] in L[i + 1][1:L[i + 1][0] + 1]:
            ans.append(L[i][j + 1])

c = Counter(ans)
count = 0
for k, v in c.items():
    if (v == N):
        count += 1
    else:
        continue
print(count)

Submission status: Accepted

Solution code:
def Foods_Loved(n, m, kal):

    ans = 0

    for i in range(1, m+1):
        flag = True
        for ka in kal:
            if i not in ka[1:]:
                flag = False
        if flag:
            ans += 1

    return ans

def main():
    n, m = map(int, input().split())
    kal = [list(map(int, input().split())) for i in range(n)]
    print(Foods_Loved(n, m, kal))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

c = Counter(a)

ans = 0
for k, v in c.most_common():
    if v == n:
        ans += 1
    else:
        break
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
MOD = 10**9+7

def main():
    N, M = map(int, readline().split())
    S = set(i for i in range(1,M+1))
    for _ in range(N):
        S &= set(list(map(int, readline().split()))[1:])
    print(len(S))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

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

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

count = 0
for i in range(len(t)):
    if t[i] == n:
        count += 1
print(count)

Submission status: Accepted

Solution code:

n,m = map(int,input().split())
t = [0]*m
s = []

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

count = 0

for i in range(len(t)):
    if t[i] == n:
        count += 1

print(count)

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
answer = set(range(1, M+1))
for _ in range(N):
    k, *A = lr()
    s = set(A)
    answer &= s

print(len(answer))

Submission status: Accepted

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

favorites = set(KA[0])
for KAi in KA:
    favorites = favorites & set(KAi)

number_of_common_favorites = len(favorites)

print(number_of_common_favorites)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
X=[0]*M
for i in range(N):
  K,*A=list(map(int,input().split()))
  for a in A:
    X[a-1]+=1
ans=0
for x in X:
  if x==N:
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    ans = [1] * M
    for _ in range(N):
        A = list(map(lambda x: int(x) - 1, input().split()))[1:]
        for a in range(M):
            if a not in A:
                ans[a] = 0
    print(sum(ans))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

k, *a = [int(i) for i in input().split()]

a = set(a)

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

Submission status: Accepted

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

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


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

print(count)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
lst = [0] * M
for i in range(N):
  s = input().rstrip().split(' ')
  num = int(s[0])
  for j in range(1, num+1):
    lst[int(s[j])-1] += 1
length = len(lst)
count = 0
for k in range(length):
  if lst[k] == N:
    count += 1
print(count)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ans = [0 for _ in range(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:
n, m = map(int, input().split())
servey = []
for i in range(n):
    k_a = list(map(int, input().split()))
    servey.append(k_a)
for j in servey:
    del j[0]
loves = []
for x in range(1, m+1):
    count = 0
    for y in servey:
        if x in y:
            count+=1
        loves.append(count)
food_count = 0     
for z in loves:
    if z == n:
        food_count += 1

print(food_count)

Submission status: Accepted

Solution code:
from collections import Counter
n,m = map(int,input().split())
input_lines = [int(j) for i in range(n) for j in input().split()[1:]]

menu_dic = Counter(input_lines)
print(sum(value==n for key,value in menu_dic.items()))

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
n_list = list(map(int,input().split()))[1:]

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


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

    N, M = il()
    R = [set(il()[1:]) for _ in range(N)]
    ret = R[0]
    for r in R:
        ret &= r
    print(len(ret))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

d = [0]*m
for _ in range(n):
    flag = True
    for a in map(int, input().split()):
        if flag:
            flag = False
            continue
        d[a-1] += 1

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
ans = []
l = []
for i in range(n):
    if i == 0:
        ans = list(map(int,input().split()))
        ans.pop(0)
    else:
        l = list(map(int,input().split()))
        l.pop(0)
        ans = set(ans) & set(l)
print (len(ans))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
k = []
a = []
while True:
  try:
    tmp = list(map(int,input().split()))
    k.append(tmp[0])
    a.append(tmp[1:])
  except:
    break

counter = [0]*m
for i in a:
  for j in i:
    counter[j-1] +=1

ans = counter.count(n)
print(ans)

Submission status: Accepted

Solution code:
icase=0
if icase==0:
    n,m=map(int,input().split())
#    ki,aset=int(input()),set(map(int,input().split()))
    lista=list(map(int,input().split()))
    ki=lista[0]
    aset=set(lista[1:])
    for i in range(1,n):
        lista=list(map(int,input().split()))
        ki=lista[0]
        a=set(lista[1:])
        aset=aset & a
    print(len(aset))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    answer = [[0]*M for n in range(N)]
    for i in range(N):
        K, *A = map(int, input().split())
        for a in A:
            answer[i][a-1] = 1
    count = 0
    for j in range(M):
        same = 0
        for i in range(N):
            same += answer[i][j]
        if same == N:
            count += 1
    print(count)
main()

Submission status: Accepted

Solution code:
import collections
N,M=map(int,input().split())
a=[]
for _ 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())

li = [0] * M

for i in range(N):
    K = list(map(int, input().split()))
    for j in range(1, len(K)):
        li[K[j]-1] += 1

print(li.count(N))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC 118: B – Foods Loved by Everyone
N, M = [int(s) for s in input().split()]
tmp = [[int(s) for s in input().split()] for _ in range(N)]
a = [tmp[i][1:] for i in range(N)]

kind = 0

for i in range(1, M + 1):
    everyone = True

    for j in range(N):
        if i not in a[j]:
            everyone = False
            break

    if everyone:
        kind += 1

print(kind)

Submission status: Accepted

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

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

ss = Counter(s)

ans = []
for k, v in ss.items():
  if v == n:
    ans.append(k)
    
print(len(ans))

Submission status: Accepted

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

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

    for j in A:
        a[j-1] -= 1


count = 0
for i in a:
    if i == 0:
        count += 1

print(count)

Submission status: Accepted

Solution code:
# solution

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

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    cnts = [0 for _ in range(M)]
    for _ in range(N):
        A = list(map(int, input().split()))
        K = A.pop(0)
        for a in A:
            cnts[a-1] += 1
    
    ans = cnts.count(N)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

answer = len(se)
print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque,Counter
N,M = map(int,input().split())
A = []
for i in range(N):
  KA = deque(list(map(int,input().split())))
  KA.popleft()
  A += KA
A = Counter(A)
values, counts = zip(*A.most_common())

print(counts.count(N))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [[int(x) for x in input().split()] for y in range(N)]
ans = set(int(z) for z in range(1, 31))
for i in range(N):
    A[i].pop(0)
    ans = ans & set(A[i])
print(len(ans))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
l = list()
for i in range(N):
    la = [int(x) for x in input().split()]
    for j in range(1, la[0] + 1):
        l.append(la[j])

ans = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def myAnswer(N:int,M:int,K:list,A:list) -> int:
   kinds = [0 for i in range(M)]
   total = 0
   for a in A:
      for k in a:
         kinds[k-1]+=1
   for kind in kinds:
      if(kind == N):
         total+=1
   return total



def modelAnswer():
   tmp=1
def main():
   N,M = map(int,input().split())
   K =[]
   A = []
   for _ in range(N):
      tmp = list(map(int,input().split()))
      K.append(tmp.pop(0))
      A.append(tmp)
   print(myAnswer(N,M,K,A))

if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:
from collections import Counter
N, M = map(int,input().split())
cnt = [0 for _ in range(M+1)]
for _ in range(N):
    Q = list(map(int,input().split()))
    for i in Q[1:]:
        cnt[i] += 1
d = Counter(cnt)
print(d[N])

Submission status: Accepted

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

print(ary.count(N))

Submission status: Accepted

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

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

print(ans.count(n))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
surveys = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(1, M+1):
    flag = True
    for survey in surveys:
        if i not in survey[1:]:
            flag = False
            break
    if flag:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def i(): return list(map(int, input().split()))
l = [set(i()[1:]) for _ in range(i()[0])]
print(len(l[0].intersection(*l[1:])))

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,food[0]+1):
    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())

likes = set(range(1, M + 1))
for _ in range(N):
    A = list(map(int, input().split()[1:]))
    likes = likes.intersection(set(A))

print(len(likes))

Submission status: Accepted

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

foods = []
for i in range(m): foods.append(True)

for i in range(n):
    k = list(map(int, input().split()))
    k.pop(0)
    for j in range(1,m+1):
        if j not in k: foods[j-1] = False

print(foods.count(True))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = list()
favorite = {i+1: 0 for i in range(m)}
for i in range(n):
    x = list(map(int, input().split()))
    a.append(x)

for i in a:
    for j in i[1:]:
        favorite[j] += 1

ans = 0

for i in favorite.values():
    if i == n:
        ans += 1

print(ans)

Submission status: Accepted

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

print(like.count(N))

Submission status: Accepted

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

k0 = list(map(int, input().split()))
k0.pop(0)
le = len(k0)
aut = []

for i in range(n-1):
    ka = list(map(int, input().split()))
    ka.pop(0)
    for j in range(le):
        num = k0[j]
        if num not in ka:
            aut.append(num)

print(le-len(set(aut)))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
dict = {i:True for i in range(1, m+1)}
ans = 0

for i in range(n):
    _, *a = map(int, input().split())
    for j in range(1, m + 1):
        if j not in a:
            dict[j] = False

for i in range(1, m + 1):
    if dict[i]:
        ans += 1

print(ans)

Submission status: Accepted

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