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 = list(map(int, input().split()))
d = {}
ll = []
food = [i for i in range(m)]
food2 = []
for i in range(n):
	l = list(map(int, input().split()))
	ll.append(l)
for i in range(n):
	for j in range(1,ll[i][0]+1):
		if not ll[i][j] in food2:
			food2.append(ll[i][j])
			d.setdefault(ll[i][j],0)
		d[ll[i][j]] += 1
print(len([i for i in d.values() if i == n]))
#print(list(d.values()).count(n))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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())
s = set([i for i in range(1, m+1)])

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

print(len(s))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
s = []
for i in range(n):
    s.append(list(map(int,input().split())))
cnt = 0
for j in range(1,m+1):
    check = True
    for i in range(n):
        if not j in s[i][1::]:
            check = False
    if check:
        cnt += 1
print(cnt)

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 = list(map(int, input().split()))
like = []
for _ in range(n):
  ka = list(map(int, input().split()))
  k = ka[0]
  a = ka[1:]
  for e in a:
    like.append(e)

ans = 0
for i in range(1, m + 1):
  if like.count(i) == n:
    ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

d={n:0 for n in range(1,m+1)}

count=0

for i in range(n):
    k=[int(x) for x in input().split()]
    for j in range(1,len(k)):
        d[k[j]]+=1

for buf in range(1,m+1):
    if d[buf]==n:
        count+=1

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections as col
n, m = map(int, input().split())
t = [list(map(int,input().split())) for _ in range(n)]
t2 = []

for i in range(n):
    t[i].remove(t[i][0])
    t2 += t[i]

ans = col.Counter(t2)
ans = ans.values()
ans = list(ans)

print(ans.count(n))

Submission status: Accepted

Solution code:
n, m = map(int, input().split(' '))
_, *intersection = map(int, input().split(' '))
intersection = set(intersection)
for _ in range(1, n):
    _, *newlist = map(int, input().split(' '))
    intersection = intersection & set(newlist)
print(len(intersection))

Submission status: Accepted

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

for j in range(n):
  L=list(map(int,input().split()))

  for i in range(1,L[0]+1):
    s[L[i]-1][j]=1

for i in range(m):
  if s[i]==[1]*n:
    count+=1

print(count)

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)
ans = 0
print(len(s))

Submission status: Accepted

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

# input
N, M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]

# solve
ans = [0] * M
for i in range(N):
    for j in range(1, A[i][0] + 1):
        ans[A[i][j] - 1] += 1

# output
print(ans.count(N))

Submission status: Accepted

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

n, m = map(int, input().split())
foods = [1] * m
for n_i in range(n):
    ka = list(map(int, input().split()))
    k = ka[0]
    a = ka[1:]
    mask = [0] * m
    for a_i in a:
        mask[a_i-1] = 1
    for m_i in range(m):
        foods[m_i] *= mask[m_i]

print(sum(foods))

Submission status: Accepted

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

arr=[]
for _ in range(n):
  k,*a=list(map(int,input().split()))
  arr.extend(a)

c = collections.Counter(arr)

cnt=0
for c_ in c.most_common():
  if n == c_[1]:
    cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

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

cnt=0
for v in dic.values():
  if v == n:
    cnt+=1
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    n, m = map(int, input().split())
    ka = [list(map(int, input().split())) for _ in range(n)]
    common = set([i for i in range(1, m + 1)])
    for i in range(len(ka)):
        common = set(set(ka[i][1:]) & common)
    return len(common)


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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=[]
ans=[]
for _ in range(n):
        k=list(map(int,input().split()))
        l.append(k[1:])
for i in range(1,m+1):
        for j in range(n):
                if i in l[j]:
                        continue
                else:
                        break
        else:
                ans.append(i)
print(len(ans))

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())
fav = [0] * m
for _ in [0]*n:
    k, *A = map(int, input().split())
    for a in A:
        fav[a-1] += 1
print(len(list(filter(lambda x: x == n, fav))))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import copy

inputa = input().split()
# inputb = input().split()
# inputc = input().split()

a = int(inputa[0])
b = int(inputa[1])
# c = int(inputa[2])

# inputb = input().split()
# inputbint = [int(x) for x in inputb]
# inputList = list(b)

# x = int(inputb[0])
# y = int(inputb[1])

inputList=[]
for i in range(a):
    inputNum = input().split()
    inputNum = [int(x) for x in inputNum]
    inputList.append(inputNum)

# inputList = [int(n) for n in inputList]

# b = [int(n) for n in inputb]
# c = [int(n) for n in inputc]

ans = [True]*b

for i in range(len(inputList)):
    anstmp = [False]*b

    for j in range(1, len(inputList[i])):
        anstmp[inputList[i][j]-1] = True

    for j in range(b):
        ans[j] = ans[j] * anstmp[j]

cnt = 0
for i in range(b):
    if ans[i] == True:
        cnt += 1

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=input().split()
n,m=int(n),int(m)
#辞書に気づけ
b={}
for i in range(n):
    x=input().split()
    for j in range(int(x[0])):
        if int(x[j+1]) not in b:
            b[int(x[j+1])]=1
        else:
            b[int(x[j+1])]+=1
c=0
for i in b:
    if b[i]==n:
        c+=1
print(c)

Submission status: Accepted

Solution code:

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

pos_list = []

for i in range(n):
    k, *a = map(int, input().split())
    if i == 0:
        pos_list = a
    else:
        pos_list = [pos for pos in pos_list if pos in a]

print(len(pos_list))

Submission status: Accepted

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

tabecol = {}
for n in range(N):
    for tabe in A[n][1:]:
        if tabe in tabecol:
            tabecol[tabe] += 1
        else:
            tabecol[tabe] = 1

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

Submission status: Accepted

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

ans = 0
i_list = []

for i in range(N):
	tmp_list = list(map(int,input().split()))
	i_list.extend(tmp_list[1:])

for i in range(1,M+1):
  if i_list.count(i) == N:
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
like=[0]*(M+1)
for _ in range(N):
  arr=list(map(int,input().split()))
  for v in arr[1:]:
    like[v]+=1
print(sum([v==N for v in like]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
c=list(map(int,input().split()))[1:]
#print(c)
for _ in range(a-1):
  #print(range(a))
  d=list(map(int,input().split()))[1:]
  #print(d)
  c=set(c)&set(d)

#print(c)
print(len(c))

Submission status: Accepted

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

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

answer = 0
for i in range(m):
    if like[i] == n:
        answer += 1

print(answer)

Submission status: Accepted

Solution code:


n,m = [int(x) for x in input().split()]
print(len(set.intersection(*[set(input().split()[1:]) for _ in range(n)])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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:
from collections import defaultdict
n, m = map(int, input().split())
s = []
for _ in range(n):
    k, *a = map(int, input().split())
    s.append(a)
dd = defaultdict(int)
for l in s:
    for k in l:
        dd[k] += 1

print(sum(1 if v == n else 0 for k, v in dd.items()))

Submission status: Accepted

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

hantei = [0] * 30
count = [0] * 30
for j in range(0,30):
    hantei[j] = j + 1

for i in range(N):
    for j in range(1,int(K[i][0])+1):
        for k in range(0,30):
            if int(K[i][j]) == hantei[k]:
                count[k] += 1

ans = 0
for  k in range(0,30):
    if count[k] == N:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ml = []
for j in range(m):
    ml.append(j + 1)
r = set(ml)
for i in range(n):
    li = list(map(int, input().split()))
    r = r & set(li[1:])
print(len(r))

Submission status: Accepted

Solution code:

n, m = map(int, input().split())
likes = [0] *  m

for i in range(n):
    k, *a = map(int, input().split())
    for j in a:
        likes[j-1] += 1

count = 0
for i in likes:
    if i == n:
        count += 1

print(count)

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())
ka = [list(map(int, input().split()))[1:] for _ in range(n)]

ans = 0
for i in range(1, m+1):
  cnt = 0
  for j in ka:
    if i in j:
      cnt += 1
  if cnt == n:
    ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a = []
for i in range(n):
    k = list(map(int, input().split()))
    a.append(k[1:])
cnt = 0
for i in range(1, 31):
    key = 1
    for j in range(n):
        if i not in a[j]:
            key = 0
            break
    if key == 1:
        cnt += 1
print(cnt)

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())
m_s = set(range(1,m+1))
for i in range(n):
  K,*A=map(int,input().split())
  m_s = m_s & set(A) 
print(len(m_s))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
# 集合の積をとっていく。、SETを使う
set_m = set(range(1, m+1))
for i in range(n):
    k, *a = map(int, input().split())
    set_m &= set(a)
print(len(set_m))

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
  amenu=[False]*m # その人のリスト　すべてFalse
  a=list(map(int,input().split()))
  a.pop(0)
  for j in range(len(a)):
    amenu[a[j]-1]=True # 含まれていればTrueにする
    
  for p in range(len(amenu)):
    if amenu[p]==False:
      menu[p]=False

count=0
for i in range(len(menu)):
  count = count + menu[i]

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

a = set(str(x) for x in range(1,M+1))
for i in range(N):
  li = list(input().split())
  a = a & set(li[1:])

print (len(a))

Submission status: Accepted

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

Submission status: Accepted

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

like = [0] * (m+1)

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

cnt = 0
for i in range(len(like)):
    if like[i] == n:
        cnt += 1

print(cnt)

Submission status: Accepted

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

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

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 = [list(map(int, input().split())) for _ in range(N)]

ans = 0
l = sorted(k, key=lambda l: l[0])
small = l[0]
others = l[1:]

for i in small[1:]:
    if all([i in o[1:] for o in others]):
        ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

#print(ans)

for i in range(n):
    for j in range(1, m+1):
        if j not in a[i] and j in ans:
            ans.remove(j)

#print(ans)
print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

import collections

N, M = list(map(int, input().split()))
likes = []
for i in range(N):
    x = list(map(int, input().split()))
    _ = x.pop(0)
    likes += x

col = collections.Counter(likes)
count = 0
for k, v in col.items():
    if v == N:
        count += 1

print(count)

Submission status: Accepted

Solution code:

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

    base.append(tmp)

base = list(map(list, zip(*base)))

count = 0
for x in base:
    if not 0 in x:
        count += 1

print(count)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
M = [0]*M
for i in range(N):
    likes = [int(i) for i in input().split()]
    for i in range(1,len(likes)):
        M[likes[i]-1]+=1
count = 0
for item in M:
    if item == N:
        count += 1
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

N, M = map(int, input().split())
k = [None] * N
a = [None] * N
for i in range(N):
    ka = list(map(int, input().split()))
    k[i] = ka[0]
    a[i] = ka[1:]

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

    if count >= N:
        ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in a:
  for j in range(len(i)):
    b.append(i[j])
c = 0
for i in range(m):
  if b.count(i+1) == n:
    c += 1
print(c)

Submission status: Accepted

Solution code:
'''
考え方
n行 m列の行列
「全ての行に登場する数字」の種類数を数える

'''

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

# print(k_rows)

## 全行の積集合を取得
# 全てのmをリスト化
k_intersection = range(1,m+1)
for k_row in k_rows:
    # print(k_intersection)
    # print(k_row[1:])
    k_intersection = set(k_intersection) & set(k_row[1:])

# print(k_intersection)
print(len(k_intersection))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
A = []
for i in range(n):
    a = input().split()
    A.extend(a[1:])
words = list(set(A))
result = 0
for j in range(len(words)):
    if A.count(words[j]) == n:
        result += 1
print(result)

Submission status: Accepted

Solution code:
mp = []
Tmp = input().rstrip().split(' ')
 
nN = int(Tmp[0])
nM = int(Tmp[1])
 
nF = [ 0 for i in range(nM)]
 
for i in range(nN):
  Tmp = input().rstrip().split(' ')
  nTmpN = int(Tmp[0])
  for j in range(nTmpN):
    nCnt = int(Tmp[j+1]) - 1
    nF[nCnt] += 1

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

print(nAns)

Submission status: Accepted

Solution code:
"""
# 標準入力取得
## 文字列
     = sys.stdin.readline().rstrip()
     = list(sys.stdin.readline().rstrip())

## 数値
     = int(sys.stdin.readline())
     = map(int, sys.stdin.readline().split())
     = list(map(int, sys.stdin.readline().split()))
     = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

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

mod = 1000000007

if __name__ == "__main__":
    N, M = map(int, sys.stdin.readline().split())
    like = [0 for _ in range(M)]
    for _ in range(N):
        ans = list(map(int, sys.stdin.readline().split()))
        for a in ans[1::]:
            like[a - 1] += 1

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

    print(cnt)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
menu = [0 for _ in range(m)]
for i in range(n):
  now = list(map(int,input().split()))
  del now[0]
  for x in now:
    menu[x-1] += 1
for j in range(m):
  if menu[j] == n:
    menu[j] = 1
  else:
    menu[j] = 0
print(sum(menu))

Submission status: Accepted

Solution code:
#118
n, m = (int(_) for _ in input().split())
ans = 0
food = [0 for i in range(m)]
for i in range(n):
    person = [int(_) for _ in input().split()]
    for j in range(1, person[0] + 1):
        food[person[j] - 1] += 1
for f in food:
    if f == n:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
dp = [0]*(M+1)
for _ in range(N):
    l = list(map(int, input().split()))
    for e in l[1:]:
        dp[e] += 1
ans = 0
for e in dp:
    if e == N:
        ans += 1
print(ans)

Submission status: Accepted

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


N, M = map(int, input().split(' '))
intersection = None
for _ in range(N):
    k, *a = map(int, input().split(' '))
    if intersection is None:
        intersection = set(a)
    else:
        intersection = intersection & set(a)

print(len(intersection))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(x.count(n))

Submission status: Accepted

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

a = list(map(int, input().split()))
for  j in range(1, len(a)):
    foods.add(a[j])

for i in range(n-1): 
    a = list(map(int, input().split()))
    for j in range(1,len(a)):
        tmp.add(a[j])
    foods &= tmp
    tmp.clear()
    
print(len(foods))

Submission status: Accepted

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

s = set(range(1, M+1))
for k, *A in KA:
  s &= set(A)
print(len(s))

Submission status: Accepted

Solution code:
def solve():
    N,M = map(int, input().split())
    foods = [0]*M
    for _ in range(N):
        A = map(int, input().split()[1:])
        for idx in A:
            foods[idx-1] += 1
    
    print(sum(food == N for food in foods))
    
solve()

Submission status: Accepted

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

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

print(li.count(n))

Submission status: Accepted

Solution code:
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

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

mod = 1000000007

if __name__ == "__main__":
    n,m = map(int, sys.stdin.readline().split())
    l= [list(map(int,list(sys.stdin.readline().split()))) for i in range(n)]
    c=0
    if n ==1:
        print(l[0][0])
    else:
        for i in range(1,m+1):
            flag = 0
            for j in range(n):
                if i not in l[j][1:]:
                    flag = 1
            if flag == 0:
                c+=1
        print(c)

Submission status: Accepted

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

cnt = 0
for i in range(1, m+1):
    flag = True
    for j in range(len(a)):
        if not i in a[j]:
            flag = False
    if flag:
        cnt += 1

print(cnt)

Submission status: Accepted

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

common=[]

for i in range(n):
    k,*a=list(map(int,input().split()))
    common.extend(a)
print(len([num for num in set(common) if common.count(num)==n] ))

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

arr = [0 for j in range(M)]

for i in range(N):
    line = [int(x) for x in input().split()]
    for j in line[1:]:
        arr[j-1] += 1

print(arr.count(N))

Submission status: Accepted

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

for j in range(N):
    List[j].remove(List[j][0])

ans = 0
for k in range(len(List[0])):
    num = 0
    for l in range(1,N):
        if List[0][k] in List[l]:
            num += 1
        else:
            break
    if num == N-1:
        ans += 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

dic = {}
for i in range(n):
    for j in range(1, k[i][0]+1):
        if k[i][j] in dic:
            dic[k[i][j]] += 1
        else:
            dic[k[i][j]] = 1

ans = 0
for i in dic.values():
    if n == i:
        ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
nm = list(map(int, input().split(' ')))
n = nm[0]
m = nm[1]
backet = [0 for _ in range(m)]
for _ in range(n):
    likes = list(map(int, input().split(' ')))[1:]
    for like in likes:
        backet[like - 1] += 1
res = backet.count(n)
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

d = {}
for i in range(n):
    arr = list(map(int,input().split()))
    for j in range(1,arr[0]+1):
        if not arr[j] in d:
            d[arr[j]] = 1
        else:
            d[arr[j]] += 1

ans = 0

for k in d.keys():
    if d[k] == n:
        ans += 1

# print(d)
print(ans)

Submission status: Accepted

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

l = [0]*m

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
I=lambda:input().split()
n,m=I();s=set(I()[1:])
for _ in[0]*(int(n)-1):s&=set(I()[1:])
print(len(s))