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())
favs = [ 0 for _ in range(m) ]
for i in range(n):
    line = input().split()
    k = int(line[0])
    for j in range(k):
        a = int(line[j + 1])
        favs[a - 1] += 1
sum = 0
for i in range(m):
    if favs[i] == n:
        sum += 1
print(sum)

Submission status: Accepted

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

b = [x[1:] for x in a ]

c = []
for j in range(1,31):
    for k in range(n):
        if j in b[k]:
            c.append(j)

d = [x for x in set(c) if c.count(x) == n]

print(len(d))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
a = []
for i in range(N):
  array = list(map(int, input().strip().split(' ')))
  a.append(array)
ans = 0
sum = [0]*32
tmp = 0
for i in range(N):
  tmp = a[i][0]
  for j in range(tmp):
    sum[a[i][j+1]] = sum[a[i][j+1]] + 1
    
for i in range(32):
  if sum[i] == N:
    ans = ans + 1
print(ans)

Submission status: Accepted

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

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

a = {}
for i in list:
    for j in i[1:]:
        if j in a:
            a[j] = a[j] + 1
        else:
            a[j] = 1

cnt = 0
for x in a.values():
    if x == n[0]:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
import collections
N, M = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
sum_list = []
ans = 0
for i in range(N):
        for x in X[i][1:]:
                sum_list.append(x)
c = collections.Counter(sum_list)
for i in c.values():
        if i == N:
                ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = list(map(int, input().split()))
array = list(map(int, input().split()))
array.remove(array[0])
dainyu = []
for i in range(0, N[0]-1):
    data = list(map(int, input().split()))
    dainyu = []
    for loop in range(1, data[0]+1):
        if (array.count(data[loop]) != 0) :
            dainyu.append(data[loop])
    array = dainyu
print(len(array))

Submission status: Accepted

Solution code:
import numpy as np

a = input().split()
b = []
for i in range(int(a[0])):
  c = input().split()
  b.extend(c[1:])
count = 0
  
for j in range(int(a[1])+1):
  check = b.count(str(j))
  if check >= int(a[0]):
    count += 1

print(count)

Submission status: Accepted

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

like = [1] * M

for i in range(N):
    K, *A = map(int, input().split())
    for i in range(M):
        if i + 1 not in A:
            like[i] = 0
print(sum(like))

Submission status: Accepted

Solution code:
import collections
import itertools

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

counter = collections.Counter(a)

ret = [letter for letter,count in counter.most_common() if count == counter.most_common()[0][1]]
if N == counter.most_common()[0][1]:
	print(len(ret))
else:
  print(0)

Submission status: Accepted

Solution code:
import numpy as np
n, m = map(int, input().split())
A = []
for _ in range(n):
  __ = input().split()
  A.append(np.array(__, dtype=int))
ans = []
for i in range(m):
  ans.append(i+1)
_ans = ans.copy()
for a in A:
  for i in range(len(ans)):
    if not ans[i] in a[1:]:
      _ans.remove(ans[i])
  ans = _ans.copy()
  
print(len(_ans))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
k=[0]*m
for i in range(n):
    A=[int(i) for i in input().split()]
    for i in range(1,len(A)):k[A[i]-1]+=1
print(sum(k[i]==n for i in range(m)))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 16 21:09:45 2019

@author: iwata
"""

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

a = list(map(int, input().split()))
for i in range(1,len(a)):
    anew.append(a[i])

if N==1:
    print(len(anew))
else:
    for j in range(1,N):
        a = list(map(int, input().split()))
        for k in range(1, len(a)):
            anew.append(a[k])
        anew_duplicate = [x for x in set(anew) if anew.count(x) > 1]
        anew = anew_duplicate 
    print(len(anew_duplicate))

Submission status: Accepted

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

count = [0 for i in range(K)]

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

ans = 0
for i in range(K):
    if count[i] == N:
        ans += 1

print(ans)

Submission status: Accepted

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

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

for i in range(m):
    all_true = True
    for j in a:
        if (i+1) not in j:
            all_true = False
            break
    if all_true:
        ans[i] = True

print (ans.count(True))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
likes = [0]*M
for n in range(N):
    K = [int(i) for i in input().split()]
    A = K[1:]
    for a in A:
        likes[a-1]+=1
result=0
for like in likes:
    if like == N:
        result+=1
print(result)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
li = []
for _ in range(N):
    L = [int(x) for x in input().split()]
    li.append(L[1:])

# print(li)

ans = 0
for i in range(1, M+1):
    s = 0
    for j in range(N):
        s += li[j].count(i)
    if s == N:
        ans += 1
    # all_in = True
    # for j in range(N):
    #     print(li[j][1:])
    #     if i in li[j][1:] is True:
    #         continue
    #     else:
    #         all_in = False
    #         break
    # if all_in is True:
    #     ans += 1

print(ans)

Submission status: Accepted

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

a_li =[]
for i in range(n):
    li = input().split()
    del li[0]
    a_li += li

count_li =[]
for o in range(m+1):
    x = a_li.count(str(o))
    count_li.append(int(x))
    
print(count_li.count(n))

Submission status: Accepted

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

all_like = [0 for i in range(m)]
#print(all_like)

for i in range(n):
    line = []
    for part in input().split()[1:]:
        all_like[int(part)-1] += 1

#print(all_like)

cnt = 0
for part in all_like:
    if part == n:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
result = [0 for i in range(m)]
for mindex in range(0,m):
    for nindex in range(0,n):
        for kindex in range(1,a[nindex][0]+1):
            if a[nindex][kindex] == mindex+1:
                result[mindex]+=1
            else:
                pass
                
 
print(result.count(n))

Submission status: Accepted

Solution code:
N = input().split()[0]
like = set(input().split()[1:])
for i in range(int(N) - 1):
    like = like & set(input().split()[1:])
print(len(like))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
k = list(map(int, input().split()))
del k[0]
ans = set(k)

for i in range(n-1):
    x = list(map(int, input().split()))
    del x[0]

    x = set(x)
    ans = ans & x

ans = list(ans)

print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

A=np.zeros((N,M))

for i in range(N):
    AA=list(map(int,input().split()))
    AA.pop(0)

    for j in AA:
        A[i][j-1]=1

for i in range(N-1):
    A[0]=A[0]*A[i+1]

print(np.sum(A[0]==1))

Submission status: Accepted

Solution code:
num, food_num = map(int, input().rstrip().split(" "))

food_list = [i + 1 for i in range(food_num)]

for i in range(num):
    input_line = input().rstrip().split(" ")
    input_line.pop(0)
    favorite_food = [int(j) for j in input_line]
    food_list = list(set(favorite_food) & set(food_list))

print(len(food_list))

Submission status: Accepted

Solution code:
from itertools import chain
from collections import Counter

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

print(sum(c==N for c in Counter(chain(*A)).values()))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b=map(int, input().split())

list2=[]
for i in range(a):
    c=list(map(int, input().split(" ")))
    del c[0]
    list2.append(c)
    
res= set(list2[0])
for i in range(1, a):
    res=res & set(list2[i])

r= len(res)
print(r)

Submission status: Accepted

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

K.sort(key=lambda x:x[0])

tmp=set(K[0][1:])
for A in K[1:]:
  tmp=tmp&set(A[1:])
  
print(len(tmp))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 16 21:12:07 2019

@author: yff20
"""

l1 = input().split()

ln = [0] * (int(l1[1]))

for num in range(0, int(l1[0])):
   l2 = input().split()
   for index in range(1, len(l2)):
       ln[int(l2[int(index)])-1] += 1
    
count = 0

for i in ln:
    if(i==int(l1[0])):
        count += 1

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

Submission status: Accepted

Solution code:
print((lambda p: sum([1 if sum([sum([1 if p[2][j][k+1]-1==i else 0 for k in range(p[2][j][0])]) for j in range(p[0])])==p[0] else 0 for i in range(p[1])]))((lambda a: [a[0],a[1],[list(map(int,input().split())) for i in range(a[0])]])(list(map(int,input().split())))))

Submission status: Accepted

Solution code:
N, M = (int(x) for x in input().split())
KA = [[int(x) for x in l] for l in [input().split() for i in range(N)]]
[x.pop(0) for x in KA]
#print(KA)
x = []
for s in KA:
  x.extend(s)
#print(x)
c = 0
for i in range(1, M + 1):
  #print(x.count(i))
  c = c + (1 if x.count(i) == N else 0)
print(c)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy


def main():
  n, m = list(map(int, input().split()))
  a = numpy.ones(m)

  for _ in range(n):
    b = numpy.zeros(m)
    b[list(map(lambda x: int(x) - 1, input().split()))[1:]] = 1
    a *= b

  print(int(numpy.sum(a)), flush=True)


if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
el = {}
for i in range(N):
    P = list(map(int, input().split()))
    K = P.pop(0)
    if i == 0: el = set(P)
    el = el & set(P)
print(len(el))

Submission status: Accepted

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

I = [True]*(M)

for j in range(1,M+1):
    for ki in range(N):
        if not (j in A[ki]):
            I[j-1] = False

print(I.count(True))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=[]
for i in range(n):
    a=list(map(str,input().split()))
    v=int(a[0])
    a.pop(0)
    for i in range(v):
        l.append(a[i])
s=[]
i=0
while i<m:
    i+=1
    i=str(i)
    s.append(l.count(i))
    i=int(i)
print(s.count(n))

Submission status: Accepted

Solution code:
listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))
    except:
        break;
x,y = map(int, listA[0])
l1 = listA[1][1:]
la = []
for a in l1:
  if x == 1:
    la.extend(l1)
    break
  b = True
  for lr in listA[2:]:
    if lr[1:].count(a) == 0:
      b=False
      break
  if b:
    la.append(a)


print(len(la))

Submission status: Accepted

Solution code:
import numpy as np
n,m = map(int,input().split())
ans = np.ones(m+1)
ans[0] = 0
for i in range(n):
    a = list(map(int,input().split()))
    a.pop(0)
    for i in range(1,m+1):
        if i in a:
            continue
        else:
            ans[i] = 0
print(int(np.sum(ans)))

Submission status: Accepted

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

s=set()
for i in range(m):
    s.add(i+1)


for i in range(n):
    a= [int(j) for j in input().split()]
    a.pop(0)
    a=set(a)
    s=s & a

print(len(s))

Submission status: Accepted

Solution code:
n, m = [int(x) for x in input().split()]
food_list = [0 for x in range(m)]
 
for i in range(n):
  s = [int(x) for x in input().split()]
  k = s[0]
  e = s[1:]
  for j in range(k):
    food_list[e[j]-1] += 1

ans = 0

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

Submission status: Accepted

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

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

for i in range(0, n):
	As = set(map(int, input().split()[1:]))
	product = product.intersection(As)
	
print(len(product))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
array = []
for i in range(n):
    array.append([int(k) for k in input().split()])
result = {}
for arr in array:
    for i, k in enumerate(arr):
        if i == 0:
            continue
        if k not in result:
            result[k] = 0
        result[k] += 1
res = 0
for i in result.items():
    if i[1] == n:
        res += 1
print(res)

Submission status: Accepted

Solution code:
from sys import stdin


def count_samples_of_like_same_food(n, m, samples_and_like_foods):
    #all_samples_count = len(samples_and_like_foods)
    like_foods_num_dict = {}
    for samples_like_foods in samples_and_like_foods:
        #like_foods_set = tuple(set(like_foods))
        sample = samples_like_foods[0]
        like_foods = samples_like_foods[1:]
        #print(like_foods_set)
        for like_food in like_foods:
            if like_food not in like_foods_num_dict:
                like_foods_num_dict[like_food] = 1
            else:
                like_foods_num_dict[like_food] += 1

    same_like_food_samples_count = 0
    for key, value in like_foods_num_dict.items():
        #print(value, n)
        if value == n:
            same_like_food_samples_count += 1
        else:
            #raise
            pass

    #print(same_like_food_samples_count)
    return same_like_food_samples_count


def main():
    input_line_list = stdin.readlines()
    input_line_list = [y.rstrip() for y in input_line_list]
    n, m = [int(z) for z in input_line_list[0].split()]
    samples_and_like_foods = [x.split() for x in input_line_list[1:]]
    #print(n, m)
    #print(samples_and_like_foods)
    #print(input_line_list)
    #samples_and_like_foods = [like_foods_string.split() for like_foods_string in input_line_list]
    #print(samples_and_like_foods)
    print(count_samples_of_like_same_food(n, m, samples_and_like_foods))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ka=[]
ans=0

for i in range(n):
    atmp=list(input().split())
    ka.append(atmp)


like=ka[0][1::]

if n>1:
    for i in range(1,n):
        liketmp=ka[i][1::]
        for k in range(0,len(like)):
            if like[k] not in liketmp:
                     like[k]='0'

for j in range(len(like)):
    if like[j]!='0':
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
n, k = [int(i) for i in input().split()]
lines = [set(input().split()[1:]) for i in range(n)]
diff = set(lines[0])
for i in range(1,len(lines)):
  diff = diff&lines[i]
print(len(diff))

Submission status: Accepted

Solution code:
n = 0
N, M = map(int, input().split())
A = []
for i in range(1,N+1):
    S = input().split()
    for j in range(len(S)):
        S[j] = int(S[j])
    A = A + S[1:]
    
for i in range(1, M+1): 
    cnt = A.count(i)
    if cnt == N:
        n += 1 
print("{}".format(n))

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
num_li = [input().split() for n in range(N)]
num_li = sorted(num_li)
#print(num_li)
#minin = []
#for i in range(len(num_li)):
#  minin.append(num_li[i][0])
#idx = minin.index(min(minin))
flag = False
count = 0

if len(num_li) ==  1:
  print(len(num_li[0][1:]))
  exit()

for i in range(1, int(num_li[0][0])+1):
  for j in range(1, len(num_li)):
    if num_li[0][i] in num_li[j][1:]:
#      print(num_li[0][i])
#      print(num_li[j])
      flag = True
    else:
      flag = False
      break
  if flag == True:
    count += 1
print(count)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = [input().split() for i in range(n)]
b = [a[i][1:] for i in range(n)]
def l(n):
  if n == 1:
    return b[0]
  else:
    return set(l(n-1)) & set(b[n-1])
print(len(l(n)))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
anslist = [0 for i in range(m)]
for i in range(n):
    ka = list(map(int, input().split()))
    del ka[0]
    for i in ka:
        anslist[i - 1] += 1

ans = 0
for i in anslist:
    if i == n:
        ans += 1
print(ans)

Submission status: Accepted

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

likeList=[]
for i in range(n):
    ai=list(map(int,input().strip().split()))[1:]
    likeList.extend(ai)
like=0
for i in range(m):
    if likeList.count(i+1)==n:
        like+=1
print(like)

Submission status: Accepted

Solution code:
from sys import stdin
from collections import Counter

N, M = stdin.readline().rstrip().split()
N, M = int(N), int(M)

all_list = []

for i in range(N):
    a_list = stdin.readline().rstrip().split()
    a_list = a_list[1:]
    all_list += a_list

counter = Counter(all_list)
all_like_list = [value for key, value in counter.items() if value == N]
print(len(all_like_list))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# B
#
# input
n, m = map(int,input().split())
o = [0] * (m+1)
for i in range(n):
  l = list(map(int,input().split()))
  #print(l)
  x = l[0]
  #print(x)
  for j in range(x):
    o[l[j+1]] += 1
    #print(o)
# output
print(o.count(n))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
data = [input().split() for i in range(N)] 
result=[]
for j in range(N):
    result=result+data[j][1:]
result=[int(s) for s in result]
ans=[x for x in result if result.count(x) == N]
print(int(len(ans)/N))

Submission status: Accepted

Solution code:
import collections
N,M = map(int, input().split())
p_list = []
for i in range(N):
  fli = list(map(int,input().split()))
  p_list.extend(fli[1:])
  c = collections.Counter(p_list)
  values, counts = zip(*c.most_common())
#print(N in counts)
#print(counts)
print(counts.count(N))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
List = list(range(1,M))
anser = []
def judge(N,M,List,anser):
  for i in range(N):
    L = list(map(int, input().split()))
    del L[0]
    if i==0:
      anser.extend(L)
    else:
      anser = list(set(L)&set(anser))
    
    
  print(len(anser))
judge(N,M,List,anser)

Submission status: Accepted

Solution code:
N,K=list(map(int, input().split()))
ans=[0]*31

K1=[]
cnt=0
for i in range(N):
	K1=list(map(int, input().split()))
	for i in range(K1[0]):
		ans[K1[i+1]]=ans[K1[i+1]]+1
	K1.clear()


for i in range(30):

	if ans[i+1]==N :
		cnt=cnt+1

print(cnt)

Submission status: Accepted

Solution code:
s = input()

n = int(s.split()[0])
m = int(s.split()[1])

inp = [input().split() for _ in range(n)]

count = 0
for i in range(1,m+1):
    flg = True
    for like in inp:
        if str(i) not in like[1:]:
            flg = False
            break
    if flg:
        count += 1

print(count)

Submission status: Accepted

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

count = 0
for i in range(K[0]):
    flag = True
    for j in range(N-1):
        if(inpu[0][i] not in inpu[j+1]):
            flag = False
    if (flag == True):
        count = count + 1
print(count)

Submission status: Accepted

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

#一列目削除
for i in range(0,N):
    list[i].pop(0)

stock = []

#解答が全リストにあるか探索
for i in range(0,N):
    for j in range(0,len(list[i])):
        cnt = 0
        for k in range(0,N):
            if list[i][j] in list[k]:
                cnt += 1
        if cnt == N:
            stock.append(list[i][j])

if N == 1:
    stock = list[i]

print(len(set(stock)))

Submission status: Accepted

Solution code:
def generateBin(m, t):
    l = list(t)
    bin_num = 0
    for i in range( m):
        if l.count(i+1) == 1:
            bin_num += 1<< i
    return bin_num

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

ans = 0
for i in range( m):
    ans += 1 << i

bin_n =0
for i in range(n):
    k,*t = tuple(map(int,input().split()))
    bin_n = generateBin(m, t)
    ans = ans & bin_n

print('{:b}'.format(ans).count('1'))

Submission status: Accepted

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

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

#%%

mlist = [0] * m

#%%
for i in range(len(a)):
    for j in range(len(a[i])):
        mlist[a[i][j] - 1] += 1

counter = 0
for mlisti in mlist:
    if mlisti == n:
        counter += 1

print(counter)
#%%

Submission status: Accepted

Solution code:
import numpy as np

s=input().split(" ")
N=int(s[0])
lst=[]
for i in range(N):
    if i==0:
        lst=input().split(" ")[1:]
    else:
        lst = set(lst) & set(input().split(" ")[1:])
    
print(len(lst))

Submission status: Accepted

Solution code:
#!/usr/bin/python3

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

A = []
for k in range(N):
    Ai = [i for i in map(int, input().split())]
    _M = Ai.pop(0)
    A.append(Ai)

res = A[0]
for k in range(N - 1):
    res = list(set(res) & set(A[k + 1]))


print(len(res))

Submission status: Accepted

Solution code:
### B

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

A = []

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


c = 0
Count = 0
for m in range(M):
	for n in range(N):
		if m+1 in A[n]:
			c += 1
#			print(str(n) + " likes " + str(m+1))
	if c == N:
		Count += 1
#	print("Count = " + str(Count))
	c = 0

print(Count)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
listA=[]
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
x = 0
for j in range(1,listA[0][0]+1):
    for i in range(1,n):
        listB = []
        for k in range(1,listA[i][0]+1):
          listB.append(listA[i][k])
        if listA[0][j] not in listB:
          break
    else:
    	x += 1
print(x)

Submission status: Accepted

Solution code:
N,M = map(int, input().split(' '))
result = set(range(1,M+1)) 
for i in range(N):
  a = [int(j) for j in input().split(' ')]
  result =  result & set(a[1:])

print(len(result))

Submission status: Accepted

Solution code:
import sys
import io
import math

datalist = input().split()

i = 0
for i in range(int(datalist[0])):
    if i == 0:
        l_new = input().split()
        l_new.pop(0)
    if i != 0:
        l_input = input().split()
        l_input.pop(0)
        l_new = set(l_input) & set(l_new)

print(len(l_new))

Submission status: Accepted

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

dic = {}
for i in range(0,n):
    k = list(map(int,input().split()))
    for j in range(1,len(k)):
        if k[j] in dic:
            dic[k[j]] += 1
        else:
            dic[k[j]] = 1
        
res = 0
for key,value in dic.items():
    if value == n:
        res+=1
print(res)

Submission status: Accepted

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

k = []
num_list = []
for x in range(n):
    a = list(map(int, input().split()))
    k.append(a[1:])
    num_list += a[1:]

num_list = list(set(num_list))

result = 0

for x in num_list:
    for a in k:
        f = False
        for b in a :
            if b == x:
                f = True
        if f != True:
            break
    if f :
        result += 1

print(result)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N,M = map(int, lines.pop(0).split(' '))
    res = set(range(1,M+1))
    for i in range(N):
        a = list(map(int, lines.pop(0).split(' ')))
        a.pop(0)
        res = res & set(a)
    print(len(res))


#
# main
#
lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
num =0
line_m=[]
line_s=[]
for k in range(M+1):
    line_m.append(0)
for i in range(N):
    line_s = list(map(int, input().split()))
    for n in range(int(line_s[0])):
        line_m[int(line_s[n+1])] = int(line_m[int(line_s[n+1])]) + 1

for s in range(M+1):
    if line_m[s] == N:
        num = num+1

# print(line_s)
# print(line_m)

print(num)

Submission status: Accepted

Solution code:
import numpy as np
import math

n, m = map(int, input().split())
X = []
A = []
inter = range(1, m+1)
for i in range(n):
    X = list(map(int, input().split()))
    A = X[1:]
    inter = list(set(inter) & set(A))

print(len(inter))

Submission status: Accepted

Solution code:
from sys import stdin

def main():
    N, M = map(int, input().split())
    A = [tuple(map(int, input().split())) for _ in [0] * N]

    ans = set(A[0][1:])
    for a in A:
        ans &= set(a[1:])
    print(len(ans))

input = lambda: stdin.readline()
main()

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
a = []
love = 0
for i in range(N):
    a.append(list(map(int,input().split())))
for k in range(M):
    count = 0
    for i in range(N):
        if k+1 in a[i][1:]:
            count += 1
        else:
            break
    if count == N:
        love += 1
print(love)

Submission status: Accepted

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

num_dict = {}

if N == 0:
    print(0)
else:
    for i in range(N):
        data = list(map(int,input().split()))
        if len(data) > 1:        
            for j in range(len(data)-1):
                if data[j+1] in num_dict:
                    num_dict[data[j+1]] = num_dict[data[j+1]] + 1
                else:
                    num_dict[data[j+1]] = 1

if num_dict == {} or N not in num_dict.values():
    print(0)
else: 
    keys = [k for k, v in num_dict.items() if v == N]
    print(len(keys))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
for i in range(n):
    if i==0:
        a0=list(map(int,input().split()))	
        b0=a0[1:]
    else:
        a=list(map(int,input().split()))
        b=a[1:]
        c=[]
        for j in b0:
            if not j in b:
                c.append(j)
        for x in c:
            b0.remove(x)
print(len(b0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N, M = input().split()
hito = []
for i in range(int(N)):
    hito.append(input().split())

for i in range(int(N)):
    hito[i] = list(map(int, hito[i]))

for i in range(int(N)):
    hito[i].pop(0)

hikaku = np.arange(1,int(M)+1)
for i in range(int(N)):
    hikaku = list(set(hikaku) & set(hito[i]))



print(len(hikaku))

Submission status: Accepted

Solution code:
from operator import add

n, m = map(int, input().split())
li = []
for i in range(n):
    li.append(list(map(int, input().split())))
    del li[i][0]
li = sum(li, [])
li_2 = list(set(li))
count = 0
for num in li_2:
    if n == li.count(num):
        count += 1
print(count)

Submission status: Accepted

Solution code:
def main():
    row_input = input()
    split_input = row_input.split()

    N = int(split_input[0])
    M = int(split_input[1])

    ansors = []
    for i in range(N):
        row_input = input()
        split_input = row_input.split()
        ansor = []
        for k in range(1, int(split_input[0])+1):
            ansor.append(int(split_input[k]))
        ansors.append(ansor)

    food_list = []
    for i in range(1,M+1):
        food_list.append(i)

    for ans in ansors:
        length = len(food_list)
        diff = 0
        for i in range(length):
            target_food = food_list[i-diff]
            if target_food in ans:
                pass
            else:
                food_list.remove(target_food)
                diff+=1

    result = len(food_list)
    print(result)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
likefood = []
result = 0

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

for i in range(a[1]):
    if likefood.count(i+1) == a[0]:
        result += 1

print(result)

Submission status: Accepted

Solution code:
n, m = list(map(int,input().split()))
kinds = [0]*m
for i_n in range(n):
  likes = list(map(int,input().split()))
  if likes[0] != 0:
    for j_likes in likes[1:]:
      kinds[j_likes-1]+=1
print(sum([ 1 if kind==n  else 0 for kind in kinds]))

Submission status: Accepted

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

for i in range(1,len(favlist[0])):
    notfav.append(favlist[0][i])

for i in range(n):
    favlist[i][0] = 0

if n != 1:
    for i in range(n):
        for j in range(len(notfav)):
            if not notfav[j] in favlist[i]:
                notfav[j] = 0
    cnt = 0
    for i in range(len(notfav)):
        if notfav[i] != 0:
            cnt += 1
    print(cnt)
else:
    print(len(favlist[0]) - 1)