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 =[list(map(int, input().split())) for i in range(N)]
#print(a)
list_ = set([i+1 for i in range(M)])
#print(list_)

for j in range(N):
    list_ &= set(a[j][1:])
    #print(list_)

if len(list_) !=0:
    print(len(list_))
else:
    print(0)

Submission status: Accepted

Solution code:
N,M = tuple(map(int,input().split()))
import numpy as np
like_array = np.zeros((N,M))
for i in range(N):
    _in_ =list(map(int,input().split()))
    K =_in_[0]
    A = _in_[1:]
    for j in A:
        like_array[i,j-1] = 1
print(int(np.sum(np.prod(like_array,axis=0))))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import numpy as np
N, M = (int(i) for i in input().split())
KA = [list(map(int, input().split())) for _ in range(N)]
# print(N, M)
# print(KA)
# print(list(range(1, N+1)))
count_list = [0] * M

for A in KA:
    for a in A[1:]:
        # print(a)
        count_list[a-1] += 1
print(np.sum((np.array(count_list) / N)==1))

Submission status: Accepted

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

k = []
list = [0] * m
for i in range(n):
  line = [int(item) for item in input().split()]
  for item in range(m):
    if (item+1) in line[1:]:
      list[item] += 1

num = 0
for item in list:
  if item == n:
    num+=1

print(num)

Submission status: Accepted

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

Submission status: Accepted

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

count = 0
for k in ans:
  if k == N:
    count += 1
print(count)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
D = []
for i in range(1, N + 1):
    ni = [int(_) for _ in input().split()]
    ni = ni[1:]
    D.extend(ni)
E =[]
for j in range(1, M + 1):
    if D.count(j) == N:
        E.append(j)
print(len(E))

Submission status: Accepted

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

food = [0] * (M+1)

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

ans = 0
for f in food:
    if f == N:
        ans += 1
print(ans)

Submission status: Accepted

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

N, M = [int(x) for x in input().split()]
ls =[]
for _ in range(N):
    foodlist = [int(x) for x in input().split()]
    ls += foodlist[1:]

answer = 0
for M  in range(M):
    if ls.count(M +1) == N:
        answer += 1

print (answer)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
a=[input().split() for i in range(N)]
count=0
b=[0 for i in range(M+1)]#1~Mの食べ物の個数→b[1]~b[M]
for i in range(N):
    for j in range(1,len(a[i])):#a[i][1]~a[i][len-1]
        b[int(a[i][j])]+=1
for i in range(1,M+1):
    if b[i]==N:
        count+=1
print(count)

Submission status: Accepted

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

count = [0]*M

for i in range(N):
    k = list(map(int,input().split()))
    k = k[1:]
    for kk in k:
        count[kk-1]+=1
total = 0
for l in count:
    if l ==  N:
        total += 1
print(total)

Submission status: Accepted

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

i_like_these = input().split()
everyone_likes_these = set(i_like_these[1::])
for n in range(N-1):
    n_likes_these = input().split()
    n_likes_these = n_likes_these[1::]
    everyone_likes_these &= set(n_likes_these)

print(len(everyone_likes_these))

Submission status: Accepted

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

Submission status: Accepted

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

B=[0]*(M+1)

for i in range(0,N):
  A=list(map(int,input().split(" ")))
  #print(A)
  for j in range (1,A[0]+1):
    jj=A[j]
    B[jj]+=1
    
#print (B)
print (B.count(N))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
Al=[list(map(int,input().split()))[1:] for _ in range(N)]
V=[[False]*M for _ in range(N)]
for row, As in enumerate(Al):
    for A in As:
        V[row][A-1]=True
print(sum([all(f) for f in zip(*V)]))

Submission status: Accepted

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

Submission status: Accepted

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

for k_a in K_A:
    for a in k_a[1:]:
        result[a-1] -= 1

print(sum(map(lambda x: x == 0, result)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=[]
for i in range(N):
  B=list(map(int,input().split()))
  B.remove(B[0])
  A.append(B)
C=[]
for j in range(N):
    C+=A[j]
D=0
for k in range(M):
    if C.count(k+1)==N:
        D+=1
print(D)

Submission status: Accepted

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

inp = input().split(" ")
inp.remove(inp[0])
for i in inp:
  likeNum.append(i)

for n in range(0,N-1):
  inp = input().split(" ")
  inp.remove(inp[0])
  nextInp = []
  for i in inp:
    if i in likeNum:
      nextInp.append(i)
  likeNum = nextInp

print(len(likeNum))

Submission status: Accepted

Solution code:
def ans():
  N, M = map(int,input().split())
  A = [list(map(int,input().split())) for _ in range(N)]
  d = {}
  cnt = 0
  for a in A:
    for j in range(1,a[0]+1):
      if(a[j] in d):
        d[a[j]] += 1
      else:
        d[a[j]] = 1
      if(d[a[j]] == N):
        cnt += 1
  print(cnt)
ans()

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
dic_ = {}
for _ in range(n):
    a = list(map(int, input().split()))
    a = a[1:]
    for i in a:
        if i in dic_:
            dic_[i] += 1
        else:
            dic_[i] = 1

ans = 0
for i in dic_.keys():
    if dic_[i] == n:
        ans += 1

print(ans)

Submission status: Accepted

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

count_list = []
for x in e:
    count_list += x[1:]

result = 0
for i in range(m):
    if count_list.count(i+1) == n:
        result += 1

print(result)

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:
# https://atcoder.jp/contests/abc118/tasks/abc118_b
n, m = [int(x) for x in input().split()]
a = []
r = set(_ for _ in range(1, m + 1))
for _ in range(n):
    k = [int(x) for x in input().split()][1:]
    a.append(k)
for t in a:
    r &= set(t)
print(len(r))

Submission status: Accepted

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

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

for i in range(N-1):
  L = list(map(int, input().split()))
  S = S & set(L[1:])

print(len(S))

Submission status: Accepted

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

count = [0] * m
for i in range(n):
    k = list(map(int, input().split()))
    k = k[1:]
    for kk in k:
        count[kk - 1] += 1
total = 0
for c in count:
    if c == n:
        total += 1
print(total)

Submission status: Accepted

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

ref = [i+1 for i in range(M)]
LIKE = [i+1 for i in range(M)]

for i in range(N):
    myLIKE = list(map(int,input().split()[1:]))
    for j in ref:
        try:
            if j not in myLIKE:
                LIKE.remove(j)
        except ValueError:
            pass
            
print(len(LIKE))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
row = []
count = [0]*m
ans = 0
for it in range(n):
	row.append(list(map(int,input().split())))
# print(row)
# print(count)
for it in range(n):
	for mc in row[it][1:]:
		count[mc-1] += 1
		if count[mc-1] == n:
			ans += 1
# print(count)
print(ans)

Submission status: Accepted

Solution code:
def foods_loved_by_everyone(N: int, M: int, KA: list) -> int:
    loved = [0] * M

    for ka in KA:
        for a in ka[1:]:
            loved[a-1] += 1

    return sum([1 for l in loved if l == N])


if __name__ == "__main__":
    N = 0
    N, M = [int(s) for s in input().split()]
    KA = [[int(s) for s in input().split()] for _ in range(N)]
    ans = foods_loved_by_everyone(N, M, KA)
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce
import collections
n, m = map(int, input().split())
a = reduce(lambda a, b: a + b, [input().split()[1:] for _ in range(n)])
c = collections.Counter(a)
print(len([a for a in c.values() if a == n]))

Submission status: Accepted

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

R = set(range(1, M+1))

for _ in range(N):
	k, *A = map(int, input().split())
	R     = R & set(A)

print(len(R))

Submission status: Accepted

Solution code:
import sys

N,M = map(int,input().split())
member = dict()
for i in range(1,N+1,1):
    ilist = list(map(int,input().split()))
    ilist.pop(0)
    member[i]=set(ilist)

match_set=member[1]

for i in range(2,N+1,1):#memberに対し、1人ずつ検査していく
    match_set = match_set & member[i]

print(len(match_set))

Submission status: Accepted

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

sumamry = [0] * M
for vec in vectors:
    ans = vec[1:]
    for a in ans:
        sumamry[a-1] += 1

ret = 0
for s in sumamry:
    if s == N:
        ret += 1

print(ret)

Submission status: Accepted

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

sumamry = [0] * 30
for vec in vectors:
    ans = vec[1:]
    for a in ans:
        sumamry[a-1] += 1

ret = 0
for s in sumamry:
    if s == N:
        ret += 1

print(ret)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
k = []
a = []
ans = 0
for i in range(N):
    templist = list(map(int,input().split()))
    k.append(templist[0])
    a.append(templist[1:])

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

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
N, M = [int(x) for x in stdin.readline().rstrip().split()]
l = []
m = []
for i in range(N):
    l.append(stdin.readline().rstrip().split())
    l[i].pop(0)
k = l[N-1]
for i in range(N-1):
    k = set(k)&set(l[i])
print(len(k))

Submission status: Accepted

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

# listのINNER JOINを繰り返して、最後にlistの要素数を返す
list_1st = input().split()[1:]

for i in range(N-1):
  list_tmp = input().split()[1:]
  # list_1st = list(set(list_1st) & set(list_tmp))
  list_1st = [x for x in list_1st if x in list_tmp]

if N == 1:
  print(len(list_1st))
else:
  l_output = [i for i in list_1st if i != ' ']
  print(len(l_output))

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, raw_input().split())

result = [0]*M

for i in range(N):
  foods = map(int, raw_input().split())
  pers_count = foods.pop(0)
  
  for f in foods:
    result[f-1] += 1

res_count = 0
for r in result:
  if N == r:
    res_count += 1

print res_count

Submission status: Accepted

Solution code:
N, M = map(int, input().split(' '))
cands = None
for _ in range(N):
  items = set(list(map(int, input().split(' ')))[1:])
  if cands is None:
    cands = items
    continue
  else:
    cands &= items
  
  if len(cands) == 0:
    break
print(len(cands))

Submission status: Accepted

Solution code:
N, M = map(int, input().rstrip().split(' '))
m = {}
for i in range(N):
    row = list(map(int, input().rstrip().split(' ')))
    for j in range(row[0]):
        k = row[1 + j]
        if k in m:
            v = m[k]
            m[k] = v + 1
        else:
            m[k] = 1


num = 0
for v in m.values():
    if v == N:
        num = num + 1


print(num)

Submission status: Accepted

Solution code:
N,M = [int(x) for x in input().split()]
ans = 0
fd = [0] * (M + 10)
for i in range(N):
  x, *xs=[int(x) for x in input().split()]
  for j in xs:
    fd[j] += 1
print(len(list(filter(lambda x: x == N, fd))))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
count = dict(zip(range(1, m+1), [0]*m))
for _ in range(n):
    ka = list(map(int, input().split()))
    for a in ka[1:]:
        count[a] += 1

ans = sum([1 for k, v in count.items() if v == n])
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

num, kind = map(int, input().split())
foodList = list(range(1, kind+1))

for i in range(num):
    inputList = list(map(int, input().split()))
    inputList.pop(0)
    foodList = list(set(inputList) & set(foodList))

print(len(foodList))

Submission status: Accepted

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

cnt = [None] + [0] * M
for _ in range(N):
  line = list(map(int, input().split()))
  for a in line[1:]:
    cnt[a] += 1

answer = 0
for c in cnt[1:]:
  if c == N:
    answer += 1
print(answer)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
answer = set([])
for i in range(N):
  K_A = [int(x) for x in input().split()]
  K = K_A[0]
  A = K_A[1:]
  if i==0:
    answer = answer.union(set(A))
  else:
    answer = answer.intersection(set(A))

print(len(answer))

Submission status: Accepted

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

intersection = None

for _ in range(N):
  nth_list = list(map(int, input().split()))
  nth_list = nth_list[1:]
  nth_set = set(nth_list)
  if intersection is None:
    intersection = nth_set
  else:
    intersection &= nth_set
print(len(intersection))

Submission status: Accepted

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

for i in range(N):
    a,*b = map(int,input().split())
    list &= set(b)

print(len(list))

Submission status: Accepted

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

for k in range(N):
    L = list(map(int,input().split()))
    for e in range(L[0]):
        M[L[1+e]-1] += 1
ans = 0
for e in M:
    if e == N:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

N, M = list(map(int, input().split(' ')))
mat = np.zeros((N, M))
for i in range(N):
  lines = list(map(int, input().split(' ')))
  for j in range(lines[0]):
    mat[i, lines[j+1]-1] += 1

mat_common = np.min(mat, axis=0)
result = np.sum(mat_common)
print(int(result))

Submission status: Accepted

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

count = 0

for i in range(1,M+1):
  flg = True
  for list in list_list:
    if i in list[1:]:
      continue
    else:
      flg = False
      break
  if flg == True:
  	count += 1
print(count)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = set(range(1, m+1))
for _ in range(n):
    _, *ai = map(int, input().split())
    a = a & set(ai)

print(len(a))

Submission status: Accepted

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

for i in range(N-1):
	a = list(map(int,input().split()))
	a.pop(0)
	list_ = set(a) & set(list_)

print(len(list_))

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
q=[input() for i in range(n)]
l=[i+1 for i in range(m)]
l1=[i+1 for i in range(m)]
for i in q:
  t=list(map(int, i.split()))
  for k in l1:
    if (k not in t[1:]):
      if k in l:
      	l.remove(k)
print(len(l))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
foods = set(input().split()[1:])
for i in range(N - 1):
    temp = set(input().split()[1:])
    foods = foods & temp
print(len(foods))

Submission status: Accepted

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

def foods(n, k):
    if n == 1:
        return len(k[0]) - 1

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

        next = k[i+1][1:]
        comb = []    

        for j in init[:]:
            if j in next:
                comb.append(j)
        init = comb[:]

    return len(comb)

print(foods(n, k))

Submission status: Accepted

Solution code:
from collections import Counter
N, M = map(int, input().split())
flags = [True for i in range(M)]
for i in range(N):
    l = list(map(int, input().split()))
    l.pop(0)
    for j in range(M):
        if j + 1 not in l:
            flags[j] = False

print(flags.count(True))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = [int(i) for i in input().split()]
counter = [0 for i in range(M)]
count = 0
A = []
for i in range(N):
  A.append([int(i) for i in input().split()])
  A[i] = A[i][1:]
  for a in A[i]:
    counter[a - 1] += 1

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

print(count)

Submission status: Accepted

Solution code:
I=lambda:list(map(int,input().split()))
n,m=I()
from collections import defaultdict
d = defaultdict(int)
for i in range(n):
  a,*b=I()
  for j in b:
    d[j]+=1
print(sum(1 for i in d.values() if i==n))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

ans_List = [1 for i in range(M)]
for i in range(N):
    for j in range(M):
        if j+1 not in A[i][1:]:
            ans_List[j] = 0
ans = 0
for i in ans_List:
    ans += i

print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
m = 0
for i in range(M):
    m += 2**i
for n in range(N):
    k = list(map(int, input().split()))
    k_n = k[0]
    _m = 0
    for i in range(k_n):
        _m ^= 2**(k[i+1]-1)
    m &= _m
ret = bin(m).count("1")
print(ret)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

for i in range(m,1):
    dic[i] = 0


for _ in range(n):
    arr = list(map(int, input().split()))

    for item in arr[1:]:

        if item in dic:
            dic[item] += 1
        else:
            dic[item] = 1

ans = 0
for count in dic.values():
    if count == n:
        ans += 1

print(ans)

Submission status: Accepted

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

    for idx in a:
        D[idx-1] += 1

print(D.count(n))

Submission status: Accepted

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

a = list(map(int,input().split()))
N = a[0]
M = a[1]
cnt = [0,]*(M+1)
ans = 0
for i in range(N):
    K, *like, = readline().split()
    K = int(K)
    like = [int(s) for s in like]
    for j in range(K):
        cnt[like[j]] += 1
for i in range(1, M+1):
    if cnt[i] == N:
        ans += 1
print(str(ans))

Submission status: Accepted

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

for people in survey:
    del people[0]
    food = food & set(people)

print(len(food))

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
    L=[int(i) for i in input().split()]
    S=S&set(L[1:])
print(len(list(S)))

Submission status: Accepted

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

D = [0] * M

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

    for idx in a:
        D[idx-1] += 1

print(D.count(N))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
st = {i+1 for i in range(m)}
for i in range(n):
  a=list(map(int,input().split()))
  del a[0]
  sa=set(a)
  st=st&sa
print(len(st))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
for i in range(n):
    k=[int(j) for j in input().split()]
    t=set([k[j+1] for j in range(k[0])])
    if i==0: l={j for j in t}
    else: l=l&t
print(len(l))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for key in a_dict:
    if a_dict[key] == N:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
c=set(list(range(1,m+1)))#from 1 to m+1 set {}
#print(c)
for i in range(n):
    l=list(map(int,input().split()))
    a=l[1:]
    #l[0] no mean
    c=c & set(a) # and > & 
    #print(c)
print(len(c))

Submission status: Accepted

Solution code:
import sys
 
lines = sys.stdin.read().rstrip().split("\n")
n, m = [int(x) for x in lines[0].split(" ")]
 
result = set(lines[1].split(" ")[1:])
 
if len(lines) == 2:
  print(len(result))
else:
  for x in lines[2:]:
    result = result & set(x.split(" ")[1:])
  print(len(result))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=set([i+1 for i in range(m)])
for i in range(n):
    k=[int(j) for j in input().split()]
    t=set([k[j+1] for j in range(k[0])])
    l=l&t
print(len(l))

Submission status: Accepted

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

from collections import defaultdict
fav = defaultdict(int)
for i in range(N):
    KA = list(map(int, input().split()))
    for i in range(1, KA[0]+1):
        fav[str(KA[i])] += 1

ans = 0
for i in fav.keys():
    if fav[i] == N:
        ans += 1
print(ans)

Submission status: Accepted

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

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

print(len(food_set))

Submission status: Accepted

Solution code:
import sys

(sn, sm) = sys.stdin.readline().split()
n = int(sn)
m = int(sm)

flg = [0 for j in range(m)]
for i in range(n):
  sa = sys.stdin.readline().split()
  if len(sa) > 1:
    for saj in sa[1:]:
      aj = int(saj)
      flg[aj - 1] += 1

suma = 0
for sumaj in flg:
  if sumaj == n:
    suma += 1
print(suma)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

L = defaultdict(int)
for i in range(N):
	KA = list(map(int, input().split()))
	for j in range(KA[0]):
		L[KA[1 + j]] += 1

for i in range(1, M + 1):
	if L[i] == N:
		c += 1

print(c)

Submission status: Accepted

Solution code:
import sys
import collections

a=[]
l = map(int, raw_input().split())
for n in range(l[0]):
    x = map(int, raw_input().split())
    a.extend(x[1:])

c = collections.Counter(a)
values, counts = zip(*c.most_common())
print(counts.count(l[0]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
Fm = [0]*M
KA = [list(map(int, input().split())) for _ in range(N)]
for n in range(N):
  #KA = list(map(int, input().split()))
  for i in range(KA[n][0]):
    Fm[KA[n][i+1]-1] += 1
ans = 0
for m in range(M):
  if Fm[m] == N:
    ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N, M = map(int,input().split())
kinds = np.zeros(M)
for _ in range(N):
    inputs = input().split()
    K = inputs[0]
    A = inputs[1:]
    for a in A:
        kinds[int(a)-1] += 1
N = len(kinds[np.where(kinds==N)])
print(N)

Submission status: Accepted

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

S = set()

for i in range(N):
  A = list(map(int, input().split()))
  wS = set(A[1::])
  if i == 0:
    S = wS
  else:
    S = S & wS #S.intersection(wS)
    
print(len(S))

Submission status: Accepted

Solution code:
import numpy as np
n, m = map(int, input().split())

cnt = np.array([0 for x in range(m + 1)])

for i in range(n):
    a = list(map(int, input().split()))[1:]
    cnt[a] += 1
print(np.sum(cnt >= n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N,M=map(int,input().split())
A=np.zeros((N+1,M+1))
A[0]=np.ones(M+1)
for i in range(1,N+1):
    B=list(map(int,input().split()))
    for m in range(1,B[0]+1):
        A[i][B[m]]=A[i-1][B[m]]
a=sum(A[N])
print(int(a))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# ｎとｍの取得
data = input().split()
n = int(data[0]) #n == 人数
m = int(data[1]) #m == 数字の種類
ans = 0
#ｎ回データを取得してカウント

j = 1 #j == 好きな数字
i = 1 #i == 行数カウンタ
c = [0] * (m + 1)#c == ある数が含まれているかのカウンタ　0で初期化
    #データの取得

while i <= n:
    tmp = [int(s) for s in input().split()]
    td = tmp[1:] #td == 好きな番号
    tn = tmp[0]  #tn == 好きな番号の数
    
    # 数字が含まれているかの比較
    while j <= m: # jがすべての数字について実行
        
        if j in td: # jがｔｄに含まれるかの分岐
            j = int(j) #　ｊを数値に戻す
            
            c[j] += 1 # ｃのｊ番目の要素にカウント
        j = int(j) #if ではじかれたとき用にｊを数値に戻す
        j += 1# ｊをカウント
    j = 1    
    i += 1 # iをカウント

# 全てに含まれている数字の集計

for x in c:
    if x == n:
        ans += 1



print(ans)

Submission status: Accepted

Solution code:
# ｎとｍの取得
data = input().split()
n = int(data[0]) #n == 人数
m = int(data[1]) #m == 数字の種類
ans = 0
#ｎ回データを取得してカウント

j = 1 #j == 好きな数字
i = 1 #i == 行数カウンタ
c = [0] * (m  *2)#c == ある数が含まれているかのカウンタ　0で初期化
    #データの取得

while i <= n:
    tmp = [int(s) for s in input().split()]
    td = tmp[1:] #td == 好きな番号
    tn = tmp[0]  #tn == 好きな番号の数
    
    # 数字が含まれているかの比較
    while j <= m: # jがすべての数字について実行
        
        if j in td: # jがｔｄに含まれるかの分岐
            j = int(j) #　ｊを数値に戻す
            
            c[j] += 1 # ｃのｊ番目の要素にカウント
        j = int(j) #if ではじかれたとき用にｊを数値に戻す
        j += 1# ｊをカウント
    j = 1    
    i += 1 # iをカウント

# 全てに含まれている数字の集計

for x in c:
    if x == n:
        ans += 1



print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
print(len(set.intersection(*[set(s.split()[1:])for s in open(0).readlines()[1:]])))

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    n, m = [int(x) for x in input().strip().split(' ')]
    hyp = set()
    for i in range(n):
        line = [int(x) for x in input().strip().split(' ')]
        if i == 0:
            hyp = set(line[1:])
            continue
        hyp = hyp.intersection(set(line[1:]))
    print(len(hyp))