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())
cnt = [0] * M

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

ans = sum([1 if i == N else 0 for i in cnt])
print(ans)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[]
k=[]
while True:
    try:
        dk,*d=list(map(int,input().split()))
        a.append(d)
        k.append(dk)
    except:
        break;
ans=set(a[0])
for i in range(1,n):
  ans=ans&set(a[i])

print(len(ans))

Submission status: Accepted

Solution code:
import sys
import math
from collections import Counter
import itertools
import fractions
import datetime
from decimal import Decimal
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################

N,M=MI()
KA=LLI(N)
like=[0]*M

for ka in KA:
    i = 0
    for a in ka:
        if i == 0:
            i += 1
            continue
        like[a-1] += 1

cnt = 0
for l in like:
    if l == N:
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
# N：人数 M：種類
# K1：個 A1 A2 ...：好きな食べ物の数字
# K2 A1 A2
# 全員が好きな食べ物の種類数

N, M = map(int, input().split())
s = set(range(1, M+1))

for _ in range(N):
    k, *a = map(int, input().split())
    s&=set(a)
print(len(s))

Submission status: Accepted

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

dic = {}

for i in range(N):
  for j in range(len(KA[i])-1):
    if KA[i][1+j] not in dic.keys():
      dic[KA[i][1+j]] = 1
    else:
      dic[KA[i][1+j]] += 1
      
ans = 0

for i in dic:
  if dic[i] == N:
    ans += 1
    
print(ans)

Submission status: Accepted

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

ans = set([i + 1 for i in range(M)])
for _ in range(N):
    T = input().split()
    A = set([int(i) for i in T[1:]])
    ans = ans & A
print(len(ans))

Submission status: Accepted

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

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

print(len(like))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

k, m = list(map(int, input().split()))


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


for i in range(k):
    _, *a = list(map(int, input().split()))
    set_ = set_ & set(a)


print(len(set_))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
K = []
A = []
for i in range(n):
    L = list(map(int, input().split()))
    K.append(L[0])
    A.append(L[1:])
# print(A)
Aall = []
for e in A:
    Aall += e
# print(Aall)
ans = 0
for i in range(1, m + 1):
    if Aall.count(i) == n:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(foods.count(n))

Submission status: Accepted

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

b = []

for i in range(n):
    for j in range(1,l[i][0]+1):
        b.append(l[i][j])

ans = 0
for k in range(1,m+1):
    cnt = b.count(k)
    if cnt == n:
        ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
ans = [0]*m
for _ in range(n):
    T = list(map(int,input().split()))
    for i in range(1,len(T)):
        ans[T[i]-1] += 1


ans_s = 0
for a in ans:
    if a == n:
        ans_s += 1

print(ans_s)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    cnt = set(range(1, M+1))
    for _ in range(N):
        K, *A = map(int, input().split())
        cnt.intersection_update(set(A))
    ans = len(cnt)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

S = [0]*M

for j in range (N):
  for k in range(1, L[j][0]+1):
    S[L[j][k]-1] += 1
    
print(S.count(N))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    from collections import defaultdict
    N, M = [int(i) for i in input().split()]
    kaa = [list(map(int, input().split())) for _ in range(N)]
    ans = defaultdict(int)
    for k, *a in kaa:
        for A in a:
            ans[A] += 1
    print(list(ans.values()).count(N))


resolve()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
k=[]
c=list(range(1,m+1))
for i in range(n):
    a=list(map(int,input().split()))
    a.pop(0)
    k.append(a)
for i in range(1,m+1):
    cnt=0
    for j in range(n):
        if k[j].count(i)>0:
            cnt+=1
    if cnt!=n:
        c.remove(i)
print(len(c))

Submission status: Accepted

Solution code:
n, m = input().split(" ")
n = int(n)
m = int(m)
k = []
for i in range(n):
    k.append([])
    tmp = input().split(" ")
    for j in range(1, len(tmp)):
        k[i].append(int(tmp[j]))

dict = {}
for i in range(1, m+1):
    dict[i] = 0

for i in k:
    for j in i:
        dict[j] += 1

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

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ans = None
for i in range(n):
    aa = tuple(map(int, input().split()))
    aa = aa[1:]
    if ans is None:
        ans = set(aa)
    else:
        ans = ans & set(aa)
print(len(ans))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
L = []
for i in range(N):
  L.append(list(map(int, input().split())))
  
#M種にいくつ票が入るか入れる
cnt = [0] * M


#N人の中でj番目の人の中でk番目の食べ物が好きであるかcntの票を足す
for j in range(N):
  for k in range(1, L[j][0]+1):
    cnt[L[j][k]-1]+= 1

#Nと同じ票入っているものだけcount
print(cnt.count(N))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

    ans = like_food.count(N)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
ans_list=list(input().split())[1:]
for i in range(n-1):
  l=len(ans_list)
  ans_list2=ans_list
  ans_list=[]
  keep=input().split()[1:]
  for j in range(l):
    if ans_list2[j] in keep:
      ans_list.append(ans_list2[j])
print(len(ans_list))

Submission status: Accepted

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

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


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

    foods = foods&fav

if len(foods)!=0:
    print(len(foods))
else:
    print(0)

Submission status: Accepted

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

Submission status: Accepted

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

cnt = [0] * m
for i 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))

Submission status: Accepted

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

a = []
b = list((0 for i in range(m)))

for i in range(n):
    a.append(list(map(int, input().split())))
    
for a_ in a:
    k = a_[0]
    for k_ in range(k):
        b[(a_[k_ + 1]) - 1] += 1
        
ans = 0
for b_ in b:
    if b_ == n:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

B = [0]*30

for i in range(N):
	K, *A = map(int, input().split())
	for a in A:
		B[a-1] += 1

print(sum(c == N for c in B))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
suki=[0]*M # これが最終的にNになったら皆好きてこと
for i in range(N):
  tmp=list(map(int, input().split()))
  for val in tmp[1:]:
    suki[val-1]+=1

ans=suki.count(N)
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict
N, M = list(map(int, input().split()))
K = []
A = []
for _ in range(N):
    line = list(map(int, input().split()))
    K += [line[0]]
    A += [line[1:]]

count = defaultdict(int)
for a_ in A:
    for a in a_:
        count[a] += 1

result = 0
for k, v in count.items():
    if v == N:
        result += 1
print(result)

Submission status: Accepted

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

for j in a[0][1:]:
    for k in range(1, n):
        if not j in a[k][1:]:
            t -= 1
            break

print(t)

Submission status: Accepted

Solution code:
import numpy as np

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

cnt = 0
for i in A[0]:
    flg = True
    for j in range(1,N):
        if not i in A[j]:
            flg = False
            break
    if flg:
        cnt +=1
print(cnt)

Submission status: Accepted

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

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

ans = 0
from collections import Counter
cnt = Counter(A)
for k,v in cnt.items():
    if v == n:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
kal = [list(map(int, input().split())) for i in range(n)]
rl = kal[0][1:]
for l in kal:
    rl = set(l[1:]) & set(rl)
print(len(rl))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    from collections import Counter
    from itertools import chain
    N, M = list(map(int, input().split()))
    A = [list(map(int, input().split()))[1:] for _ in range(N)]
    c = Counter(chain(*A))
    print(len([v for v in c.values() if v >= N]))
    

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def check(A):
  check_result = []
  for i in range(1, len(A)):
    check_result.append(list(set(A[i-1])&set(A[i])))
  if len(check_result) != len(A):
    return check_result
  return False

N, M = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
for i in range(len(A)):
  A[i].pop(0)
while True:
  check_result = check(A)
  if check_result:
    A = check_result
  else:
    if not A[0]:
      print(0)
      break
    else:
      print(len(A[0]))
      break

Submission status: Accepted

Solution code:
def check(A):
  check_result = []
  for i in range(1, len(A)):
    check_result.append(list(set(A[i-1])&set(A[i])))
  if len(check_result) != len(A):
    return check_result
  return False

N, M = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]
result = []
for i in range(len(A)):
  A[i].pop(0)
while True:
  check_result = check(A)
  if check_result:
    A = check_result
  else:
    if not A[0]:
      print(0)
      break
    else:
      print(len(A[0]))
      break

Submission status: Accepted

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

Submission status: Accepted

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

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

for j in range(1,31):
	d=b.count(j)
	if d==n:
		c+=1
print(c)

Submission status: Accepted

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

Submission status: Accepted

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

K = [0]*N

A = [[] for i in range(N)]

Dict ={}

for i in range(N):
    temp = list(map(int,input().split()))
    K[i] = temp[0]
    A[i] = temp[1:]
    
for i in range(M):
    Dict[i+1]=0
    
cnt = 0


for i in range(N):
    
    for j in A[i]:
        Dict[j]+=1
        
        
for i in Dict.keys():
  
    if Dict[i] >=N:
        cnt+=1
        
print(cnt)

Submission status: Accepted

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

matrix = [[ False for _ in range(n)] for _ in range(m)]
#横が人，縦がしなもの


for person_id in range(n):
    person = people[person_id]
    for konomi_num in person[1:]:
        matrix[konomi_num-1][person_id] = True
ans = 0
for food in range(m):
    if all(matrix[food]):
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
L = set(range(1,M+1,1))
suki = [1]*M
for i in range(N):
  indata = list(map(int, input().split()))
  K = set(indata[1:])
  Kbar = L-K
  for j in Kbar:
    suki[j-1]=0

ans = sum(suki)
print(ans)

Submission status: Accepted

Solution code:
N, _ = map(int, input().split())
KA = [list(map(int, input().split())) for _ in range(N)]
ans = set()
for i, ka in enumerate(KA):
  a = set(ka[1:])
  if not i:
    ans = a
  else:
    ans = ans & a
    
print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

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

ans = [0]*m
for i in range(n):
    for j in range(1,k[i][0]+1):
        ans[k[i][j]-1] += 1

print(ans.count(n))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def f11():
    N, M=map(int, input().split())
    item=[0 for i in range(M)]
    for i in range(N):
        A = [int(j) for j in input().split()]
        for j in range(A[0]):
            item[A[j+1]-1] += 1
    print(sum([1 if item[i]==N else 0 for i in range(M)]))

def main():
    f11()

main()

Submission status: Accepted

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

Submission status: Accepted

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

for i in apple:
    i.pop(0)
orange = []
for i in apple:
    for j in i:
        orange.append(j)
cat = 0
for i in range(m):
    if orange.count(i + 1) == n:
        cat += 1
    else:
        pass
print(cat)

Submission status: Accepted

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

foods = set(list(range(1, M + 1)))
for i in range(N):
    inp = list(map(int, input().split()))
    foods = foods & set(inp[1:])

print(len(foods))

Submission status: Accepted

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

for i in range(0,n):
  a[i] = input().split()
  k[i] = a[i][0]
  del a[i][0]
c = [0]*m

for i in range(0,n):
  for j in range(0,int(k[i])):
    c[int(a[i][j])-1] += 1
k = 0
for i in range(0,m):
  if(c[i] == n):
    k += 1
    
print(k)

Submission status: Accepted

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

K = []
A = []
for i in range(N):
    k, *a = map(int, input().split())
    K += [k]
    A += a

counter = 0
for j in range(1,M+1):
    if A.count(j) == N:
        counter += 1

print(counter)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
q = [list(map(int,input().split())) for p in range(n)]
ans = [0]*m
for qq in q:
	for t in qq[1:]:
		ans[t-1] += 1
t = 0
for a in ans:
	if a == n:
		t += 1
print(t)

Submission status: Accepted

Solution code:
# For taking integer inputs.
def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


N, M = invr()
K = []
for i in range(N):

    temp = inlist()
    temp = temp[1:]
    K.append(set(temp))
res = K[0]
for i in range(1, N):
    res = res.intersection(K[i])
print(len(res))

Submission status: Accepted

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

s = list(map(int, input().split()))
s.pop(0)

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

Submission status: Accepted

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

x = {i + 1 for i in range(M)}
for _ in range(N):
    x &= set(list(map(int, input().split()))[1:])
print(len(x))

Submission status: Accepted

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

print(a.count(n))

Submission status: Accepted

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

ans = 0
for li in like:
    if li == n:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
K, A = [], []
for _ in range(N):
    ka = list(map(int, input().split()))
    k = ka.pop(0)
    K.append(k)
    A.append(ka)

count = [0] * M
for i in range(N):
    for j in range(len(A[i])):
        count[A[i][j]-1] += 1
print(len([i for i, x in enumerate(count) if x == N]))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
KA=[list(map(int,input().split())) for _ in range(N)]
c=[0]*M
  
for m in range(N):
  a=KA[m][0]+1
  for n in range(1,a):
    c0=KA[m][n]
    c[c0-1]+=1 
print(c.count(N))

Submission status: Accepted

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

ans = 0
for li in like:
    if li == n:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

A = list(map(int,input().split()))
A.pop(0)

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

print(len(A))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

like = [0]*M

for i in range(N):
    for j in range(K[i]):
        like[A[i][j]-1] += 1 

print(like.count(N))

Submission status: Accepted

Solution code:
import sys

N, M = map(int, input().split())
A = [list(map(int, sys.stdin.readline().rsplit()))[1:] for _ in range(N)]
S = [0] * M

for i in range(N):
    for a in A[i]:
        S[a - 1] += 1

res = 0
for s in S:
    if s == N:
        res += 1
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
import math
import fractions
import functools
import copy
n, m = map(int, input().split())
k = []
a = []
for i in range(n):
    l  = list(map(int, input().split()))
    k.append(l[0])
    a.append(l[1:])

ans = [0]*(m+1)

for i in range(n):
    for j in range(len(a[i])):
        ans[a[i][j]] +=1

print(ans.count(n))

Submission status: Accepted

Solution code:
from collections import deque
n, m = map(int, input().split())
a = [0]*m
for _ in range(n):
    A = deque(map(int, input().split()))
    k = A.popleft()
    if _ == 0:
        S = set(A)
    else:
        S = S & set(A)
print(len(S))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
n,m = map(int,input().split())
for i in range(n):
    A = deque(map(int,input().split()))
    k = A.popleft()
    if i == 0:
        S = set(A)
    else:
        S = S & set(A)

print(len(S))

Submission status: Accepted

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

Submission status: Accepted

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

ans = [0]*m

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

    for i in a[1:]:
        ans[i-1] += 1

cnt = 0

for i in ans:
    if i == n:
        cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
import bisect
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#############
# Main Code #
#############

N,M = inputIL()
data = inputILL(N)

s = set(i+1 for i in range(M))
for item in data:
  s &= set(item[1:])



print(len(s))

Submission status: Accepted

Solution code:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    n,m=map(int, readline().rstrip().split())
    cnt=[0]*100
    for i in range(n):
        arr=list(map(int, readline().rstrip().split()))
        for j in range(1,len(arr)):
            cnt[arr[j]]+=1
    ans=0
    for c in cnt:
        if c==n:
            ans+=1
    print(ans)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------