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:
N, M= map(int,input().split())

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

print(len(arr))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
favo = []
count = 0
for i in range(N):
    favo.append([int(x) for x in input().split()][1:])

for j in range(1, M+1):
    if all([j in x for x in favo]):
        count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
k = 0
alist = []
while k < n :
  a = list(map(int,input().split()))
  alist.append(a)
  k += 1
#
if n == 1 :
  print(len(alist[0])-1)
else:
  for blist in alist :
    b = blist[0]
    blist.remove(b)
#
  anslist = []
  ans = 0
  i_roop = len(alist[0])
  while i_roop >= 0 :
    if i_roop == 0 :
      break
    else:
      c = min(alist[0])
      for j in range(1,n) :
        if c in alist[j] :
          anslist.append("OK")
          if j == n-1 :
            if len(anslist) == n-1 :
              ans += 1
        else:
          if j == n-1 :
            if len(anslist) == n-1 :
              ans += 1
          break
      alist[0].remove(c)
    anslist = []
    i_roop += -1

if n != 1 :
  print(ans)

Submission status: Accepted

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

for l in range(len(flag)):
  if flag[l] == N: ans += 1
  else: pass
  
print(ans)

Submission status: Accepted

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

like = []
cnt = 0

for i in range(N):
	like.append([int(x) for x in 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:
#A
"""
a,b = map(int, input().split())
if b % a == 0:
    print(b + a)
else:
    print(b-a)
"""

#B

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


#C
"""
import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

n = int(input())
a = list(map(int, input().split()))
print(gcd_list(a))
"""

Submission status: Accepted

Solution code:
#!/usr/bin/python

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

Submission status: Accepted

Solution code:
from collections import Counter
N,M = map(int,input().split())
ans = 0
an = []
for i in range(N):
    tmp = list(map(int, input().split()))
    an += tmp[1:]
for i in Counter(an).values():
    if i==N:
        ans+=1
print(ans)

Submission status: Accepted

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

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, xor
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, M = MAP()

C = Counter()
for _ in range(N):
    l = LIST()
    l = l[1:]
    for a in l:
        C[a] += 1

cnt = 0
for v in C.values():
    if v == N:
        cnt += 1
print(cnt)

Submission status: Accepted

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

for _ in range(n):
    _, *o = map(int, input().split())
    for x in o:
        res[x - 1] += 1

ans = sum(1 for x in res if x == n)

print(ans)

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    result = [0] * (M + 1)
    for _ in range(N):
        row = list(map(int, input().split()))
        A = row[1:]
        for num in A:
            result[num] += 1

    print(len(list(filter(lambda x: x == N, result))))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

for i in range(n):
    _, *o = map(int, input().split())
    for x in o:
        res[x - 1] += 1

ans = sum(1 for x in res if x == n)

print(ans)

Submission status: Accepted

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

for i in range(n):
    o = list(map(int, input().split()))
    for j, x in enumerate(o):
        if j != 0:
            res[x - 1] += 1

ans = sum(1 for x in res if x == n)

print(ans)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    n, m = map(int, raw_input().split(" "))
    answers = []

    answer = set(raw_input().split(" ")[1:])
    for x in range(n-1):
        answer = answer.intersection(raw_input().split(" ")[1:])

    print(len(answer))

Submission status: Accepted

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

for i in range(N):
  Nlist=list(map(int,input().split()))
  if i==0:
    answerlist=Nlist[1:]
  else:
    answerlist_update=[]
    for j in range(len(answerlist)):
      if answerlist[j] in Nlist[1:]:
        answerlist_update.append(answerlist[j])
    answerlist=answerlist_update
print(len(answerlist))

Submission status: Accepted

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

candidate = [i + 1 for i in range(m)]

for _ in range(n):
  likes = list(map(int, input().split()))[1:]
  candidate = [x for x in candidate if x in likes]
  
print(len(candidate))

Submission status: Accepted

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

foods = dict(zip([i+1 for i in range(M)], [0 for i in range(M)]))

for i in range(N):
    A = list(map(int, input().split()))[1::]
    for f in A:
        foods[f]+=1
ans = 0
for count in foods.values():
    if(count == N):
        ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

k = []
a = []

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

#print(k)
#print(a)

ans = [0 for _ in range(m)]

for i in range(n):
    for j in range(len(a[i])):
#        print(i, j)
        if a[i][j] != 0:
            ans[a[i][j]-1] += 1

#print(ans)

num = 0

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

print(num)

Submission status: Accepted

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

fav=[0 for x in range(M+1)]
for i in range(N):
  A=[int(x) for x in input().split()]
  for j in range(A[0]):
    fav[A[j+1]]+=1
ans=0
for c in fav:
  if c==N:
    ans+=1
print(ans)

Submission status: Accepted

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


def solve(string):
    string = string.split("\n")
    n, m = map(int, string[0].split())
    ans = {i + 1 for i in range(m)}
    for loves in string[1:]:
        ans &= set(map(int, loves.split()[1:]))
    return str(len(ans))


if __name__ == '__main__':
    base = input()
    n, m = map(int, base.split())
    tmp = [base]
    for _ in range(n):
        tmp.append(input())
    print(solve('\n'.join(tmp)))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
F = [True for _ in range(M)]
# print(F)
for _ in range(N):
    IN = input().split()
    # K = int(IN[0])
    A = [int(a) for a in IN[1:]]
    G = [i in A for i in range(1, M + 1)]
    F = [F[i] and G[i] for i in range(M)]
print(F.count(True))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M=[int(i) for i in input().split(" ")]
vote=[0 for i in range(M)]
for i in range(N):
    K,*A=[int(i) for i in input().split(" ")]
    for k in A:
        vote[k-1]+=1
print(sum([1 for i in vote if i==N]))

Submission status: Accepted

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

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

print(sum(i == n for i in cnt))

Submission status: Accepted

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

    a = []
    for _ in range(n):
        r = [int(s) for s in input().split()][1:]
        a.append(r)
    
    print(solve(m, a))

def solve(m, a):
    s = set(range(1, m + 1))

    for i in range(len(a)):
        s = s & set(a[i])
    
    return len(s)

main()

Submission status: Accepted

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

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

N, M = map(int, input().split())
s = set()
for n in range(N):
    items = list(map(int, input().split()))
    K = items[0]
    As = items[1:]
    if n == 0:
        s = set(As)
    else:
        s &= set(As)
print(len(s))

Submission status: Accepted

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

A_list[0].pop(0)
a = A_list[0]
for i in range(1, N):
  A_list[i].pop(0)
  a = set(a) & set(A_list[i])

if len(a)==0:
  print(0)
else:
  print(len(a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N,M = map(int,input().split())
    cnt = [0]*M
    for _ in range(N):
        K,*A = map(int,input().split())
        for a in A:
            cnt[a-1] += 1
    print(sum(c==N for c in cnt))

main()

Submission status: Accepted

Solution code:
a, b = map(int, raw_input().strip().split(' '))

memo = [0 for _ in xrange(b + 1)]
for _ in xrange(a) :
    for x in  map(int, raw_input().strip().split(' '))[1:] :
        memo[x] += 1

print len([0 for x in xrange(len(memo)) if memo[x] == a])

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
_, *A = map(int,input().split())
s = set(A)
for i in range(N-1):
    _, *B = map(int,input().split())
    s &= set(B)
print(len(s))

Submission status: Accepted

Solution code:
N,M = (int(x) for x in input().split())
a = [[int(x) for x in input().split()] for i in range(N)] 
food = [0]*(M+1)
count = 0
for i in range(N):
    for j in range(1,a[i][0]+1):
        food[a[i][j]] = food[a[i][j]] + 1
for i in range(M+1):
    if food[i] == N:
        count = count + 1
print(count)

Submission status: Accepted

Solution code:
person_num, shurui = map(int, input().split())
like_set = set(list(map(int, input().split()))[1:])
for i in range(person_num - 1):
    like_set_kari = set(list(map(int, input().split()))[1:])
    like_set &= like_set_kari
print(len(like_set))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(cnt)

Submission status: Accepted

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

l = []

for i in range(N):
	del K_A[i][0]
	for j in range(len(K_A[i])):
		l.append(K_A[i][j])
		
count = 0

for i in range(K+1):
	if l.count(i) == N:
		count  += 1

print(count)

Submission status: Accepted

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

print(num)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
for i in range(N):
    A = list(map(int, input().split()))
    if i == 0:
        ans = set(A[1:])
    else:
        ans = set(A[1:]) & ans
print(len(ans))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
N, M = map(int, input().split())
ans = [0] * M
for _ in range(N):
    K, *A = list(map(int, input().split()))
    for x in A:
        ans[x - 1] += 1
print(len([x for x in ans if x == N]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def read():
    return int(input())

def reads():
    return list(map(int, input().split()))

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

Submission status: Accepted

Solution code:
import numpy as np

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

temp = input_numbers()

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

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

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

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

count = 0

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

print(count)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
temp = list(map(int, input().split()))
temp = set(temp[1:])
for i in range(n-1):
	temp2 = list(map(int, input().split()))
	temp2 = set(temp2[1:])
	temp = temp.intersection(temp2)
print(len(temp))

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
    l = list(map(int, input().split()))
    # print(l)
    for j in range(l[0]):
        nop[l[j+1]-1] += 1

# print(nop, n)

print(nop.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 = set(A[0])
for i in range(1, N):
  l &= set(A[i])
print(len(l))

Submission status: Accepted

Solution code:
from collections import Counter

def parse_line(line, type=int):
	return [type(x) for x in line.split(' ')]

def main():
	n, m = parse_line(input())
	counter = Counter()
	for _ in range(n):
		k_choices = parse_line(input())
		choices = k_choices[1:]
		for choice in choices:
			counter[choice] += 1
	print(len([x for x in counter.values() if x == n]))


	

if __name__ == '__main__':
	main()

Submission status: Accepted

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

nokori=[0]*(M+1)
  
for i in range(0,N):

  kk=list(map(int,input().split(" "))) 
  K=kk[0]
  del kk[0]
  
  for j in kk:
    nokori[j]+=1
    
  #print(nokori)
  
for ii in nokori:
  count+=(ii==N)
print(count)

Submission status: Accepted

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

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

marray = [0] * m
count = 0

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

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

print(count)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
num = set(range(1,m+1))

for i in range(n):
    a = set(list(map(int,input().split()))[1:])
    num = num&a

print(len(num))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
Likes = [True] * M
count = [0] * M
nums = 0
for n in range(N):
    KA = list(map(int,input().split()))[1:]
    for i in KA:
        count[i-1] += 1
for i,j in enumerate(count):
    if j == N:
      nums +=1
print(nums)

Submission status: Accepted

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

from collections import Counter
c = Counter()
for i in range(n):
    tmp = list(map(int,input().split()))
    for j in tmp[1:]:
        c[j] += 1
cnt = 0
for i in c:
    if c[i] == n:
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
# your code goes here

def main(base, new):
	new_base = []
	for member in base:
		if member in new:
			new_base.append(member)
		else:
			pass
	return new_base


init = input()
base = input().split(' ')[1:]
try:
	while True:
		base = main(base, input().split(' ')[1:])
except:
	pass
print(len(base))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
data = dict()
for i in range(m):
    data[i+1] = 0
for i in range(n):
    temp = list(map(int,input().split()))
    for k in range(1,temp[0]+1):
        data[temp[k]] += 1
counter = 0
for i in data:
    if data[i] == n:
        counter += 1
print(counter)

Submission status: Accepted

Solution code:
import sys

def main():
  input = sys.stdin.readline
  N, M = map(int, input().split())
  A = set(list(range(1, M+1)))
  for _ in range(N):
    B = set(list(map(int, input().split()))[1:])
    A = A & B
  print(len(A))


if __name__ == '__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

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

a = []
k = []

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


ans = [0 for _ in range(m)]


for i in range(n):
    for x in a[i]:
        ans[x-1] += 1

temp = 0

for x in ans:
    if x == n:
        temp += 1

print(temp)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


N, M = ds_in()

all_loved = set([i for i in range(1, M+1)])
for _ in range(N):
    loved = set(ds_in()[1:])
    all_loved = all_loved.intersection(loved)

print(len(all_loved))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
K = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
#人ループ
for person in range(0,N):
    L = list(map(int,input().split()))
    for kind in range(1,L[0]+1):
        K[L[kind]] += 1
print(K.count(N))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
out = []
for x in range(n):
    temp = list(map(int, input().split()))[1:]
    if x == 0: out = temp
    else:
        out = list(set(out).intersection(set(temp)))
print(len(out))

Submission status: Accepted

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

As = set(range(1,M+1))
for i in range(N):
    temp = list(map(int, input().split(' ')))
    k = temp[0]
    As = As & set(temp[1:])

print(len(As))

Submission status: Accepted

Solution code:
import collections

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

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

c = collections.Counter(a)
ans = 0
for val in c.values():
    if val == N:
        ans += 1

print(ans)

Submission status: Accepted

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

for i in range(n):
  a = list(map(int, input().split()))
  b = {a[i] for i in range(1,a[0]+1)}
  if i == 0:
    x = b
  else:
    x = x & b

print(len(x))

Submission status: Accepted

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

for i in range(n):
    o = list(map(int, input().split()))
    for j, x in enumerate(o):
        if j != 0:
            res[i][x - 1] = True

res = list(zip(*res))

ans = sum(1 for x in res if all(x))

print(ans)

Submission status: Accepted

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

for i in range(n):
    o = list(map(int, input().split()))
    for j, x in enumerate(o):
        if j != 0:
            res[i][x - 1] = True

ans = 0
res = list(zip(*res))

for i, x in enumerate(res):
    if all(x):
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n,m=(int(i) for i in input().split())
l = [x+1 for x in range(m)]
for i in range(n):
    a = [int(x) for x in input().split()]
    k = a.pop(0)
    l = list(set(l) & set(a))
print(len(l))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
dic = {}
for i in range(0, N):
    Ak = list(map(int, input().split()))[1:]
   # print(Ak)
    for v in Ak:
        if v in dic.keys():
            dic[v] += 1
        else:
            dic[v] = 1    
result = 0
for vals in dic.values():
    if vals == N:
        result += 1

print(result)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N):
  KA=list(map(int,input().split()))
  for i in range(1, KA[0]+1):
    memo[KA[i]-1]+=1
    
for m in memo:
  if m==N:
    ans+=1
    
print(ans)

Submission status: Accepted

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

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

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)]
dic = {}
for hobbies in e:
    for i in range(1,len(hobbies)):
        if hobbies[i] in dic:
            dic[hobbies[i]] +=1
        else:
            dic[hobbies[i]] = 1
everyoneLike = []
for key,num in dic.items():
    if num == n:
        everyoneLike.append(key)
print(len(everyoneLike))

Submission status: Accepted

Solution code:
(N,M) = map(int,input().split())
r = int(-1)
for i in range(N):
  A = list(map(int,input().split()))
  A.pop(0)
  c = 0
  for a in A:
    c |= (1 << (a-1))
  r &= c

ans = sum([(r>>n)&1 for n in range(M)])
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
for i in range(n):
    lst = [int(j) for j in input().split()]
    lst.pop(0)
    if i == 0:
        ans = list(lst)
    else:
        tmp = list(lst)
        for x in lst:
            if x not in ans:
                tmp.remove(x)
        ans = list(tmp)
print(len(ans))

Submission status: Accepted

Solution code:

# coding: utf-8

# In[65]:


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

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


# In[66]:


print(like.count(N))

Submission status: Accepted

Solution code:
from collections import defaultdict
d = defaultdict(lambda:0)
N,M = map(int,input().split())
for i in range(N):
    K = list(map(int,input().split()))
    for j in range(1,K[0]+1):
        d[K[j]] += 1
ans = 0
for key in d:
    if d[key] == N:
        ans += 1
print(ans)

Submission status: Accepted

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

tmp = list(map(int, input().split()))
ans = set(tmp[1:])

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

print(len(ans))

Submission status: Accepted

Solution code:
#-*-coding:utf8;-*-
#qpy:3
#qpy:console
n, m = map(int, input().split())
food = []
like = 0
for i in range(n):
    food.append(input().split())
    del food[i][0]
for i in range(1, m+1):
    for j in range(n):
        if str(i) in food[j]:
            if j == n-1:
                like += 1
        else:
            break
print(like)

Submission status: Accepted

Solution code:
def inpl():
    return list(map(int, input().split()))


n, m = inpl()
ans = [0] * m
for _ in range(n):
    A = inpl()
    for a in A[1:]:
        ans[a - 1] += 1
print(len(list(filter(lambda x: x == n, ans))))

Submission status: Accepted

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


food_s=set(food)

for i in food_s:
    if food.count(i) == n:
        ans += 1

print(ans)

Submission status: Accepted

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

# その食べ物を好きだと答えた人の人数
X = [0] * (M+1)

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

print( X.count(N) )

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 =map(int,input().split())

ans_list=[0]*(M+1)
for i in range(N):
    A = list(map(int,input().split()))
    for i in A[1:]:
        ans_list[i]+=1

print(ans_list.count(N))

Submission status: Accepted

Solution code:
n,m = (int(i) for i in input().split())
x = [0]*m
for i in range(n):
  y = [int(i) for i in input().split()]
  for j in y[1:]: x[j-1]+=1
print(x.count(n))

Submission status: Accepted

Solution code:
def get_int(): return int(input())
def get_float(): return float(input())
def get_line(): return input().split()
def get_lines(v): return [get_line() for _ in range(v)]
def get_int_line(): return list(map(int, get_line()))
def get_int_lines(v): return [get_int_line() for _ in range(v)]
def get_float_line(): return list(map(float, get_line()))
def get_float_lines(v): return [get_float_line() for _ in range(v)]

N, M = get_int_line()
K = get_int_lines(N)

for i in range(N):
  K[i].remove(K[i][0])

ans = 0
for i in range(M):
  f = True
  for j in range(N):
    ff = len([v for v in K[j] if v == i + 1]) > 0
    if (not ff):
      f = False
  if (f): ans += 1

print(ans)

Submission status: Accepted

Solution code:
# _*_ coding:utf-8 _*_
#  Atcoder_Beginners_Contest118-B
#  TODO https://atcoder.jp/contests/abc118/tasks/abc118_b

def solveProblem(persons,kinds,orgDataSet):
	kindsDict=[0 for i in range(0,kinds,+1)]
	for i in range(0,persons,+1):
		eachLine = orgDataSet[i]
		length = len(eachLine)
		for j in range(1,length,+1):
			likeKind = eachLine[j]-1
			kindsDict[likeKind]=kindsDict[likeKind]+1
	agreePerson = 0
	for i in range(0,len(kindsDict),+1):
		if kindsDict[i] == persons:
			agreePerson = agreePerson + 1
	answer = agreePerson
	return answer


if __name__ == '__main__':
	N,M = map(int,input().strip().split(' '))
	dataList = []
	for i in range(0,N,+1):
		dataList.append(list(map(int,input().strip().split(' '))))
	solution = solveProblem(N,M,dataList)
	print("{}".format(solution))

Submission status: Accepted

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

if len(a_list) == 1:
    print(len(a_list[0]))
    exit()
ans = set(a_list[0])
for a_lis in a_list:
    ans = ans & set(a_lis)

print(len(list(ans)))