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:
# from math import factorial,sqrt,ceil
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
n,m = map(int,input().split())
ansset = set(range(1,m+1))

times = n
table = []
for _ in range(times):
    table.append(list(map(int,input().split()))) # 行列の場合

for lis in table:
    ansset = ansset & set(lis[1:])

print(len(ansset))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Accepted

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

H=[0]*N
for i in range(N):
    K,*H[i],=map(int,input().split())

ans=M
j=1
while j<=M:
    for x in H:
        if j not in x:
            ans-=1
            break
    j+=1

print(ans)

Submission status: Accepted

Solution code:
n,m = map(int, input().split(' '))
List = [i+1 for i in range(m)]

i = 0
while i < n:
    k_list = list(map(int, input().split(' ')))
    lcopy = List[:]
    for l in lcopy:
        if l not in k_list[1:]:
            List.remove(l)
            #print(l,List)
    i += 1
print(len(List))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = [0]*M
ans = 0
for i in range(N):
  k = list(map(int,input().split()))
  for j in range(1,len(k)):
    A[k[j]-1] += 1
for i in range(len(A)):
  if A[i] == 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)]
y=0
if n!=1:
    for i in range(m):
        x=0
        for j in range(n):
            if i+1 in a[j][1:a[j][0]+1]:
                x+=1
            else:
                x+=0
        if x==n:
            y+=1
    print(y)
else:
    for i in range(2,a[0][0]+1):
        if a[0][1]!=a[0][i]:
            y+=1
    print(y+1)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
M=[0]*31
for i in range(n):
    a=[int(_) for _ in input().split()]
    for j in range(a[0]):
        M[a[j+1]]+=1

print(M.count(n))

Submission status: Accepted

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

favorite=set(list(range(1,m+1)))

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

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 cnt:
  ans += (i == n)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, raw_input().split())
like = [0] * m
for _ in xrange(n):
    for a in map(int, raw_input().split())[1:]:
        like[a - 1] += 1
print sum(c == n for c in like)

Submission status: Accepted

Solution code:
p,q= input().split()
a,b =(int(p), int(q))
ans_list = []
for i in range(a):
    a_list = input().split()
    ans_list.append(a_list)
ans = 0
for i in range(b+1):
    count = 0
    for j in range(a):
        if str(i)in ans_list[j][1:]:
            count +=1
    if count == a:
        ans +=1
        
print(ans)

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

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

ans = []

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

print(len(ans))

Submission status: Accepted

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def main():
    n, m = MII()
    food = set(MII()[1:])
    for i in range(n-1):
        a = MII()[1:]
        food &= set(a)
    print(len(food))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n,m = iim()
l = set(range(1,m+1))

for i in range(n):
    A = set(iil()[1:])
    l = l&A

print(len(l))

Submission status: Accepted

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

temp_l = [0]*M

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = list(map(int,input().split()))
a = list(map(int,input().split()))
a.pop(0)
ans = a
for i in range(N-1):
    a = list(map(int,input().split()))
    a.pop(0)
    x = set(a) & set(ans)
    ans = list(x)
print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

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

counter = 0

for i in range(1, 31):
  for j in range(n):
    judge = False
    for k in range(1, len(List[j])):
      if List[j][k] == i:
        judge = True
    if not judge:
      break
  if judge:
  	counter += 1
      

print(counter)

Submission status: Accepted

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

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

print(ans.count(1))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=[int(i) for i in input().split()]
l=l[1:]
for i in range(n-1):
  s=[int(j) for j in input().split()]
  s=s[1:]
  ln=[]
  for le in l:
    if le in s:
      ln.append(le)
  l=ln
print(len(l))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#ABC-118-B
N, M = map(int, input().split())
memo = [0]*(M+1)

for _ in range(N):
    Ki, *A = map(int, input().split())
    for item in A:
        memo[int(item)] += 1

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

print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
like = []
for i in range(n):
    like.append(set(list(map(int, input().split()))[1:]))
work = like[0]
for el in like[1:]:
    work = work & el
print(len(work))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
# int(input()) # 入力が1つ
n, m = map(int, input().split()) # 入力が複数
d = []
for _ in range(n):
    food = set(input().split()[1:])
    d.append(food)

s = d[0]
for i in range(n):
    s = s & d[i]
print(len(s))

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,m = LI()
cnt = [0]*m
for i in range(n):
    query = LI()
    for j in query[1:]:
        cnt[j-1] += 1
ans = 0
for i in cnt:
    if i == n:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
def main():
  n,m = map(int,input().split())
  OK = [0] * m + [0]
  cnt = 0
  while True:
    try:
      LIST = list(map(int,input().split()))
      k = LIST[0]
      A = LIST[1:]
      for i in range(k):
        OK[A[i]] += 1
    except:
      break
  #print(OK)
  for i in range(m + 1):
    if OK[i] == n:
      cnt += 1
    else:
      pass
  print(cnt)
  
  
  
  
if __name__ == '__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
S = set(range(1, m + 1))
for _ in range(n):
    ignore, *A = map(int, input().split())
    S &= set(A)
print(len(S))

Submission status: Accepted

Solution code:
import collections
n, m = map(int, input().split())
a_list = sum([list(map(int, input().split()))[1:] for _ in range(n)], [])
col = collections.Counter(a_list)
print(len([k for k, v in col.items() if v == n]))

Submission status: Accepted

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

K = []
A = []
for _ in range(N):
    tmp = list(map(int,input().split()))
    K.append(tmp[0])
    A += tmp[1:]
    #A.append(tmp[1:])
#print(sorted(A))
cnt = 0
for i in range(1,M+1):
    #print(A.count(i))
    if(A.count(i) == N):
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
def main():
  #n = int(input())
  #s = input()
  #s = input().split()
  n,m = list(map(int,input().split()))
  #a = [input() for i in range(n)]
  #a = [int(input()) for i in range(n)]
  #a = [input().split() for i in range(n)]
  a = [list(map(int,input().split())) for i in range(n)]
  ans = 0
  count = 0
  lis = [0]*m
  
  for i in range(n):
    for k in range(1,a[i][0]+1):
      lis[a[i][k]-1] += 1
  print(lis.count(n))  
if __name__ == '__main__':
  main()

Submission status: Accepted

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

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

print(m.count(n))

Submission status: Accepted

Solution code:
# abc118_b.py
N, M = map(int,input().split())
A = []
ans_list = [0]*(M+1)
ans = 0
for i in range(N):
    _,*a = list(map(int,input().split()))
    A.append(a)
for i in A:
    for j in i:
        ans_list[j] += 1
for i in ans_list[1:]:
    if i == N:
        ans += 1
print(ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

a = list(map(int, input().split()))
del a[0]
a = set(a)
ref = a

for i in range (n - 1):
    a = list(map(int, input().split()))
    del a[0]
    a = set(a)
    ref = ref & a

print(len(ref))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
KA=[]
for _ in range(N):
    KA.append(list(map(int, input().split())))
#print(N, M, KA)
KA=[set(val[1:]) for val in KA]
#print(KA)
for val in KA:
    KA[0]=KA[0].intersection(val)
#print(KA[0])
print(len(KA[0]))

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])
ans = 0
for j in range(M):
    if X.count(j+1) == N:
        ans += 1
print(ans)

Submission status: Accepted

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

import numpy as np

food_list = np.zeros(m)

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

print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
m = [i + 1 for i in range(M)]
for j in range(N):
  K = list(map(int, input().split()))
  n = K[0] + 1
  m = [K[k] for k in range(n) if k != 0 and (K[k] in m)]
print(len(m))

Submission status: Accepted

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

Submission status: Accepted

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

loves = {}
for i in range(N):
    for j in range(1, A[i][0]+1):
        love = A[i][j]
        if love in loves:
            loves[love] += 1
        else:
            loves[love] = 1

print( len(list(filter( lambda x: loves[x] == N, loves ))))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
foods_likes = [0] * M
for _ in range(N):
    survey_result = list(map(int, input().split()))
    k = survey_result[0]
    a = survey_result[1:]
    for i in range(k):
        foods_likes[a[i] - 1] += 1
ans = 0
for likes in foods_likes:
    if likes == N:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

# print(lists)

like_food = {}
for i in range(N):
    for j in range(len(lists[i])):
        j = lists[i][j]
        if j not in like_food.keys():
            like_food[j] = 1
        elif j in like_food.keys():
            like_food[j] += 1
# print(like_food)

count = 0
for i in like_food.values():
    if i == N:
        count += 1
    else:
        continue

print(count)

Submission status: Accepted

Solution code:
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

def main():
    N, M = map(int, input().split())
    counter = Counter()
    for _ in range(N):
        K, *A = map(int, input().split())
        counter += Counter(A)
    print(sum(1 for c in counter.values() if c == N))

main()

Submission status: Accepted

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

surveys = []

for i in range(N):
    z = [int(i) for i in input().split()]
    surveys.append(z[1:])

joint_surveys = []

for i in surveys:
    joint_surveys = joint_surveys + i

res = []

for i in range(1, M+1):
    if joint_surveys.count(i) == N:
        res.append('x')

print(len(res))

Submission status: Accepted

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

K = []
A = []
ans = 0

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

for i in range(1, M+1):
    c = 0
    for a in A:
        if i in a:
            c += 1

    if c == N:
        ans += 1

print(ans)

Submission status: Accepted

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

a = set([i + 1 for i in range(M)])
for n in range(N):
    A = list(map(int, input().split()))
    K = A.pop(0)
    a &= set(A)
print(len(a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n,m=INTM()
    alist=[]
    for i in range(n):
        ka=LIST()
        ka.pop(0)
        ka=set(ka)
        alist.append(ka)
    for i in range(n-1):
        alist[n-1]=alist[n-1]&alist[i]
    print(len(alist[n-1]))
if __name__ == '__main__':
    do()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
INF = 10**10
MOD = 10**9 + 7
sys.setrecursionlimit(100000000)
from functools import lru_cache
from itertools import permutations

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


if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
K=[0]*N
A=[[0] for _ in range(N)]
for i in range(N):
  tmp = list(map(int,input().split()))
  K[i]=tmp[0]
  A[i]=set(tmp[1:])
  
for j,item in enumerate(A):
  if j==0:
    ans=A[j]
    #print(j,ans)
  else:
    ans=ans.intersection(item)
    #print(j,ans)
    
print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

n, m = map(int, input().split())
a = []
for _ in range(n):
    k, *a_ = map(int, input().split())
    a.extend(a_)

d = Counter(a)
ans = [k for k, v in d.items() if v == n]
print(len(ans))

Submission status: Accepted

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

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

for c in list_score:
    ans = ans & set(c[1:])

print(len(ans))

Submission status: Accepted

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

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

c = 0
for i in range(M):
    like[i] -= N


for i in range(M):
    if like[i] == 0:
        c += 1

print(c)

Submission status: Accepted

Solution code:
N,M = map(int,input().split(" "))
List = [0]*M
for i in range(N):
    LIst = [int(i)-1 for i in input().split(" ")]
    for l in LIst[1:]:
        List[l]+=1
count = 0
for i in List:
    if i==N:
        count+=1
print(count)

Submission status: Accepted

Solution code:
import numpy as np
n,m = list(map(int,input().split()))
t = np.zeros(m,dtype=int)
count = 0
for i in range(n):
    a = list(map(int,input().split()))
    for j in range(1,a[0]+1):
        t[a[j]-1]+=1
for i in range(m):
    if t[i] == n:
        count+=1
print(count)

Submission status: Accepted

Solution code:
n,m = map(int, input().split( ))
bit = (1<<m)-1
for i in range(n):
    _, *a, = map(int, input().split( ))
    tmp = 0
    for aj in a:
        tmp |= 1<<(aj-1)
    bit &= tmp



ans = 0
for i in range(m):
   if (bit>>i)&1:
       ans += 1
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
like = [0] * (M + 1)
for _ in range(N):
    KA = list(map(int, input().split()))
    for i in range(1, len(KA)):
        like[KA[i]] += 1
like.sort(reverse=True)
ans = 0
for i in range(M + 1):
    if like[i] == N:
        ans += 1
    else:
        break
print(ans)

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

Submission status: Accepted

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

cnt = [0]*M
W = [0]*N
for i in range(N):
    W[i] = list(map(int, input().split()))
    for k in range(1, W[i][0]+1):
        cnt[W[i][k]-1] += 1
ans = cnt.count(N)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

s = set(range(1, M+1))
for i in range(N):
    s = s & set(W[i][1:])
ans = len(s)
print(ans)

Submission status: Accepted

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

base=[N]*M

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
k = set(input()[2:].split())

for i in range(n-1):
    k = k & set(input()[2:].split())
    
print(len(k))

Submission status: Accepted

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

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

    ans = 0

    ans_list = [0] * m

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
ans = 0
que = []
for i in range(n):
    a = list(map(int,input().split()))
    que.append(a[1::])
for i in range(1,m+1):
    flag = True
    for j in range(n):
        if i not in que[j]:
            flag = False
    if flag:
        ans += 1
print(ans)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

for i in range(1, m + 1):
    flg = True
    for j in range(n):
        if i not in ka[j]:
            flg = False
            break
    if flg:
        ans += 1
print(ans)

Submission status: Accepted

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

sum=0
for i in range(1,m+1):
    flg=True
    for j in range(n):
        if i not in l[j]:
            flg=False
            break
    if flg==True:
        sum+=1
print(sum)

Submission status: Accepted

Solution code:
import collections
N, M = map(int, input().split())
ans = collections.defaultdict(int)
for i in range(N):
  tmp = list(map(int, input().split()))
  tmp = tmp[1:]
  for j in tmp:
    ans[j]+=1
  
maxnum = max(ans.values())
if maxnum == N:
  anslist = [kv[0] for kv in ans.items() if kv[1] == maxnum]
  print(len(anslist))
else:
  print(0)

Submission status: Accepted

Solution code:
ii=lambda:int(input())
miis=lambda:map(int,input().split())
lmiis=lambda:list(map(int,input().split()))

n,m=miis()

k=lmiis()
st=set(k[1:])

for i in range(n-1):
  ki=lmiis()
  st=st&set(ki[1:])

print(len(st))

Submission status: Accepted

Solution code:
def main():
    n, m = map(int, input().split())
    kas = [list(map(int, input().split())) for _ in range(n)]
    question_dict = {i: 0 for i in range(1, m+1)}
    ans = 0

    for ka in kas:
        a = ka[1:]
        for i in a:
            question_dict[i] += 1

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

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

foods = [0] * m

for ans in answers:
    for a in ans[1:]:
        foods[a-1] += 1

cnt = 0
for x in foods:
    if x == n:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
#ABC118B
N,M=map(int,input().split())
food=[1]*(M+1)
for _ in range(N):
    q=list(map(int,input().split()))
    q=q[1:]
    for item in range(M+1):
        if item not in q:
            food[item]=0
print(sum(food))

Submission status: Accepted

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

for i in range(N-1):
    a = set(l[i])&set(l[i+1])
    l[i+1] = a
if N==1:
  print(len(l[0])) 
else:
  print(len(a))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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