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:
import copy
N,M = map(int, input().split())
isFirst = True
like_list_all = []

for i in range(N):
    like_list = input().split()
    del like_list[0]
    if isFirst:
        like_list_all = copy.copy(like_list)
        isFirst = False
        continue
    like_list_all = list(set(like_list_all) & set(like_list))

print(len(like_list_all))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 16 20:52:33 2019

@author: Owner
"""


import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
import copy

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

"""
N, X = map(int, input().split())

x = [0]*N
x[:] = map(int, input().split())

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())
    
all(nstr.count(c) for c in '753')

ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
#A, B, totAB = zip(*ABT)


(x >> i) & 1

"""

N, M = map(int, input().split())
cnt_res = [0]*M
for n in range(N):
    KA =[]
    KA = list(map(int, input().split()))
    K = KA.pop(0)
    for m in range(K):
        num = KA[m]
        cnt_res[num-1] += 1
print(cnt_res.count(N))

Submission status: Accepted

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

for _ in range(n):
    lik = list(map(int,input().split()))
    del lik[0]
    lik.sort()
    li.append(lik)

count = 0
for i in range(1,m+1):
    flag = True
    for j in range(n):
        if i in li[j]:
            pass
        else:
            flag = False
    if flag:
        count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

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

cnt = 0
for k in range(0, m + 1):
    if foods[k] == n:
        cnt = cnt + 1
print(cnt)

Submission status: Accepted

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

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()))
    for j in range(tmp[0]):
        ans[tmp[j+1]-1]+=1
        
now = 0
        
for i in range(M):
    if ans[i]==N:
        now+=1
        
print(now)

Submission status: Accepted

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

TALL = list(range(1,M+1))

for i in range(N):
  A = list(map(int,input().split()))
  del A[0]
  NTALL = []
  for k in TALL:
    if k in A:
      NTALL.append(k)
    else:
      NTALL.append(0)
  TALL = NTALL

TALL = [i for i in TALL if not i==0]
print(len(TALL))

Submission status: Accepted

Solution code:
import numpy as np

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

KA=[] # K,Aの行列
number = 0; # 食べ物の種類数
# 好きな食べ物カウント
like = np.zeros(M)

while True:
    try:
        KA.append(list(map(int,input().split())))
    except:
        break;

for i in KA:
    i.pop(0)

for i in range(M+1):
    if sum(x.count(i) for x in KA) == N:
        number+=1

print(number)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
people, foods = input().split()
people, foods = int(people), int(foods)

all_like = []
for i in range(people):
  a = input().split()
  num = int(a[0])
  like_str = a[1:]
  like = [int(j) for j in like_str]
  all_like += like
 
output = 0
for food in range(foods):
  if all_like.count(food+1) == people:
    output += 1
print(output)

Submission status: Accepted

Solution code:
def make_list(list,num):
    count_list=[0]*(num+1)
    #print(count_list)
    #print(num)
    for x in list:
        for y in x:
            count_list[y]+=1
    answer=count_list.count(len(list))
    return answer


# スペース区切りの整数の入力
a,b = map(int, input().split())
# 文字列の入力
like_list=[]
for x in range(a):
    input_list = list(map(int, input().split()))
    del input_list[0]
    like_list.append(input_list)
#print(like_list)
s=make_list(like_list,b)
# 出力
print(s)

Submission status: Accepted

Solution code:
a,b = input().split(" ")
a,b = int(a),int(b)
list = []
list2 = []
for i in range(a):
  list += input().split(" ")[1:]
list = [int(i) for i in list]
list2 = []
for i in range(b+1):
  if list.count(i) == a:
    list2.append(i)
print(len(list2))

Submission status: Accepted

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

answer = 0
for i in range(N):
    a.append(list(map(int, input().split())))

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

print(answer)

Submission status: Accepted

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

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

Submission status: Accepted

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

    for n in A[i]:
        if not n == 0:
            like[n-1] += 1
print(like.count(N))

Submission status: Accepted

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

food_set = set(A[0])
for i in range(N):
    food_set = food_set & set(A[i])
    
print(len(food_set))

Submission status: Accepted

Solution code:
import sys

def main(inp):
    n,m=map(int,next(inp).split())
    
    count=[0 for _ in range(m)]
    
    for i in range(n):
        result=list(map(int,next(inp).split()))
        for j in range(1,len(result)):
            count[result[j]-1]+=1

    ans=0
    for i in range(m):
        if(count[i]==n):
            ans+=1
    
    return ans
    
print(main(sys.stdin))

Submission status: Accepted

Solution code:
""" AtCoder"""

N, M = map(int, input().split())
KA = [list(map(int, input().split())) for _ in range(N)]

l = []
for i in range(M+1):
    l.append(0)

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

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

print(ans)

Submission status: Accepted

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

tmp = []

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


ans = 0

for j in range(31):
    flg = 1
    for k in range(n):
        if not j in tmp[k][1:tmp[k][0]+1]:
            flg = 0
    if flg == 1:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split())) # 整数
answer=[]
a = []
food_list=[]
for i in range(N):
    answer=list(map(int, input().split()))
    if i==0:
        food_list=answer[1:]
    else:
        like_food=[]
        for food in answer[1:]:
            if (food in like_food)==False:
                if (food in food_list)==True:
                    like_food.append(food)
        food_list=like_food
print(len(food_list))

Submission status: Accepted

Solution code:
answerers, num_foods = map(int, input().split(' '))
favorites = []

for i in range(answerers):
  current_ans = list(map(int, input().split(' ')))
  favorites.extend(current_ans[1:])

res = [ favorites.count(food) == answerers for food in list(set(favorites)) ]
print(res.count(True))

Submission status: Accepted

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

for i in range(n):
    del P[i][0]
    
K = set(P[0])
L = {}
for i in range(1,n):
    L = set(P[i])
    K = K & L
print(len(K))

Submission status: Accepted

Solution code:
import copy
N,M = [int(i) for i in input().split()]
l=[]
for i in range(N):
    tmp = [int(j) for j in input().split()]
    l.append(tmp)

for i in range(N):
    if i == 0:
        nokori_food = copy.deepcopy(l[0][1:])
    else:
        nokori_food_next = []
        for j in nokori_food:
            for k in l[i][1:]:
                if j==k:
                    nokori_food_next.append(k)
        nokori_food = copy.deepcopy(nokori_food_next)
print(len(nokori_food))

Submission status: Accepted

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

N, M = map(int, input().split())
ans = set(range(1, M+1))
for i in range(N):
    test_set = set(list(map(int, input().split()))[1:])
    ans = ans.intersection(test_set)
print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = []
b = []
a = list(map(int,input().split()))
del a[0]
for i in range(n-1):
  c = list(map(int,input().split()))
  del c[0]
  for j in range(len(a)):
    if a[j] not in c:
      a[j] = "#"
print(len(a) - a.count("#"))

Submission status: Accepted

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

ans = 0
k = []

for i in range(1,M+1):
    k.append(i)
for i in range(N):
    for j in range(1,M+1):
        if j not in ka[i][1:] and j in k:
            k.remove(j)
print(len(k))

Submission status: Accepted

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

K = [[int(i) for i in input().split()] for i in range(N)]

sekishugo = set(range(1,M+1))
for k in range(N):
  new_set = set(K[k][1:])
  sekishugo = sekishugo & new_set
  
print(len(sekishugo))

Submission status: Accepted

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

sum = 0
countList = [0] * (m+1)

for i in range(n):
    l = list(map(int, input().split()))

    for j in range(1, len(l)):
        countList[l[j]] += 1

for k in countList:
    if k == n:
        sum += 1

print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(food.count(N))

Submission status: Accepted

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

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

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

count = 0
for a in ans:
	if a == n:
		count += 1
print(count)

Submission status: Accepted

Solution code:
a,b= map(int,input().split())
arr = [0]*b

for x in range(a):
    te = list(map(int,input().split()))
    K = te[0]
    if a != 1:
        for p in range(K):
            arr[te[p+1]-1] += 1
    else:
        arr = list(set(te[1:len(te)]))
h = max(arr)

if h == a:
    print(arr.count(h))
elif a == 1:
    print(len(arr))
else:
    print(0)

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
data = []
for i in range(N):
    if i == 0:
        list_KA = list(map(int,input().split()))
        list_KA.pop(0)
    else:
        list_A = list(map(int,input().split()))
        list_A.pop(0)
        list_KA.extend(list_A)
l = set(list_KA)
ans = 0
for x in l:
    c = list_KA.count(x)
    if N == c:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter

n,m = list(map(int, input().split()))
ls = []
for i in range(n):
  a = list(map(int, input().split()))
  del a[0]
  for j in range(len(a)):
    ls.append(a[j])
#print(ls)

c = Counter(ls)
b = [k[0] for k in c.items() if k[1] == n]
#print(b)
print(len(b))

Submission status: Accepted

Solution code:
import numpy as np

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


fav_list = np.arange(1, M + 1)

for i in range(N):
    result_list = list(map(int,input().split()))
    del result_list[0]
    fav_list = np.intersect1d(fav_list, result_list)
    
print(fav_list.size)

Submission status: Accepted

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

import sys

def main():
    sp = [int(e) for e in sys.stdin.readline().split(" ")]
    n = sp[0]
    m = sp[1]

    M = [0] * m

    for l in sys.stdin:
        for e in [int(e) for e in l.strip().split(" ")][1:]:
            M[e-1] += 1

    i = 0
    for e in M:
        if e == n:
            i+=1

    print(i)

main()

Submission status: Accepted

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

Submission status: Accepted

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

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

d = {i+1:0 for i in range(M)}
for k in K:
    for i in range(1, len(k)):
        d[k[i]] += 1

ans = 0
for m in d.values():
    if m == N:
        ans += 1

print(ans)

Submission status: Accepted

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

li = []
for i in range(n):
    x = map(int,input().split())
    li.append(list(x)[1:])
#    print(li)


sumnum = 0 
for i in range(1, m+1):
    num = 0 
    for j in range(n):
        if i not in li[j]:
            num=0
            break
        num = 1 

    if num == 1:
        sumnum+=1
print(sumnum)

Submission status: Accepted

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

for i in range(n):
    k=list(map(int,input().split()))
    for j in range(1,m+1):
    
        if fav[j]==1:
        

            if j not in k[1:]:
                
                fav[j]=0

print(sum(fav)-1)

Submission status: Accepted

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

m = set([x for x in range(1, M + 1)])

for i in range(N):
    K, *A = [int(x) for x in input().split()]
    m &= set(A)

print(len(m))

Submission status: Accepted

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

ary = []
f_num = 0

for j in range(M+1):
    ary.append(0)

for i in range(N):
    L = map(int, raw_input().split())
    L.pop(0)
    for vote in L:
        ary[vote] = ary[vote] +1

for k in ary:
    if k == N:
        f_num = f_num + 1

print f_num

Submission status: Accepted

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

Submission status: Accepted

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

S = [0]*M

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

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

print(count)

Submission status: Accepted

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

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

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

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

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

print(judge)

Submission status: Accepted

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

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

count = 0
for j in range(m):
    flag = True 
    for i in range(n):
        if A[i][j] == 0:
            flag = False 
    if flag:
        count += 1

print(count)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
foods = set(range(1, m+1))
for i in range(n):
  opinion = set(list(map(int, input().split()))[1:])
  match = foods & opinion
  if match:
    foods = match
  else:
    foods = set()
    break
print(len(foods))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
people_num, food_num = [int(n) for n in input().split()]
_, *fav_foods = [int(n) for n in input().split()]
fav_foods = set(fav_foods)

for p in range(1, people_num):
    _, *favs = [int(n) for n in input().split()]
    favs = set(favs)
    fav_foods = {f for f in fav_foods if f in favs}

print(len(fav_foods))

Submission status: Accepted

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

Submission status: Accepted

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

k =[]
for i in range(n):
    k1 = [int(i) for i in input().split()]
    k.append(k1)

num = [0]*m

for i in k:
    for j in range(len(i)):
        if j != 0:
            num[i[j]-1] +=1


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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

e = [[int(i) for i in input().split()] for i in range(n)] 

marray = [0] * m
count = 0

for i in e:
    for j in i[1:]:
        marray[j-1] += 1

for i in marray:
    if i == n:
        count += 1

print(count)

Submission status: Accepted

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

K1 = list(map(int, input().split()))
del K1[0]
hat = set(K1)

for i in range(NM[0]-1):
    tmp = list(map(int, input().split()))
    del tmp[0]
    hat = hat & set(tmp)

print(len(hat))

Submission status: Accepted

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

if __name__ == '__main__':
    N, M = map(int, input().split(' '))

    likes = set([int(c) for c in input().split(' ')][1:])
    for _ in range(N - 1):
        likes = likes & set([int(c) for c in input().split(' ')][1:])
    print(len(likes))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
# import bisect
# import math
# import numpy as np


"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x//y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def d(self, p):
        re = 0
        for i in range(len(p) - 1):
            re += ((p[i][0] - p[i + 1][0]) ** 2 + (p[i][1] - p[i + 1][1]) ** 2) ** 0.5
        return re


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    n, m = ip.IL()
    res = [[False for _ in r(m)] for _ in r(n)]

    for i in r(n):
        o = ip.IL()
        for j, x in e(o):
            if j == 0:
                pass
            else:
                j -= 1
                res[i][x-1] = True

    ans = 0
    for i in r(m):
        rr = 0
        for j in r(n):
            if res[j][i]:
                rr += 1
        if rr == n:
            ans += 1

    print(ans)


main()

Submission status: Accepted

Solution code:
import numpy as np

def input_numbers():
    temp = list(map(int, input().split()))
    return temp

temp = input_numbers()

n = temp[0]
m = temp[1]

like = []
for i in range(n):
    like += [input_numbers()]

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

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

count = 0

for i in ls:
    if(i == n):
        count += 1

print(count)

Submission status: Accepted

Solution code:
k, m = map(int, input().split())
for i in range(k):
  ans = list(map(int, input().split()))
  ans.pop(0)
  if i == 0:
    same = ans
  else:
    ans_set = set(ans)
    same_set = set(same)
    same = list(ans_set & same_set)
print('{}'.format(len(same)))

Submission status: Accepted

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

x = set()

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

Submission status: Accepted

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

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 ni in range(n):
    temp = [int(i) for i in input().split()]
    s &= set(temp[1:])

print(len(s))

Submission status: Accepted

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

like = {}

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

    K = foods.pop(0)

    for food in foods:
        if food in like:
            like[food] += 1
        else:
            like[food] = 1

count = 0;

for numOfLike in like.values():

    if numOfLike == N:
        count += 1

print(count)

Submission status: Accepted

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

i = 0
inter_set = set(KA[0][1:])
for line in KA:
  tmp_lst = []
  for j in range(1,line[0]+1):
    tmp_lst.append(KA[i][j])
  inter_set = inter_set & set(tmp_lst)
  i+=1
print(len(inter_set))

Submission status: Accepted

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

A=[]
for i in range(N):
	A.append(map(str, raw_input().split()))


score=0
for i in range(M):
	point_tmp=0
	for j in range(N):
		if str(i+1) in A[j][1:]:
			point_tmp+=1
	if point_tmp==N:
		score+=1

print score

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
c = []
for i in range(a):
  *s, = map(int, input().split())
  c += s[1:]
count=[]
e = c[:]
d=list(set(c))

for i in d:
  if e.count(i) == a:
    count.append(i)
    
print(len(count))

Submission status: Accepted

Solution code:


N,M = input().split()
N = int(N) 
all_foods_bags = [input().split() for i in range(N)] 


for i, foods_bags in enumerate(all_foods_bags):
    foods_bags.pop(0)
    all_foods_bags[i] = foods_bags

 
for i, foods_bags in enumerate(all_foods_bags):
    if i == 0:
        original_food_set = set(foods_bags)
    
    else:
        original_food_set = original_food_set & set(foods_bags)

print(len(original_food_set))

Submission status: Accepted

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

Submission status: Accepted

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

l = [0] * (m+1)

for i in range(n):
    ip = [int(j) for j in input().split()]
    ip.pop(0)
    for j in ip:
        l[int(j)] += 1
        
print(l.count(n))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(b.count(n))

Submission status: Accepted

Solution code:
from sys import stdin
n, m = [int(x) for x in stdin.readline().rstrip().split()]
data = [stdin.readline().rstrip().split() for _ in range(n)]
res = data[0]
res.pop(0)
if n > 1:
    for i in range(1, n):
        re = data[i]
        re.pop(0)
        res = list(set(re) & set(res))
print(len(res))

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
n = []
for i in range(N):
    A = [int(x) for x in input().split()]
    for j in range(1,len(A)):
        n.append(A[j])

B = list(set(n))
ans = sum(n.count(x) >= N for x in B)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
number=list(map(int,input().split()))
likes=[]
result=0
for i in range(number[0]):
    rawdata=list(map(int,input().split()))
    for k in range(rawdata[0]):
        likes.append(rawdata[k+1])
for i in range(number[1]):
    if likes.count(i+1)==number[0]:
        result+=1
print(result)

Submission status: Accepted

Solution code:
man,food = map ( int ,input().split())
num = set(range(food+1))
for i in range(man) :
    a = list ( map ( int  , input().split ()))
    del a[0]
    a = set (a)
    num = num & a
print (len (num) )