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 sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}
# b = list(map(lambda x: math.ceil(x/10)*10, a))


n, m = map(int, input().split())
con = []
for i in range(n):
    k = [int(x) for x in input().split()]
    for j in range(1, k[0]+1):
        con.append(k[j])
ans = 0
for i in range(m):
    if con.count(i+1) == n:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
like_set = {0}
for i in range(1, M+1):
    like_set.add(i)
for i in range(N):
    like = list(map(int,input().split()))
    like = set(like[1:])
    like_set = like_set & like
print(len(like_set))

Submission status: Accepted

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

Submission status: Accepted

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

my_dict = {}
for line in line_list:
    for param in line:
        if param in my_dict:
            my_dict[param] += 1
        else:
            my_dict[param] = 1
ret = 0
for param in my_dict.items():
    if param[1] == N:
        ret += 1
print(ret)

Submission status: Accepted

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

for i in range(n):
    temp = list(map(int, input().split()))
    for j in range(temp[0]):
        data[temp[j+1]-1]+=1

print(data.count(n))

Submission status: Accepted

Solution code:
b, c = map(int, input().split())
chk = {"a":0}
for i in range(b):
        lst = list(map(int, input().split()))
        for j in lst[1:]:
                if(j in chk.keys()):
                        chk[j] += 1
                else:
                        chk[j] = 1
ans = 0
for i in chk.values():
        if i == b:
                ans += 1
print(ans)

Submission status: Accepted

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

for _ in range(N):
    for a in input().split()[1:]:
        a = int(a)
        m[a] += 1

ans = 0
for voted in m.values():
    ans += 1 if voted == N else 0
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
#好きだと答えた人数を格納
fs = [0 for _ in range(M)]
for i in range(N):
    ki = list(map(int, input().split()))
    for n in ki[1:]:
        fs[n-1] += 1

cn = 0
for a in range(M):
    cn += 1 if fs[a] == N else 0
print(cn)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue May 14 15:12:42 2019

@author: avina
"""

N,M = map(int, input().split())
k = list(map(int, input().split()))
k = set(k[1:])
for i in range(N-1):
  l = list(map(int, input().split()))
  k = k & set(l[1:])
print(len(k))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[[int(x) for x in input().split()] for _ in range(n)]
d={i:0 for i in range(m)}
for i in range(n):
    k=a[i][0]
    for j in range(k):
        d[a[i][j+1]-1] += 1
cnt=0
for key in d:
    if d[key] == n:
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
a, b = map(int,input().split())
list1 = list(range(1,b+1))
list2 = []
for i in range(a):
  c = list(map(int, input().split()))
  d = c[1:]
  for j in d:
    if j in list1:
      list2.append(j)
    else:
      continue     
  list1 = list2.copy()
  list2.clear()
print(len(list1))

Submission status: Accepted

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

ans = set( i for i in range(1, m+1) )

for favset in sets:
  ans = ans & favset
  
print(len(ans))

Submission status: Accepted

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

N, M = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(N)]
ans = [0] * M

for i in range(N):
    v = L[i]
    s = v[1:v[0] + 1]
    
    for v in s:
        ans[v - 1] += 1
        
print(len([v for v in ans if v == N]))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
counts = [0] * M
for n in range(N):
    for a in list(map(int, input().split()))[1:]:
        counts[a-1] += 1
res = 0
for c in counts:
    if c == N:
        res += 1
print(res)

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N,M = inpl()
likes = [0]*M

for _ in range(N):
    kaa = inpl()
    for i in range(1,kaa[0]+1):
        likes[kaa[i]-1] += 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, math, collections, heapq, itertools
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0:
        a, b = b, a % b
    return b
  
def solve():
    N, M = map(int, line_input())
    food_liked = [0] * M
    for i in range(N):
        person_i = list(map(int, line_input()))
        for a in person_i[1:]:
            food_liked[a-1] += 1
    num_of_everyone_like = 0
    for m in range(M):
        if food_liked[m] == N:
            num_of_everyone_like += 1
    return num_of_everyone_like

  
if __name__ == "__main__":
    print(solve())

Submission status: Accepted

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

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

likes = {i for i in range(1, m + 1)}
for i in range(n):
    a = list(map(int, input().split()))[1:]
    likes &= set(a)

print(len(likes))

Submission status: Accepted

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

likes = {i for i in range(1, M + 1)}
for i in range(N):
    A = [int(c) for c in input().split()][1:]
    likes &= set(A)
print(len(likes))

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
like = [i+1 for i in range(M)]
for n in range(N):
    KA = list(map(int, input().split()))
    like = [x for x in KA[1:] if x in like]
print(len(like))

Submission status: Accepted

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

cnt = 0    
for m in range(1,M+1):
    for n in range(N):
        if not m in A_list[n][1:]:
            break
    else:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
K=[]
like=[]
food=[]
for i in range(N):
    B=[int(h) for h in input().split()]
    K.append(B[0])
    B.remove(B[0])
    for k in range(K[i]):
        like.append(B[k])
  
for j in range(1,M+1):
    food.append(like.count(j))

print(food.count(N))

Submission status: Accepted

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

Submission status: Accepted

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

f = set()
for i in l:
    if f == set():
        f = i
    else:
        f &= i

print(len(f))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ka=[list(map(int,input().split())) for i in range(n)]
count=0
for i in range(n):
  del ka[i][0]
a=[flatten for inner in ka for flatten in inner]
for i in range(m):
  if a.count(i+1)==n:
    count+=1
print(count)

Submission status: Accepted

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

t_list=[]

for i in range(n):
  f_list = list(map(int, input().split()))
  f_list.pop(0)
  for j in range(len(f_list)):
    t_list.append(f_list[j])

count = 0
for k in range(m):
  if t_list.count(k+1) == n:
    count += 1
print(count)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = list(list(map(int,input().split())) for i in range(N))
like = [1]*M
for _ in A:
    tmp = [0]*M
    for i in _[1:]:
        tmp[i-1] = 1
    for i in range(M):
        like[i] = min(like[i],tmp[i])
print(sum(like))

Submission status: Accepted

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

Submission status: Accepted

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

items = set(KA[1:])


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

ans = len(items)
print(ans)

Submission status: Accepted

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

counts = [0] * M
for _ in range(N):
    K, *A = map(int, input().split())
    for a in A:
        counts[a - 1] += 1

print(sum(count == N for count in counts))

Submission status: Accepted

Solution code:

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

    KA = list(map(int, input().split()))

    items = set(KA[1:])

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

    answer = len(items)
    print(answer)

Submission status: Accepted

Solution code:
from collections import Counter
n, m = map(int, input().split())
food_arr = []
total = 0
for i in range(n):
   food_arr += list(map(int, input().split()[1:]))
    
counter = Counter(food_arr)
for key, value in counter.items():
  if value == n:
    total += 1
print(total)

Submission status: Accepted

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

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

print(K.count(N))

Submission status: Accepted

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

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

result = [1 for i in range(1, M+1) if K[i] == N]
print(sum(result))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

print(result)

Submission status: Accepted

Solution code:
n,m = (int(j) for j in input().split())
K = [[0]]*n
Count = [0]*m
for j in range(n):
    K[j] = [int(k) for k in input().split()]
for j in range(n):
    for k in range(1,K[j][0] + 1):
        Count[K[j][k] - 1] = Count[K[j][k]-1] + 1
count2 = 0
for j in range(m):
    if Count[j] == n:
        count2 = count2 + 1
print(count2)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
data = []
for i in range(N):
    data.append(list(map(int, input().split())))
#print(data)
counter2 = 0
for i in range(1, M + 1):
    counter1 = 0
    for ans in data:
        num = ans[0]
        if i in ans[1 : num + 1]:
            counter1 += 1
        else:
            counter1 = 0
            break
    if counter1 == N:
        counter2 += 1
print(counter2)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = set([i for i in range(1, m+1)])
for i in range(n):
    a = [int(i) for i in input().split()]
    ans = ans & set(a[1:])

print(len(ans))

Submission status: Accepted

Solution code:
import numpy as np

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

ss = np.zeros((n,m),int)

for i in range(n):
    s = list(map(int, input().split()))
    
    if s[0]>0:
        for k in s[1:]:
            ss[i,k-1]=1

c = ss.sum(0)

ans = np.sum(c==n)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
d={i:0 for i in range(m)}
for i in range(n):
  k,*a=map(int,input().split())
  c=0
  for b in a:
    d[b-1]+=1
    if n==d[b-1]:c+=1
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

answers=[]
for k in range(1,M+1):
    ans=0
    for i in range(N):
        for j in range(a[i][0]):
            if a[i][j+1]==k:
                ans+=1
    if ans==(N):
        answers.append(k)
print(len(answers))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ans = 0
a = []
for i in range(n):
    s = list(input().split())
    a = a + s[1:]
for i in range(1, m + 1):
    if a.count(str(i)) == n:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict
N, M = [int(a) for a in input().split(" ")]
KAs = [[int(a) for a in input().split(" ")] for i in range(N)]
dic = defaultdict(lambda: 0)
for kas in KAs:
    for a in kas[1:]:
        dic[a] += 1
ans = 0
for cnt in dic.values():
    if cnt==N:
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
a, b = map(int, input().split())
A = []
for i in range(a):
    array = list(map(int, input().split()))
    A.append(array)
B = []
for j, k in enumerate(A):
    if j == 0:
        B = k[1:]
    else:
        B = list(set(k[1:]) & set(B))
print(len(B))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
nakami=[]
for i in range(n):
  ilist= list(map(int,input().split()))
  for j in range(1,ilist[0]+1):
    nakami.append(ilist[j])

import collections
c=collections.Counter(nakami)

a=0
for i in range(m+1):
  if c[i] == n:
    a += 1
  else:
    pass
  
print(a)

Submission status: Accepted

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

Submission status: Accepted

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

ct = [0 for _ in range(m)]
for i in range(n):
    a = list(map(int,input().split()))
    for j in range(1,len(a)):
        ct[a[j]-1] += 1

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
N,M=map(int,input().split())
k_a=[None for i in range(N)]
cnt=0
for i in range(N):
  k_a[i] = list(map(int,input().split()))[1:]
for inde in k_a[0]:
  c = 0
  for j in range(1,N):
    for k in k_a[j]:
      if inde == k:
        c+=1
        break
    if c >= N-1:
      cnt+=1
if N==1:
  print(len(k_a[0]))
else:
  print(cnt)

Submission status: Accepted

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

G = []
for i in range(N):
    A = list(map(int,input().split()))
    if A[0] != 0:
        for j in range(1,len(A)):
            G.append(A[j])

cnt = 0
for k in range(1,M+1):
    if G.count(k) == N:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=set(range(1,M+1))
for i in range(N):
    k,*a=map(int,input().split())
    A&=set(a)
print(len(A))

Submission status: Accepted

Solution code:
# coding: utf-8

n, m = map(int, input().split())
s = set(range(1,m+1))

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

print(len(s))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
A = []
x = 0
for i in range(N):
    S = list(map(int,input().split()))
    for k in range(1,S[0]+1):
        A.append(S[k])
A.sort()
for i in range(1,M+1):
    if A.count(i) == N:
        x = x + 1
print(x)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
import sys
ans = 0
lst = []
kari = []
for i in range(N):
    if i == 0:
        lst += list(map(int, input().split()))
        lst = lst[1:]
#        print (lst)
    else:
        if lst == []:
            print (0)
            sys.exit()
        else:      
            kari = list(map(int, input().split()))
#            print ('kari ', kari)
            sakujo = []
            for j in lst:
                if j in kari[1:]:
                    pass
                else:
                    sakujo += [j]
#                    lst.remove(j) #ループの途中でlstから削除すると場所がずれる
#                    print (j)
            for k in sakujo:
                lst.remove(k)

#        print ('lst ', lst)
        if lst == []:
            print (0)
            sys.exit()

#print (lst)
ans = len(lst)
print (ans)

Submission status: Accepted

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

result =[]
for i,t in enumerate(target):
     if i == 0:
         result = t[1:]
     else:
         result = list(set(t[1:]) & set(result))
         
print(len(result))

Submission status: Accepted

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

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

b = [b for inner in a for b in inner]

for i in range(m):
    ans += (b.count(i+1) == n)

print(ans)

Submission status: Accepted

Solution code:
from itertools import chain
n,m=map(int,input().split())
a=[0]*(n)
b=[0]*(n)
for i in range(n):
  b[i]=list(map(int,input().split()))
for i in range(n):
  a[i]=b[i][1:]
ans=0
c=[e for p in a for e in p]
for j in range(1,m+1):
  if c.count(j)==n:
    ans+=1
print(ans)

Submission status: Accepted

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

ans = K[0][:]
for i in range(1,N):
    ans = list(set(ans) & set(K[i]))

print(len(ans))

Submission status: Accepted

Solution code:
N,M=list(map(int,input().split()))
Key=[]
cnt=0
a=0
    
if N==1:
    a=input().split()
    print(len(a)-1)

else:    
    
    for i in range(N):
        tmp=input().split()
        for j in range(int(tmp[0])):
            Key.append(int(tmp[j+1]))
    
    for i in range(1,M+1):
        if Key.count(i)==N:
            cnt+=1
    
    print(cnt)

Submission status: Accepted

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

def solve():
    N, M = list(map(int, input().split()))
    A = list(map(int, input().split()))
    candidates = copy.deepcopy(A[1:])

    for i in range(N-1):
        A = list(map(int, input().split()))
        A = copy.deepcopy(A[1:])

        copied_candidates = copy.deepcopy(candidates)
        for candidate in copied_candidates:
            if candidate in A:
                continue
            else:
                candidates.remove(candidate)
            
    print(len(candidates))



if __name__ == "__main__":
    solve()

Submission status: Accepted

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

B = set(range(1, M + 1))
for _ in range(N):
    A = [int(x) for x in input().split()]
    B &= set(A[1::])
print(len(B))

Submission status: Accepted

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

ans = 0
for i in range(m):
    _a = sum([x == i+1 for x in a])
    if _a == n:
        ans += 1

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# B - Foods Loved by Everyone
# https://atcoder.jp/contests/abc118/tasks/abc118_b

import numpy as np

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

rcd = [[False for c in range(M+1)] for r in range(N)]

for i in range(N):
    KA = list(map(int, raw_input().split()))
    K = KA[0]
    for j in range(1, K+1):
        rcd[i][ KA[j] ] = True

rcd = np.array(rcd)

cnt = 0
for c in range( len(rcd[0]) ):
    if sum(rcd[:,c]) == N:
        cnt += 1

print '{}'.format(cnt)

Submission status: Accepted

Solution code:
inpl = lambda: list(map(int,input().split()))
N, M = inpl()
fav = [1]*M
for _ in range(N):
    A = inpl()[1:]
    for m in range(M):
        if m+1 in A:
            pass
        else:
            fav[m] = 0
print(sum(fav))

Submission status: Accepted

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

for i in range(n):
    k = list(map(int, input().split()))
    for j in k[1:]:
        lst.append(j)
    
for i in range(1, m+1):
    cnt.append(lst.count(i))

print(cnt.count(n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd
readInt = lambda: int(sys.stdin.readline())
readIntN = lambda: [int(v) for v in sys.stdin.readline().split(' ')]

def main():
    n, m = readIntN()
    res = set(readIntN()[1:])
    for i in range(n-1):
        res = res.intersection(set(readIntN()[1:]))
    print(len(res))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N,M = map(int, input().strip().split(' '))
now = [i for i in range(1,M+1)]
for line in sys.stdin:
  col = list(map(int, line.strip().split(' ')))
  now = [f for f in now if f in col[1:]]
print(len(now))

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
c=[0]*b
f=0
for i in range(a):
    d,*e=map(int,input().split())
    for j in e:
        c[j-1]+=1
        if c[j-1]==a:
            f+=1
print(f)

Submission status: Accepted

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

Submission status: Accepted

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

for i in K:
    for j in i:
        que[j] += 1
for i in que:
    if i == N:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
food = [0]*(m+1)
for i in range(n):
    temp = list(map(int,input().split()))
    for a in temp[1:]:
        food[a] += 1
ans = 0
for f in food:
    if f == n:
        ans += 1
        
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
init = set(list(map(int, input().split()))[1:])
for _ in range(N - 1):
	target = set(list(map(int, input().split()))[1:])
	init &= target
print(len(init))

Submission status: Accepted

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

Submission status: Accepted

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

l = [0] * M

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

print(l.count(N))

Submission status: Accepted

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

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

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

print(len(f))

Submission status: Accepted

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

for i in range(1, M+1):
    x = a.count(i)
    if x == N:
    	cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
nm = input().split()
n = int(nm[0])
m = int(nm[1])

kalist = []
for i in range(n):
    ka = input().split()
    k = int(ka[0])
    alist = [int(a) for a in ka[1:]]
    kalist.append((k, alist))


aset = None
for k, alist in kalist:
    if aset is None:
        aset = set(alist)
    else:
        aset = aset & set(alist)

print(len(aset))

Submission status: Accepted

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

Ms = list(range(1, M+1))
ans = list(range(1, M+1))

for i in li:
    ans = list(set(ans) - (set(Ms) - set(i)))

print(len(ans))

Submission status: Accepted

Solution code:
from collections import defaultdict
d = defaultdict(int)

N, M = map(int, input().split())
for k in range(N):
    line = input().split()[1:]
    for a in line:
        d[a] += 1

# d = dict(d)
print(list(d.values()).count(N))

Submission status: Accepted

Solution code:
Ans_list = []
Ans = 0

N,M = map(int, input().split())
for i in range(N):
  KA = list(map(int, input().split()))
  Mylist = KA[1:]
  for j in range(len(Mylist)):
      Ans_list.append(Mylist[j])
for i in range(M+1):
  if Ans_list.count(i)==N:
    Ans += 1
print(Ans)

Submission status: Accepted

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

print(memo.count(n))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
result = set(range(1,M+1))
for i in range(N):
    K, *A = list(map(int, input().split()))
    result = result.intersection(set(A))
print(len(result))

Submission status: Accepted

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

SS = []
for k in K:
    for s in k[1:]:
        SS.append(s)

SS_d = [x for x in set(SS) if SS.count(x) > N-1]

print(len(SS_d))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ans = [True for j in range(m)]
for i in range(n):
    ka = list(map(int, input().split()))
    for a in range(m):
        if not (a+1) in ka[1:]:
            ans[a] = False
print(sum(ans))

Submission status: Accepted

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

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

print(len(ans))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
X  = list(range(M + 1))
for i in range(N):
    A = list(map(int,input().split()))
    K = A.pop(0)
    X = list(set(X) & set(A))

print(len(X))

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
 
user = {}
for i in range(N):
    user[i] = list(map(int,input().split()))
 
tmp = list(range(1,31))
for k in user.keys():
    user[k].pop(0)
    tmp = list(set(tmp) & set(user[k]))
print(len(tmp))

Submission status: Accepted

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

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

food_count = [0] * m

for p in k:
    for i in range(1, len(p)):
        food_count[p[i]-1] += 1

count = 0
for f in food_count:
    if f == n:
        count += 1

print(count)

Submission status: Accepted

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

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

tmp = list(range(1,31))
for k in user.keys():
    user[k].pop(0)
    tmp = list(set(tmp) & set(user[k]))
print(len(tmp))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
listM = list(range(1,M+1))
for i in range(N):
    K = list(map(int,input().split()))
    K.pop(0)
    a = []
    for j in range(len(listM)):
        if listM[j] not in K:
          	a.append(listM[j])
    for j in range(len(a)):
      	listM.remove(a[j])
print(len(listM))

Submission status: Accepted

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