Problem:


Score : 200 points

Problem Statement

Katsusando loves omelette rice.

Besides, he loves crème brûlée, tenderloin steak and so on, and believes that these foods are all loved by everyone.

To prove that hypothesis, he conducted a survey on M kinds of foods and asked N people whether they like these foods or not.

The i-th person answered that he/she only likes the A_{i1}-th, A_{i2}-th, ..., A_{iK_i}-th food.

Find the number of the foods liked by all the N people.

Constraints

All values in input are integers.

1 \leq N, M \leq 30

1 \leq K_i \leq M

1 \leq A_{ij} \leq M

For each i (1 \leq i \leq N), A_{i1}, A_{i2}, ..., A_{iK_i} are distinct.

Constraints

Input is given from Standard Input in the following format:

N M
K_1 A_{11} A_{12} ... A_{1K_1}
K_2 A_{21} A_{22} ... A_{2K_2}
:
K_N A_{N1} A_{N2} ... A_{NK_N}

Output

Print the number of the foods liked by all the N people.

Sample Input 1

3 4
2 1 3
3 1 2 3
2 3 2

Sample Output 1

1

As only the third food is liked by all the three people, 1 should be printed.

Sample Input 2

5 5
4 2 3 4 5
4 1 3 4 5
4 1 2 4 5
4 1 2 3 5
4 1 2 3 4

Sample Output 2

0

Katsusando's hypothesis turned out to be wrong.

Sample Input 3

1 30
3 5 10 30

Sample Output 3

3



Sample input:
3 4
2 1 3
3 1 2 3
2 3 2


Sample output:
1

Submission status: Accepted

Solution code:
from functools import reduce

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

_dict={}

for i in range(N):
  _dict[i] = set(map(int, input().split()[1:]))
  
A = set(range(1, M+1))
A0 = set(range(1, M+1))

def aa(setA, setB):
  return setA & setB
  
print(len(reduce(aa, _dict.values(), A0)))

Submission status: Accepted

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

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

people_likes = dict()
for likes in likes_list:
    num = likes[0]
    for i in range(num):
        try:
            people_likes[likes[1:][i]] += 1
        except KeyError:
            people_likes[likes[1:][i]] = 1

count = 0
for v in people_likes.values():
    if v == N:
        count += 1

print(count)

Submission status: Accepted

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

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

if N == 1:
    print(e[0][0])
    exit()

set_list = []

for i in e:
    set_list.append(set(i[1:]))


ok = set()
for i in set_list:
    for num, i2 in enumerate(set_list):
        if num == 0:
            continue
        if len(ok) >=1:
            ok = list(i2.intersection(ok))
        else:
            ok = list(i.intersection(i2))
    break

print(len(ok))

Submission status: Accepted

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

r = None
for i in range(N):
    temp = list(map(int,input().split()))
    del temp[0]

    if r is None:
        r = set(temp)
    else:
        r = r & set(temp)

print(len(r))

Submission status: Accepted

Solution code:
N, M= (int(i) for i in input().split())
lst = [[int(i) for i in input().split()] for i in range(N)]
import numpy as np
food = np.zeros((N,M))
for i in range(N):
    for j in range(lst[i][0]):
        #print(lst[i][j+1])
        food[i][lst[i][j+1]-1] = 1
#print(food)
s = np.sum(food, axis=0)
print(len(s[s==N]))

Submission status: Accepted

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

p = copy.deepcopy(x[0])
for i in range(n-1):
    p.extend(x[i+1])
    p = [z  for z in set(p) if p.count(z) > 1]
print(len(p))

Submission status: Accepted

Solution code:
I=lambda:list(map(int,input().split()))
n,m=I()
a=[]
for _ in[0]*n:a.extend(I()[1:])
print(sum(n==a.count(i+1)for i in range(m)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N, M = map(int, input().split())
a = np.zeros((N,M))
for i in range(N):
    K = list(map(int, input().split())) 
    for j in K[1:]:
        a[i][j-1] = 1
b = a.sum(axis=0)
print(len(np.where(b==N)[0]))

Submission status: Accepted

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

def io_generator():
	while True:
		yield raw_input()

#+++++++++++++++++++


def cc(l1,l2):
	return list(set(l1)&set(l2))

def main(io):
	n,m= map(int, io.next().split())
	favs=range(m+1)
	for _ in range(n):
		l=list(map(int, io.next().split()))[1:]
		favs = cc(favs, l)
			
	return len(favs)

#++++++++++++++++++++

if __name__ == "__main__":
	io=io_generator()
	print main(io)

Submission status: Accepted

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

Submission status: Accepted

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


for i in range(n):
    a.append(list(map(int, input().split())))
    a[i].pop(0)

for i in range(len(a)):
    if i == 0:
        match = set(a[i])
    else:
        target = set(a[i])
        match = set(match & target)

print(len(match))

Submission status: Accepted

Solution code:
m = input().split()
n = int(m[0])
m = int(m[1])
food = list(range(1,m+1))
for i in range(n):
    inputvalue = input().split()
    del inputvalue[0]
    for j in range(1,m+1):
        if not str(j) in inputvalue and j in food:
            food.remove(j)
print(len(food))

Submission status: Accepted

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

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

for i in range(N):
    A = [int(x) for x in input().split()]
    K = A[0]
    for j in range(1,K+1):
        t[A[j]-1] += 1

ans = 0
for a in t:
    if a == N:
        ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(sum(1 for x in d if x == n))

Submission status: Accepted

Solution code:
N, M = (int(i) for i in input().split())
A = [0] * N
K = [0] * N
for n in range(N):
    A[n] = [int(i) for i in input().split()]
    K[n] = A[n][0]
    A[n] = A[n][1:]
K
A
ans = set(A[0])
for a in A[1:]:
     ans = ans & set(a)
print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter
n,m=map(int,input().split())
lst=[]
for i in range(n):
    lst.append(list(map(int,input().split())))
    del lst[i][0]
ans=[flatten for inner in lst for flatten in inner]
a=Counter(ans)
count=0
result=list(a.values())
for i in result:
    if i==n:
        count += 1
print(count)

Submission status: Accepted

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

field = [] 
for i in range(M):
    field.append([False] * N)

for n in range(N):
    row = list(map(int, input().split()))
    row.pop(0)
    for i in row:
        field[i-1][n] = True

cnt = 0
for m in range(M):
    if all(field[m]):
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
import collections
import sys


def main():
    N, M = map(int, input().split())
    data = []

    for num in range(N):
        result_data = list(input().split(' '))
        if N == 1:
            result = result_data[0]
            print(result)
            sys.exit(0)
        else:
            for i in result_data[1:]:
                data.append(int(i))

    c = collections.Counter(data)

    counter = 0

    for i in c.values():
        if i == N:
            counter += 1

    print(counter)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

a = []

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

#print(a)

ans = 0

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

print(ans)

Submission status: Accepted

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

def solve(n, m, *lines):

    
    rows = []
    for line in lines:
        rows.append([int(e) for e in line.split(" ")])

    # print(n)
    # print(m)
    # print(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():
    # 出力
    params = []
    nm = input().split(" ")
    n = int(nm[0])
    m = int(nm[1])
    params.append(n)
    params.append(m)

    for i in range(0, n):
        params.append(input())   
    print(solve(*params))

if __name__ == '__main__':

    main()

Submission status: Accepted

Solution code:
As,Bs=input().split()
N=int(As)
M=int(Bs)
ans=0

Alist=input().split()#All num
Alist.pop(0)
for i in range(N-1):
    Slist=input().split()
    Slist.pop(0)
    Alist=Alist+Slist

ASlist=list(set(Alist))#set num

for W in ASlist:
    # print(ASlist.count(W))
    if Alist.count(W)==N:
        ans=ans+1
        

print(ans)

Submission status: Accepted

Solution code:
N,K = map(int, input().split())
list_input = []
food_type = []
food = []
for n in range(N):
    list_input.append(list(map(int,input().split())))
    num = list_input[n][0]+1
    #print('num:'+str(num))
    each_food = []
    for i in range(1,num):
        #print(list_input[n][i])
        each_food.append(list_input[n][i])
        if list_input[n][i] in food_type:
            continue
        else:
            #print(i, list_input[n][i])
            food_type.append(list_input[n][i])
    food.append(each_food)
ans = 0
for t in food_type:
    all_like = True
    for f in food:
        if t not in f:
            all_like = False
    if all_like:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
k = []
for i in range(0, a[0]):
  b = list(map(int, input().split()))
  del b[0]
  k += b

kk = 0
for i in range(1, a[1] + 1):
  if k.count(i) == a[0]:
    kk += 1
print(kk)

Submission status: Accepted

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

food_list = []
for i in range(int(M)):
    food_list.append((i+1))
for i in range(int(N)):
    favorite_list = input().split()[1:]
    favorite_list = [int(x) for x in favorite_list]
    if len(food_list) == 0:
        break
    test_list = [int(x) for x in food_list]
    for j in test_list:
        if not (j in favorite_list):
            food_list.remove(j)
print(len(food_list))

Submission status: Accepted

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

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

# 1番目の配列に含まれる値が2番目以降の配列に含まれるか確認する
A = []
for i in range(len(K[0])):
    flag = True
    for j in range(len(K)):

        if K[0][i] not in K[j]:
            flag = False
            continue

    if flag:
        A.append(K[0][i])

print(len(A))

Submission status: Accepted

Solution code:
n, m = map(int, input().split(' '))
mat = []
for _ in range(n):
  mat.append(map(int, input().split(' ')[1:]))

res = set(mat[0])
for i in range(1, n):
  res = res.intersection(mat[i])
print(len(res))

Submission status: Accepted

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

m = [0] * m
for a_vec in a_mat:
    for a_val in a_vec:
        m[a_val - 1] = m[a_val - 1] + 1

print(len(list(filter(lambda x: x == n, m))))

Submission status: Accepted

Solution code:
def main():
    [N, M] = [int(num) for num in input().split(" ")]
    allset = set(range(M +  1))
    for _ in range(N):
        inp = [int(num) for num in input().split(" ")]
        inp.pop(0)
        allset =  allset.intersection(set(inp))
    print(len(allset))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
Tmp = []
Tmp = input().rstrip().split(' ')

nN = int(Tmp[0])
nM = int(Tmp[1])

nData = [[ 0 for i in range(2)] for j in range(nM)]

for i in range(nM):
    nData[i][0]=i+1

for i in range(nN):
	Tmp = input().rstrip().split(' ')
	nK = int(Tmp[0])
	nTmp =[ 0 for j in range(nK)]
	for j in range(nK):
		nTmp[j] = int(Tmp[j+1])
#	print(nTmp)
	for j in range(nM):
		if nData[j][0]  in nTmp:
			nData[j][1] += 1

nAns=0
for i in range(nM):    
    if nData[i][1]==nN:
        nAns += 1

print(nAns)

Submission status: Accepted

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

love = 0

for i in range(N):
  KA = input().split()
  love_i = 0
  for j in range(1, int(KA[0]) + 1):
    love_i += 2 ** (int(KA[j]) - 1)
  if i == 0:
    love += love_i
  else:
    love = love & love_i

love_bin_str = "{}".format(bin(love)).replace("0b", "")
print(love_bin_str.count("1"))