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:
s,m=map(int,input().split())
l=[]
for _ in range(s):
  n=[]
  n=list(map(int,input().split()))
  n.pop(0)
  l=l+n
m=dict()
for i in l:
  if i in m:
    m[i]+=1
  else:
    m[i]=1
cnt=0
for j in m:
  if m[j]==s:
    cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
N,M = map(int, input().split(' '))
ret = {}

for n in range(N):
  p = input().split(' ')
  for k in range(int(p[0])):
    key = p[int(k)+1]
    if key in ret:
      ret[key] += 1
    else:
      ret[key] = 1

print(list(ret.values()).count(N))

Submission status: Accepted

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

for i in range(N):
    scan = input().split()
    for x in range(1, len(scan)):
        nums[int(scan[x])] += 1

ans = 0
for i in nums:
    if nums[i] == N:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/2/16
Solved on 2019/2/16
@author: shinjisu
"""


# ABC 118
def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def getIntLines(n): return [int(input()) for i in range(n)]


def getIntMat(n):
    mat = []
    for i in range(n):
        mat.append(getIntList())
    return mat


def zeros2(n, m): return [zeros(m)]*n


def dmp(x):
    global debug
    if debug:
        print(x)
    return x


def probB():
    N, M = getIntList()
    A = getIntMat(N)
    dmp((N, M))
    dmp(A)
    food = set([])
    food = set(A[0][1:])
    dmp(food)
    for i in range(N):
        food2 = set(A[i][1:])
        food = food & food2
        dmp(food)
    return len(food)


debug = False  # True False
print(probB())


def probC():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    return 123


def probD():
    N = getInt()
    A = getIntList()
    dmp((N, A))
    return 123


def probA():
    A, B = getIntList()
    dmp((A, B))
    if B % A == 0:
        return A+B
    else:
        return B-A

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
a = list(map(int, input().split()))
K_past = a[0]
A_past = a[1:]
  

for n in range(1,N):
  a = list(map(int, input().split()))
  l = []
  K = a[0]
  A = a[1:]
  
  for i in range(K):
    if A[i] in A_past:
      l.append(A[i])
  A_past = l
    
print(len(A_past))

Submission status: Accepted

Solution code:
#
import sys
import math
import numpy as np
import itertools


# いくつか入力
n,m = (int(i) for i in input().split())  
# n行複数列の数をリストに
k = [[int(i) for i in input().split()] for i in range(n)] 

# print(k)
answer = 0
a = [1]*m
#print(a)
for i in range(n):
    b = [0]*m
    for j in range(1,k[i][0]+1):
        b[k[i][j]-1]=1
    for j in range(m):
        if b[j] == 0:
            a[j] = 0



for i in range(m):
    answer += a[i]

print(answer)

Submission status: Accepted

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

print(sum([1 for x in foods if x == n]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import chain
n,m = map(int,input().split())
x = [list(map(int,input().split())) for i in range(n)]
for i in x:
    i.pop(0)
x = list(chain.from_iterable(x))
cnt = 0
for i in range(1,m+1):
    if x.count(i)==n:
            cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
"""
https://atcoder.jp/contests/abc118/tasks/abc118_b
"""

import numpy as np


def parse():
    N, M = list(map(int, input().split()))
    K = np.ones((N, ), dtype=np.int32) * -1
    A = np.ones((N, M), dtype=np.int32) * -1
    for i in range(N):
        tmp = list(map(int, input().split()))
        K[i] = tmp[0]
        A[i, 0:K[i]] = tmp[1:]
    return N, M, K, A


def solve(N, M, K, A):
    nlikes = np.zeros((M + 1,), dtype=np.int32)
    for i in range(N):
        nlikes[A[i, 0:K[i]]] += 1
    print(np.size(np.where(nlikes == N)))


if __name__ == '__main__':
    inputs = parse()
    solve(*inputs)

Submission status: Accepted

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

like = {}
for i in range(N):
    first=True
    for i in input().split():
        if first:
            first=False
            continue
        if i in like:
            like[i] += 1
        else:
            like[i] = 1

count = 0
for k in like:
    if like[k] == N:
        count += 1

print(count)

Submission status: Accepted

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

A = []
ans = 0
for i in range(N):
    a = [int(x) for x in input().split()]
    a.pop(0)
    A.append(a)

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

print(ans)

Submission status: Accepted

Solution code:
#n,mを入力
n,m = map(int, input().split())

#suki = [[1,3],[1,2,3]]
suki = []
for i in range(n):
    suki.append(list(map(int, input().split())))

cnt = 0
j = 1
for j in range(m+1):
    for k in range(n):
        if suki[k][1:].count(j) == 0:
            break

        if k == (n-1):
            cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import collections
n,m=map(int,input().split())
a = []
for i in range(n):
    b = list(map(int, input().split()))
    a.append(b)
c=[]
for i in range(n):
    c.extend(a[i][1:])
co=collections.Counter(c)
s=0
for i in range(m+1):
    if co[i]==n:
        s+=1
print(s)

Submission status: Accepted

Solution code:
import numpy as np
from collections import defaultdict

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

A = list()
cnt = 0
for i in range(N):
    a = [int(k) for k in input().split()] 
    #print(a[1:])
    A.append(set(a[1:]))
    pass
for i in range(M):
    i = i+1
    flag = True
    for a in A:
        s = set()
        s.add(i)
        if s <= a:
            pass
        else:
            flag = False
            break
        pass
    if flag == True:
        cnt += 1
    pass

print(cnt)

# a2,b2=map(int, input().split())  #
# a3,b3=map(int, input().split())  #





# import os.path
# import re
# from urllib.parse import quote



# p = "curl -kI https://kotobank.jp/word/" + quote("犬") + " -o header"
# print(p)
# req = os.system(p)
# f = open('header')
# tmp = f.read()  # ファイル終端まで全て読んだデータを返す
# hit_list = re.findall("Location:.*", tmp)
# print(hit_list[0])
# print(hit_list[0][10:])

# p = "curl -k https://kotobank.jp" + hit_list[0][10:] + " > raw.html"
# print(p)

# req = os.system(p)
# # print("aa")
# # p = "sed \":a;N;$!ba;s/\n//g\" raw.html > f "
# # req = os.system(p)
# # print("aa")
# # p = " sed -e 's/ //g' f > t"
# # req = os.system(p)
# # print("aa")


# print(req)
# f = open('raw.html')
# data1 = f.read()  # ファイル終端まで全て読んだデータを返す
# print(type(data1))
# # print((data1))
# data1 = data1.replace("\n", "")
# data1 = data1.replace(" ", "")
# data1 = data1.replace("\t", "")
# # print(data1)
# hit_list = re.search("<sectionclass=\"description\">.*</section></div><!--/.ex解説--><pclass=\"source\">", data1)
# # print("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww")
# # print(hit_list.group())
# # print("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww")

# t = hit_list.group()
# k = t.find('</section>')
# t = t[:k]
# # print(t)
# # print("wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww")

# t = re.sub("<[^>]*?>", "", t)
# print(t)


# # p = "cat raw.html > sed -e \"s/<section class=\"description\">(.|\n)*<\/section>/\1/"

# # req = os.system(p)

Submission status: Accepted

Solution code:
import collections

n, m = [int(s) for s in input().split()]

likes = []
for i in range(n):
    like = [int(s) for s in input().split()]
    likes.append(list(set(like[1:])))
# print(likes)

d = set(likes[0])
for like in likes:
    d = d.intersection(set(like))
print(len(d))
# anslist = [True for i in range(1, m+1)]

# for like in likes:
    
    # al = [False for i in range(1, m+1)]
    # for l in like:
    #     al[l] = True
    # for a in al:
    #     if a == False:
    #         anslist[a] = False
# print(anslist)

Submission status: Accepted

Solution code:
import numpy as np
a = input()
b = a.split()
N = int(b[0]) # num of people
M = int(b[0]) # num of food
list = []
list_new = []
s = input()
s = s.split()
K = int(s[0])
for i in range(1,K+1):
    list_new.append(int(s[i]))
for i in range(1,N):
    list = list_new
    list_new = []
    s = input()
    s = s.split()
    s = s[1:]
    for item in s:
        if int(item) in list:
            list_new.append(int(item))
        else:
            pass
print(len(list_new))

Submission status: Accepted

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

count=0
for i in range(M):
    count1=0
    for j in range(len(K)):
        if i+1 in K[j]:
            count1+=1
    if count1==len(K):
        count+=1

print(count)

Submission status: Accepted

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

for m in range(1,M+1):
    for k in K:
        if not m in k[1:]:
            break
    else :
        ans += 1

print(ans)

Submission status: Accepted

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

cnt = 0
for i in range(1,M+1):
    for j in range(N):
        # print(A[j][1:])
        if i not in A[j][1:]:
            break
    else:
        # print(i)
        cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    N, M = [int(i) for i in input().split()]
    dic = {}
    result = 0
    for i in range(N):
        favs = [int(i) for i in input().split()][1:]
        for food in favs:
            num = dic.get(food, 0)
            num += 1
            dic[food] = num
            if num == N:
                result += 1
    print(result)

Submission status: Accepted

Solution code:
N, M = map(int, input().split(" "))
data = []
for i in range(N):
  A = list(map(int, input().split(" ")))
  A_ = sorted(A[1:])
  data.append(A_)
  
counter = 0  
for m in range(M):
  flag = 1
  for d in data:
    if m+1 in d:
      flag *= 1
    else:
      flag *= 0
  if flag == 1:
    counter += 1

print(counter)

Submission status: Accepted

Solution code:
n, m = (int(x) for x in input().split())
lis = [0]*m
for i in range(n):
    tmp_lis = [int(x) for x in input().split()]
    del tmp_lis[0]
    for ii in tmp_lis:
        lis[ii-1] += 1
res = 0
for iii in lis:
    if iii == n:
        res += 1

print(res)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
food=[] #appendのために宣言が必要
for i in range(n):
    food.append(list(map(int,input().split())))

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

Submission status: Accepted

Solution code:

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


K = {}
for i in range(0, N):
    tmp_list =  list(int(i) for i in input().split())
    K[i] = tmp_list


# result = K[0][0]
foods_set = set(K[0][1:])
for i in range(1, N):
    foods_set = set(foods_set) & set(K[i][1:])
    result = len(foods_set)
    if(result == 0): 
        break

print(len(foods_set))

Submission status: Accepted

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

loved = []
for i in range(m):
    loved.append(0)
for i in range(n):
    for f in range(ans[i][0]+1):
        if f==0:
            continue
        loved[ans[i][f]-1] += 1

a = 0

for f in range(m):
    if(loved[f]==n):
        a += 1
print(a)

Submission status: Accepted

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

@author: doppe
"""

N, M = map(int, input().split())
likeList = []

for i in range(0, N):
    L = [int(i) for i in input().split()]
    likeListTmp = []
    if (i == 0):
        likeList = L[1 : L[0] + 1]
    else:
        for j in range(1, L[0] + 1):
            if (L[j] in likeList):
                likeListTmp.append(L[j])
        likeList = likeListTmp

print(len(likeList))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
K = list(map(int,input().split()))
K = K[1:]
for i in range(N-1):
  K_ = list(map(int,input().split()))
  K = list(set(K) & set(K_[1:]))

print(len(K))

Submission status: Accepted

Solution code:
import numpy as np
from sys import stdin
N,M=[int(x) for x in stdin.readline().rstrip().split()]
a=[]
for i in range(N):
    a.append([int(x) for x in stdin.readline().rstrip().split()])

res=set(list(range(1,M+1)))
for data in a:
  
  res=res&set(data[1:])
print(len(res))

Submission status: Accepted

Solution code:
# coding=utf-8

if __name__ == '__main__':
    N, M = map(int, input().split())
    set_list = [set(list(map(int, input().split()))[1:]) for i in range(N)]
    if len(set_list) == 1:
        print(len(set_list[0]))
    else:
        _intersect = set_list[0]
        for _set in set_list[1:]:
            _intersect = _intersect.intersection(_set)
        print(len(_intersect))

Submission status: Accepted

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

print(likes.count(N))

Submission status: Accepted

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

for _ in range(n):
    temp_left = []
    temps = list(map(int, input().split()))
    n = temps[0]
    # print(temps)
    for j in range(1, n+1):
        # print(temps[j])
        # print(left_foods)
        if temps[j] in left_foods:
            temp_left.append(temps[j])
    left_foods = temp_left
print(len(left_foods))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
i = 0
li = []
while i < N:
    try:
        li.append(list(map(int, input().split())))
    except:
        break
    i += 1

if 1 == len(li):
    del(li[0][0])
    print(len(li[0]))
else:
    temp = []
    for i in range(N):
        del(li[i][0])
        if i == 0:
            temp = list(set(li[i]) & set(li[i+1]))
        else:
            temp = list(set(li[i]) & set(temp))

    if temp:
        print(len(temp))
    else:
        print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
kekka=[]
for i in range(N):
    li=list(input().split())
    li=[int(s) for s in li]
    li=li[1::]
    #print(li)
    if i==0:
        base=li
    else:
        kekka.append(li)
count=1
summ=0
for j in base:
    for i in range(N-1):
        if j in kekka[i]:
            count+=1
        #print(count)
    summ+=count//N
    count=1
        #print(j,count)
print(summ)

Submission status: Accepted

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

    for j in range(setn[0]):
        box = setn[j+1]
        num[box] = num[box] + 1

for x in range(len(num)):
    if num[x] == n:
        sum += 1

        
print(sum,end="")

Submission status: Accepted

Solution code:
import fileinput


def algorithm(n, m, a):
    foods = set(a[0][1:])
    for f in a[1:]:
        foods &= set(f[1:])
    return len(foods)


def pass_inputs(input_lines):
    n, m = input_lines[0]
    return algorithm(n, m, input_lines[1:])


def convert_int(s):
    try:
        r = int(s)
    except ValueError:
        r = s
    return r


def run():
    out = pass_inputs([[convert_int(v) for v in l.strip().split(" ")] for l in fileinput.input()])
    print(out)


if __name__ == "__main__":
    run()

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve():
    pass
    '''初期値設定'''
    N, M = [int(i) for i in input().split()]
    food = [0 for i in range(M + 1)]
    '''好み調査開始'''
    for i in range(N):
        p = [int(m) for i, m in enumerate(input().split()) if i != 0]
        for f in p:
            food[f] += 1
    '''結果出力'''
    print(food.count(N))


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import itertools
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

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

cnt = 0
for i in range(1,M+1):
    if l.count(i) == N:
        cnt += 1
print(cnt)

Submission status: Accepted

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

for i in range(m+1):
    if array.count(i)==n:
        ans+=1
        
print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, raw_input().split())
ma = []
num = 0
for i in range(n):
    x = []
    x = map(int, raw_input().split())
    ma.append(x[1:])
ma = sum(ma,[])
for mb in list(set(ma)):
    if ma.count(mb) == n:
        num+=1
print(num)

Submission status: Accepted

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

like_list = [val for val in like_dict.values() if val == n]

print(len(like_list))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
foods = {i:0 for i in range(1, m+1)}
for i in range(n):
  tmp_list = list(map(int,input().split()))
  for j in range(len(tmp_list)):
    if j>0:
      a = tmp_list.pop(1)
      foods[a] += 1
  del tmp_list
ans = [v for v in foods.values() if v==n] 
print(len(ans))

Submission status: Accepted

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

if N == 1:
    print(len(A[0]))
else:
    ans = 0
    idx = K.index(max(K))
    max_len = A.pop(idx)
    for j in max_len:
        flg = 0
        for vals in A:
            if j in vals:
                flg += 1
        else:
            if flg == len(A):
                ans += 1
    else:
        print(ans)

Submission status: Accepted

Solution code:
n,m = input().split()
N = int(n)
M = int(m)
k = []
for i in range(N):
    s = input().split()
    s = [int(i) for i in s]
    s.pop(0)
    k += s
likesum = 0
for i in range(1,M+1):
    if k.count(i) == N:
        likesum += 1
print(likesum)

Submission status: Accepted

Solution code:
n, m = list(map(int, input().split()))
anq = []
for i in range(n):
  a = list(map(int, input().split()))
  k = a.pop(0)
  anq.append(a)
  
count = 1
tempand = set(anq[0])
for i in range(n-1):
  tempand = set(tempand) & set(anq[count])
  count += 1
print(len(tempand))

Submission status: Accepted

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

print(len([i for i in range(M) if array[i] == N]))

Submission status: Accepted

Solution code:
def main():
  N, M = map(int, input().split())
  anss = []
  for _ in range(N):
    anss.append(set(list(map(int, input().split()))[1:]))

  # print(ans)
  result = set([i for i in range(31)])
  for ans in anss:
    result = result & ans

  print(len(result))
  

main()

Submission status: Accepted

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

li = []
for i in range(n):
    lis = list(map(int, input().split()))
    lis.pop(0)
    li += lis

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

print(ans)

Submission status: Accepted

Solution code:
n,m= map(int,input().split())
l=[]
for i in range(n):
  l1= list(map(int,input().split()))
  del l1[0]
  l=l+l1
ans=0
l2=list(set(l))
for j in range(len(l2)):
  if l.count(l2[j])==n:
    ans+=1
print(ans)

Submission status: Accepted

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

Count = 0
for i in range(len(k[0])):
	count = 0
	for j in range(1, len(k)):
		if k[0][i] in k[j]:
			count += 1
			continue
		else:
			break
	if count == n - 1:
		Count += 1
print(Count)

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    all = list(map(int, input().split()))
    all.pop(0)
    tmp = []
    for _ in range(N - 1):
        tmp.clear()
        tmp = list(map(int, input().split()))
        tmp.pop(0)
        all = list(set(tmp) & set(all))
    print(len(all))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

x = A[0]
for a in A[1:]:
  x = list(set(x) & set(a))

print(len(x))

Submission status: Accepted

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

ans=0
for mi in range(1,m+1):
    if all(mi in ai[1:] for ai in a):
        ans+=1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
(n, m) = map(int, input().split())
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))
    a[-1].pop(0)

score = [0 for _ in range(m)]
for i in a:
    for food_index in i:
        score[food_index - 1] += 1
print(score.count(n))

Submission status: Accepted

Solution code:
#coding:utf-8

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

fuga = [0]*M
for i in range(N):
    tmp = [int(j) for j in input().split()]
    k = tmp[0]
    s = tmp[1:]
    for i in range(k):
        fuga[s[i]-1] += 1

print(fuga.count(N))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
K = [0]*N
A = [[0]*M for i in range(N)]
for i in range(N):
  x = list(map(int, input().split()))
  K[i] = x[0]
  A[i] = x[1:]
l = A[0]
for i in range(1, N):
  j = 0
  max_j = len(l)-1
  j = 0
  while(j != max_j+1):
    if l[j] not in A[i]:
      del l[j]
      max_j -= 1
      j -= 1
    j += 1
print(len(l))

Submission status: Accepted

Solution code:
n, m = [int(i) for i in input().split()]
a_s = [{int(i) for i in input().split()[1:]} for _ in range(n)]
t = {int(i) for i in range(1, m + 1)}

for a in a_s:
    t = t & a

print(len(t))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
inputs = []
for i in range(n):
	temp = list(map(int, input().split()))
	del temp[0]
	inputs.append(temp)

count = {}

for i in range(n):
	for j in inputs[i]:
		if j in count.keys():
			count[j] += 1
		else:
			count[j] = 1

total = 0
for keys in count:
	if count[keys] == n:
		total += 1
print(total)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
foods=[0]*m
for i in range(n):
  inp=input().split()
  k=int(inp[0])
  answer=[int(i)-1 for i in inp[1:]]
  
  for j in range(k):
    foods[answer[j]]+=1
num=0
for i in range(m):
  if foods[i]==n:
    num+=1
print(num)

Submission status: Accepted

Solution code:
N,M = [int(x) for x in input().split(' ')]
MLIS = [0] * M
for i in range(N):
  p = [int(x) for x in input().split(' ')]
  for j in range(1,p[0]+1):
    #print(p[j])
    MLIS[p[j]-1] += 1
    
    
cnt = 0
for i in range(M):
  #print(i,MLIS[i])
  if MLIS[i] == N:
    cnt +=1
print(cnt)

Submission status: Accepted

Solution code:
#入力
N,M = map(int,input().split())
K = [0] * N
A = [0] * N
for i in range(N):
    K[i], *A[i] = map(int, input().split())
#共通部分    
Ans_i = set(A[0])
for i in range(N):
  Ans_i = Ans_i & set(A[i])
print(len(list(Ans_i)))

Submission status: Accepted

Solution code:
N, M = list(map(int, raw_input().split()))
K = []

array = []
for i in xrange(M): array.append(0)
for i in xrange(N):
    inputs = list(map(int, raw_input().split()))
    K = inputs[0]
    for j in xrange(K):
        array[inputs[j+1]-1] += 1

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

print str(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = [int(v) for v in input().split()]
l = [0] * m
for _ in range(n):
        k = [int(v) for v in input().split()]
        for i in range(1, len(k)):
                l[k[i] - 1] += 1
ans = 0
for num in l:
        if num == n:
                ans += 1
print(ans)

Submission status: Accepted

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

food = [0 for i in range(m)]

for i in range(n):
    line = [int(t) for t in input().split()]
    k = line[0]
    a = line[1:]
    for item in a:
        food[item - 1] += 1
        
cnt = 0
for item in food:
    if item == n:
        cnt += 1

print(cnt)

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)] 
#print(e)
x=[]

for i in range(n):
  x=x+e[i][1:]

#print(x)
ans=0
if n==1:
  ans=e[0][0]
else:
  for i in range(1,m+1):
    if x.count(i)==n:
      ans+=1
    
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
n,m = map(int,input().split())
data = np.array([[int(i) for i in input().split()]for j in range(n)])
ans = []
for i in data:
  for j in i[1:]:
    ans.append(j)
ans = np.array(ans)
count = 0
for i in range(1,m+1):
  if (ans==i).sum() == n:
    count +=1
    
print(count)

Submission status: Accepted

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

data = []
for i in range(num):
    taste = [int(i) for i in input().split()]
    del taste[0]
    data.append(taste)


result = 0
if len(data) == 1:
    result = len(data[0])
else:
    for num1 in data[0]:
        trueNum = 0
        for i in range(1, len(data)):
            if num1 in data[i]:
                trueNum += 1
                if trueNum == len(data) - 1:
                    result += 1

print(result)

Submission status: Accepted

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

Knk=[]
for _ in range(N):
    Knk.append([int(x) for x in input().strip().split()])

ans = [0] * M

for i,Kn in enumerate(Knk):
    for n,A in enumerate(Kn):
        if n == 0:
            continue
        ans[A-1]+=1

print(len([x for x in ans if x == N]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N, M = map(int, input().split())
menu = np.array([])
for i in range(N):
  a = np.array(input().split())
  menu = np.append(menu, a[1:])
menu = np.array(menu).astype(int).ravel()
count = 0
for i in range(1, M+1):
  if np.sum(menu == i) == N:
    count += 1
print(count)

Submission status: Accepted

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

table = [True for _ in range(m)]



ans = 0
for i in range(n):
    like = list(map(int , input().split()))[1:]
    # print(like)
    for j in range(m):
        if j+1 in like:
            pass
        else:
            table[j]=False
# print(table)
for is_liked in table:
    if is_liked:
        ans +=1
print(ans)