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:
lst = []
n,m = map(int, input().split())
for i in range(n):
  k = list(map(int, input().split()))
  lst = lst + k[1:]
a = 0
for i in range(1, m+1):
  if lst.count(i) == n:
    a += 1
print(a)

Submission status: Accepted

Solution code:
people, meals = map(int, input().split(" "))
count = {i:0 for i in range(1, meals+1)}

for person in range(people):
    meals = input().split(" ")
    number_liked = int(meals[0])
    meals_liked = [int(m) for m in meals[1:]]
    for i in meals_liked:
        count[i] += 1
ans = 0
for k, v in count.items():
    if people==v:
        ans += 1
print(ans)

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())

a = [0 for _ in range(M)]

for _ in range(N):
    A = list(map(int, input().split()))
    A.pop(0)
    for i in range(len(A)):
        a[A[i]-1] += 1

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

Submission status: Accepted

Solution code:
def solve(str_in_arr):
    """
    Calculate common favorite foods number of people

    Paramaters
    ----------
    str_in_arr : list of str
        list of string from standard input
        A first element of the list is number of favorite foods.

    Returns
    -------
    num_common_favorite_food : int
        common favorite foods number
    """
    _num_person, _num_food = str_in_arr[0].split()
    num_person, num_food = int(_num_person), int(_num_food)
    fav_foods_list = str_in_arr[1::]

    favorite_foods = [0] * int(num_food)

    for fav_foods in fav_foods_list:
        foods = fav_foods.split()[1::]
        for food in foods:
            idx_food = int(food) - 1
            favorite_foods[idx_food] += 1

    num_common_favorite_food = 0
    for num_person_per_food in favorite_foods:
        if num_person_per_food == num_person:
            num_common_favorite_food += 1

    return num_common_favorite_food


def main():
    num_person_and_food = input()
    _num_person, _ = num_person_and_food.split()
    num_person = int(_num_person)

    std_in = [num_person_and_food if idx == 0 else input() for idx in range(num_person+1)]
    print(solve(std_in))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

for i in range(m + 1):
    menu_count.append(0)

ans = 0

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

for i in range(n):
    for j in range(1, l[i][0] + 1):
        for k in range(1, m + 1):
            if l[i][j] == k:           #全部の数字に対して調べてない
                #print('menu_count',k,'up')  #この辺の何かがおかしい
                menu_count[k] += 1


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


#print('l\t\t', l)
#print('menu_count\t', menu_count)
#print('ans\t\t', ans)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
likes = [0] * M
for _ in range(N):
    temp = list(map(int, input().split()))
    for i in range(1, len(temp)):
        likes[temp[i] - 1] += 1
print(len([e for e in likes if e == N]))

Submission status: Accepted

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

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

Submission status: Accepted

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

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

for i in range(n):
    popped_item1=listA[i].pop(0)

listB=[]
for i in listA:
    for j in i:
        listB.append(j)

cnt=0
for i in range(m+1):
    if listB.count(i)==n:
        cnt+=1
print(cnt)

Submission status: Accepted

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

for i in range(N):
    likes = set()
    on = input().split()
    on.pop(0)
    likes = {int(j) for j in on}
    hoge &= likes


c = len(hoge)

print(c)

Submission status: Accepted

Solution code:
N,M=map(int,input().split(" "))
lists=[]
count=0
for a in range(N):
    lists+=input().split(" ")[1:]
for a in range(1,M+1):
    if(lists.count(str(a))==N):
        count+=1
print(count)

Submission status: Accepted

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

li_m = list()

for i in range(n):
    li_m = li_m + input().split()[1:]

counter = 0
for m in set(li_m):
    if li_m.count(m) == n:
        counter += 1
print(counter)

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)]

s=[]
for t in e:
  b_list=0
  for x in t[1:]:
    b_list = b_list | pow(2,x-1)
  s.append(b_list)
result=pow(2,30)-1
for i in s:
   result = result & i
cnt=0
for i in range(30):
  if result & pow(2,i):
    cnt+=1
print(cnt)

Submission status: Accepted

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

for i in range(0, n-1):
    a[i+1] = set(a[i]) & set(a[i+1])

print(len(a[n-1]))

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 a:
    i.pop(0)
for i in range(n-1):
    a[i+1] = set(a[i]) & set(a[i+1])
print(len(a[n-1]))

Submission status: Accepted

Solution code:
import sys
num = sys.stdin.readline().split()
d = {}
for line in sys.stdin.readlines():
  n = line.split()
  n.pop(0)
  for s in n:
    if s in d :
      d[s] = d[s]+1
    else :
      d[s] = 1
keys = [k for k, v in d.items() if v == int(num[0])]
print(len(keys))

Submission status: Accepted

Solution code:
n, m = map(int,input().split())
k = []
for i in range(n):
    K = list(map(int,input().split()))
    k.append(K)
ans = 0
for q in range(1,m+5):
    Z = 0
    for i in range(n):
        a = []
        b = []
        a.append(k[i])
        b = a[0]
        for l in range(1, b[0]+1):
            if b[l] == q:
                Z += 1
    if Z == n:
        ans += 1
print(ans)

Submission status: Accepted

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

for n in range(N):
    K_n_list = list(map(int, input().split()))
    del K_n_list[0]
    for K_n_list_num in K_n_list:
        all_dish.append(K_n_list_num)

prefer_dish = []
dish_kind = list(set(all_dish))
prefer_dish = [dish_kind_num for dish_kind_num in dish_kind if all_dish.count(dish_kind_num) == N]

print(len(prefer_dish))

Submission status: Accepted

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

for n in range(N):
    K_n_list = list(map(int, input().split()))
    del K_n_list[0]
#    all_dish = [K_n_list_num for K_n_list_num in K_n_list]

    for K_n_list_num in K_n_list:
        all_dish.append(K_n_list_num)

prefer_dish = []
dish_kind = list(set(all_dish))
prefer_dish = [dish_kind_num for dish_kind_num in dish_kind if all_dish.count(dish_kind_num) == N]
#for dish_kind_num in dish_kind:
#    if all_dish.count(dish_kind_num) == N:
#        prefer_dish.append(dish_kind_num)

print(len(prefer_dish))

Submission status: Accepted

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

for n in range(N):
    K_n_list = list(map(int, input().split()))
    del K_n_list[0]
#    all_dish = [K_n_list_num for K_n_list_num in K_n_list]

    for K_n_list_num in K_n_list:
        all_dish.append(K_n_list_num)

prefer_dish = []
dish_kind = list(set(all_dish))
#prefer_dish = [dish_kind_num for dish_kind_num in dish_kind if all_dish.count(dish_kind_num) == N]
for dish_kind_num in dish_kind:
    if all_dish.count(dish_kind_num) == N:
        prefer_dish.append(dish_kind_num)

print(len(prefer_dish))

Submission status: Accepted

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

for n in range(N):
    K_n_list = list(map(int, input().split()))
    del K_n_list[0]
    for K_n_list_num in K_n_list:
        all_dish.append(K_n_list_num)

prefer_dish = []
dish_kind = list(set(all_dish))
for dish_kind_num in dish_kind:
    if all_dish.count(dish_kind_num) == N:
        prefer_dish.append(dish_kind_num)

print(len(prefer_dish))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin

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

l = [int(x) for x in stdin.readline().rstrip().split()]
l.pop(0)
for i in range(n-1):
    l2 = [int(x) for x in stdin.readline().rstrip().split()]
    l2.pop(0)
    l = list(set(l)&set(l2))

print(len(l))

Submission status: Accepted

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

import sys
import math

def parse_input(lines_as_string = None):

    lines = []
    if lines_as_string is None:
        for line in sys.stdin:
            lines.append(line)
    else:
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    # 出力
    nm = lines[0].split(" ")
    n = int(nm[0])
    m = int(nm[1])

    rows = []
    for i in range(1, n+1):
        rows.append([int(e) for e in lines[i].split(" ")])

    return (n, m, rows)

def solve(n, m, rows):

    result = []
    for k in range(1, m + 1):
        tmp = []
        for i in range(0, n):
#            print(rows[i])
            r = rows[i]
#            print(r[1:r[0] + 1])
            if k in r[1:r[0]+1]:
               tmp.append(i+1)
        if len(tmp) == n:
            result.append(k)

    return len(result)

def main():

    print("%d" % solve(*parse_input()))

if __name__ == '__main__':

    main()

Submission status: Accepted

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

import sys

def parse_input(lines_as_string = None):

    lines = []
    if lines_as_string is None:
        for line in sys.stdin:
            lines.append(line)
    else:
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    # 出力
    nm = lines[0].split(" ")
    n = int(nm[0])
    m = int(nm[1])

    rows = []
    for i in range(1, n+1):
        rows.append([int(e) for e in lines[i].split(" ")])

    return (n, m, rows)

def solve(n, m, rows):

    result = []
    for k in range(1, m + 1):
        tmp = []
        for i in range(0, n):
#            print(rows[i])
            r = rows[i]
#            print(r[1:r[0] + 1])
            if k in r[1:r[0]+1]:
               tmp.append(i+1)
        if len(tmp) == n:
            result.append(k)

    return len(result)

def main():

    n, m, rows = parse_input()
    print("%d" % solve(n, m, rows))

if __name__ == '__main__':

    main()

Submission status: Accepted

Solution code:
x1 = input().split()
N = int(x1[0])
M = int(x1[1])
S = []
A = []
K = []
F = []
for i in range(M):
    S.append(0)
for i in range(N):
    K.append(0)
for i in range(N):
    A.append(input().split())
    K[i] = int(A[i][0])
    for j in range(K[i]):
        F.append(int(A[i][j+1]))
    for j in F:
        S[j - 1] += 1
    F = []
ans = 0
for i in range(M):
    if S[i] == N:
        ans += 1
print(ans)

Submission status: Accepted

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

def parse_input():

    # 出力
    nm = input().split(" ")
    n = int(nm[0])
    m = int(nm[1])

    rows = []
    for i in range(0, n):
        rows.append([int(e) for e in input().split(" ")])

    return (n, m, rows)

def solve(n, m, rows):

    result = []
    for k in range(1, m + 1):
        tmp = []
        for i in range(0, n):
#            print(rows[i])
            r = rows[i]
#            print(r[1:r[0] + 1])
            if k in r[1:r[0]+1]:
               tmp.append(i+1)
        if len(tmp) == n:
            result.append(k)

    return str(len(result))

def main():

    n, m, rows = parse_input()
    print(solve(n, m, rows))

if __name__ == '__main__':

    main()

Submission status: Accepted

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

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

count_list = [0] * 31 
for i in range(n):
    for j in range(1, len(kind_list[i])):
        count_list[kind_list[i][j]] = count_list[kind_list[i][j]] + 1

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

print(count)

Submission status: Accepted

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

print(M.count(n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import functools
N, M = (int(x) for x in input().split())
KA_arr = []
for i in range(N):
    KA_arr.append([int(x) for x in input().split()])

M_arr = [1]*M
for KA in KA_arr:
    for i in range(M):
        if not i+1 in KA[1:]:
            M_arr[i] = 0

ans = functools.reduce(lambda x,y:x+y, M_arr, 0)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

like = [0] * M

for i in range(N):
    tmp = list(map(int, input().split()))[1:]
    for a in tmp:
        like[a - 1] += 1

print(len([l for l in like if l == N]))

Submission status: Accepted

Solution code:
import sys
import pprint

pp = pprint.PrettyPrinter(indent=4)

def main():
    """ Code implementation """
    N, M = map(int, input().split())
    all_love = [True] * M
    for n in range(N):
        arr = list(map(int, input().split()))
        K, A = arr[0], arr[1:]
        this_love = [False] * M
        for k in range(K):
            a = int(A[k])
            this_love[a-1] = True
        for m in range(M):
            if all_love[m] and not this_love[m]:
                all_love[m] = False

    sum_love = 0
    for m in range(M):
        if all_love[m]:
            sum_love += 1
    print(sum_love)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

for i in range(n):
    sel = [int(i)-1 for i in input().split(" ")][1:]
    for s in sel:
        pre_res[s] += 1

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

print(res)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created: 金  2/22 10:36:58 2019

# Usage
#
"""
from collections import Counter

def i():
    n_people = int(input().split()[0])
    likes = []

    for i in range(n_people):
        likes.extend(input().split()[1:])

    return n_people, [int(l) for l in likes]

def s(n_people, likes):
    re = 0
    cn = Counter(likes)
    food = cn.keys()
    for f in food:
        if cn[f] == n_people:
            re += 1
    return re

if __name__ == '__main__':
	print(s(*i()))

Submission status: Accepted

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

cnt = Counter()
for _ in range(N):
    A = list(map(int, input().split()))[1:]
    cnt += Counter(A)

ans = 0
for k in cnt:
    if cnt[k] == N:
        ans += 1
print(ans)

Submission status: Accepted

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

correction = []
for j in range(n):
   correction += [input().split()]


list_and = correction[0][1::]
for j in range(1, n):
   list_and = set(list_and) & set(correction[j][1::])
   list_and = list(list_and)

print(len(list_and))

Submission status: Accepted

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

a = []

for i in range(N):
  b = list(map(int,input().split()))
  a.append(b)
           
c = [0]*M

for i in range(N):
	for j in range(M):
		c[j] += a[i][1:].count(j+1) 

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
n,m = [int(x) for x in input().split()]
s = set()
for i in range(n):
  _, *n = [int(x) for x in input().split()]
  if i == 0:
    s = set(n)
  else:
    s &= set(n)
print(len(s))

Submission status: Accepted

Solution code:
import numpy as np

i = [int(each) for each in input().split()]

n = i[0]
m = i[1]

l2 = np.zeros(m)

for i in range(n):
    for j, each in enumerate([int(each) - 1 for each in input().split()]):
        if j != 0:
            l2[each] += 1
    # print(l)

count = 0
for each in l2:
    if each == n:
        count += 1
print(count)

Submission status: Accepted

Solution code:
import sys

v = []
for line in sys.stdin:
    v.append([int(l) for l in line.split()])

n = v[0][0]
m = v[0][1]

a = None
for line in v[1:]:
  if a == None:
    a = line[1:]
  else:
    c = []
    for b in a:
      if b in line[1:]:
        c.append(b)
    a = c
print(len(a))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
List = []
like_dic = {}
like = 0
for i in range(N):
    List.append(input().split())
for i in range(N):
    for j in range(1,len(List[i])):
        if List[i][j] in like_dic:
            like_dic[List[i][j]] += 1
        else:
            like_dic[List[i][j]] = 1
for k in like_dic.keys():
    if like_dic[k] == N:
        like += 1
print(like)

Submission status: Accepted

Solution code:
# 2019/02/09
# AtCoder Beginner Contest 118 - B

# Input
n, m = map(int,input().split())

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

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

# Output
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(count)

Submission status: Accepted

Solution code:
N,M =[int(i)for i in input().split()]
l =[0]*M
for i in range(N):
    for j,st in enumerate(input().split()):
        if j != 0:
            st =int(st)-1
            l[st] += 1
ans =l.count(N)
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
data = []
for i in range(N):
    a = input().split()
    data.extend(a[1:])
result = 0
for i in range(1, M+1):
    if data.count(str(i))==N:
        result += 1
print(result)

Submission status: Accepted

Solution code:
nm_ent = list(map(int, input().split()))
n = nm_ent[0]
m = nm_ent[1]
full_ent = []
for i in range(0, n):
    full = list(map(int, input().split()))
    full_ent.append(full)
for k in range(0, n):
    full_ent[k].pop(0)   #2次元リストの各リストの先頭の数字を除外


#while以下は，2次元リストの1と2の共通の数字をリストとしてlist[1]に代入
#ついでlist[0]を消去し，今できたlist[0](=list[1])と本来のlist[2]を比較する
#それを繰り返す．
while True:
    if len(full_ent) == 1:
        out_flag = len(full_ent[0])
        break
    full_ent[1] = list(set(full_ent[0]) & set(full_ent[1]))
    full_ent.pop(0)

def out(out_flag):
    print(out_flag)

out(out_flag)

Submission status: Accepted

Solution code:
#coding: utf-8

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

List = []
all_and = []
for i in range(N):
    l = list(map(int, input().split()))
    del l[0]
    List.append(l)

    if i ==0:
        all_and = List[0]
    else:
        all_and = set(all_and) & set(List[i])
        all_and = list(all_and)

#print(all_and)
print(len(all_and))

Submission status: Accepted

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

Submission status: Accepted

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

if N == 1:
    print(len(A[0]))
    quit()
else:
    res = list(set(A[0]) & set(A[1]))
    for a, v in enumerate(A):
        res = list(set(res) & set(v))
    print(len(res))

Submission status: Accepted

Solution code:
people, foods = [int(x) for x in input().split()]
favors = []
for person in range(people):
  favor = [int(x) for x in input().split()]
  favors.append(favor[1:])
  
test_result = 0
if len(favors) == 1:
  test_result = len(favors[0])
else:
  all_taste = [x for favor in favors for x in favor ]
  
  for food in set(all_taste):
    if all_taste.count(food) == people:
      test_result += 1

print(test_result)

Submission status: Accepted

Solution code:
N,M =map(int,input().split())
K=[]; A =[]
for i in range(N):
    temp = input().split()
    K.append(temp[0])
    A.append(temp[1:])
c = 0
#check
for food in list(range(1,M+1)):
    for row in range(N):
        if str(food) not in A[row]:
            break
    else:
        c += 1
        continue
    
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ ==  "__main__":
    food_data = []
    n, m = map(int, input().split())
    for i in range(n):
        food_row = list(map(int, input().split()))
        food_row.pop(0)
        food_data.append(food_row)

    result = 0
    first_food_row = food_data[0]
    rest_food_rows = food_data[1:]

    for food in first_food_row:
        flag = False
        for food_row in rest_food_rows:
            if not food in food_row:
                flag = True
                break
            
        if flag:
            continue

        result += 1 

    print(result)

Submission status: Accepted

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

foods = list()
for _ in range(n):
    foods.append([int(x) for x in input().split()])

foods.sort(reverse = True)
foods = [f[1:] for f in foods]

count = 0
for f in foods[0]:
    if all(map(lambda l: f in l, foods[1:])):
        count += 1

print(count)

Submission status: Accepted

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

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

c = 0
for i in range(1, m+1):
    g = True
    for j in range(n):
        if i not in l[j][0:]:
            g = False
    if g:
        c = c + 1

print(c)

Submission status: Accepted

Solution code:
n, m = map(int, raw_input().split())
dic = {}
for i in range(n):
  l = map(int, raw_input().split())[1:]
  for j in l:
    if j in dic:
      dic[j] += 1
    else:
      dic[j] = 1
ans = 0
for i in dic:
  if dic[i] == n:
    ans += 1
print ans

Submission status: Accepted

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

for _ in range(N):
  hypo.append([int(s) for s in input().split(' ')][1:])

like_counts = [0] * M
for h in hypo:
  h_ = list(set(h))
  for i in h_:
    like_counts[i - 1] += 1

counts = 0
for i in like_counts:
  if i == N:
    counts += 1
print(counts)

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
like=[]
cnt=0
for i in range(N):
	like.append(list(map(int, input().split()))[1:])
for j in range(1,M+1):
	if all ([j in x for x in like]):
		cnt += 1
print(cnt)

Submission status: Accepted

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

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

ans = 0

for a in range(1, m+1):
    ok = True
    for i in range(n):
        if a not in listA[i][1:]:
            ok = False
    if ok:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
from itertools import chain

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


for low in data:
	del low[0]

data = list(chain.from_iterable(data))

counter = 0

for i in range(1, m+1):
	if data.count(i) == n:
		counter += 1

print(counter)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
def foods():
    n,m=map(int,input().split())
    ka=[[int(i) for i in input().split()] for i in range(n)]
    food=[i for i in range(1,m+1)]
    ans=[]
    for i in ka:
        hito=i[1:]
        ans+=[x for x,y in Counter(hito+food).items() if y>1]
    ansa=[x for x,y in Counter(ans).items() if y==n]
    return ansa

print(len(foods()))

Submission status: Accepted

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

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

print(len(Food_fav))

Submission status: Accepted

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

s = set()
A = [int(x) for x in input().split()]
s = set(A[1::])
for _ in range(N - 1):
    A = [int(x) for x in input().split()]
    s &= set(A[1::])

# print(s)
print(len(s))

Submission status: Accepted

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

    for j in range(1,b[0]+1):
        a[b[j]] += 1
t = 0
for i in range(len(a)):
    if a[i] == n:
        t += 1

print(t)

Submission status: Accepted

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

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

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

print(len(M_kinds))

Submission status: Accepted

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


seki = a[0]
for i in range(N-1):
    seki = seki & a[i+1]
    
print(len(seki))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

c = []
d = []
for i in range(n):
    a = [int(x) for x in input().split(" ")]
    if i == 0:
        c = a[- a[0]:]
    else:
        b = a[- a[0]:]
        for ce in c:
            if ce in b:
                 d.append(ce)
        c = d
        d = []

print(len(c))

Submission status: Accepted

Solution code:
N_M = list(map(int,input().split()))
N = N_M[0]
M = N_M[1]
ans = 0

list_sum = [0] * M

for i in range(N):
    tmp = list(map(int,input().split()))
    for j in tmp[1:]:
        list_sum[j - 1] +=1
        
for i in list_sum:
    if i == N:
        ans +=1
        
print(ans)

Submission status: Accepted

Solution code:
N,M=list(map(int,input().split(" ")))
bucket=[0 for _ in range(M+1)]
for i in range(N):
  r=list(map(int,input().split(" ")))
  for j in r[1:]:
    bucket[j]+=1
print(sum([i==N for i in bucket]))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
d = {}
for i in range(N):
    lst = list(map(int, input().split()))
    for a in range(1, len(lst)):
        if lst[a] in d:
            d[lst[a]] += 1
        else:
            d[lst[a]] = 1
ans = 0
for key in d:
    if d[key] == N:
        ans += 1
print(ans)

Submission status: Accepted

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

for i in range(n):
    l = list(map(int, input().split()))
    del l[0]
    li += l
    
for i in range(1, m+1):
    if li.count(i) == n:
        box.append(i)

print(len(box))

Submission status: Accepted

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


ans = 0
for i in check:
    if i == N:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
n, m = map(int, sys.stdin.readline().split())

x = set(range(1, m+1))

for i in range(n):
    x &= set(list(map(int, sys.stdin.readline().split()))[1:])

print(len(x))

Submission status: Accepted

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

listA = [list(map(int, input().split())) for j in range(n)]

ans = 0


for a in range(1, m+1):
    ok = True
    for i in range(n):
        if a not in listA[i][1:]:
            ok = False
    if ok:
        ans += 1



print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
arr = [list(map(int, input().split()))[1:] for i in range(n)]
cnt = [0 for i in range(m)]
for v in arr:
    for vi in v:
        cnt[vi - 1] += 1
# print(cnt)
ans = 0
for ci in cnt:
    if ci == n:
        ans += 1
print(ans)