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):
    a = [int(i) for i in input().split()]
    for ai in a[1:]:
        cnt[ai - 1] += 1

print(cnt.count(n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
diff = []
for i in range(N):
    like = list(map(int,input().split()))
    like.pop(0)
    diff += like
likesum = 0
for i in range(M):
    if diff.count(i+1) == N:
        likesum += 1
print(likesum)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

n,m=list(map(int,input().split()))
t=np.zeros(m)
for i in range(n):
  tmp=list(map(int,input().split()))  
  for j in range(tmp[0]):
    t[tmp[j+1]-1] += 1
  
maxIndex = [i for i, x in enumerate(t) if x == n]
print(len(maxIndex))

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(" "))
a = [0]*(m+1)
c = 0
for i in range(n):
  s = list(map(int, input().split(" ")))
  for j in range(1,s[0]+1):
    if j != 0:
      a[s[j]] += 1
      if a[s[j]] == n:
        c+=1
print(c)

Submission status: Accepted

Solution code:
N,M = input().split()
N = int(N); M = int(M)
F = []
for i in range(N):
    a = input()
    a = [int(x) for x in a.split()]
    del a[0]
    F.append(a)
res = []
for idx in range(1,M+1):
    cnt = 0
    for pep in F:
        if idx in pep:
            cnt += 1
    res.append(cnt)
print(res.count(N))

Submission status: Accepted

Solution code:
from collections import defaultdict
N, M = map(int, input().split())

a_dic = defaultdict(int)
for _ in range(N):
    a_list = list(map(int, input().split()))[1:]

    for a in a_list:
        a_dic[a] += 1

ans = 0
for val in a_dic.values():
    if val == N:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,m = LI()
    r = set(list(range(1,m+1)))
    for _ in range(n):
        r &= set(LI()[1:])

    return len(r)



print(main())

Submission status: Accepted

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

ans = A[0]
for i in range(1,N):
    t = []
    for a in A[i]:
        if a in ans:
            t.append(a)
    ans = t

print(len(ans))

Submission status: Accepted

Solution code:
N, M = [int(i) for i in input().split()]
ks = list()
for i in range(N):
  ks.append({int(i) for i in input().split()[1:]})
result = set(range(1,M+1)).intersection(*ks)
print(len(result))

Submission status: Accepted

Solution code:
#入力
N, M = map(int,input().strip().split(' '))
KA = []
for i in range(N):
    KA.append(list(map(int, input().strip().split(' '))))	#[A][B]

#処理用
i = 0
j = 0
k = 0
syurui = 0
suki_cnt = [0] * (M + 1)  #種類カウンタ


#処理
##print(suki_cnt)

for i in range(N):
    for j in range(1,len(KA[i])):
        suki_cnt[KA[i][j]] += 1

for i in range(len(suki_cnt)):
    if suki_cnt[i] == N:        #人数と同じか
        syurui += 1
    else:
        pass
    
print(syurui)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#abc118b

n,m=map(int,raw_input().split())
s=set(range(1,31))
for i in xrange(n):
 l=map(int,raw_input().split())
 s&=set(l[1:])
print len(s)

Submission status: Accepted

Solution code:
import numpy as np
import math
import sys

n,m = list(map(int, input().split()))
a = np.asarray([])
r = np.asarray([])
for _ in range(n):
    a = np.append(a,(list(map(int, input().split()))[1:]))
for i in range(m):
    r = np.append(r,np.size(a[a==i+1]))
#print(r)
print(np.size(r[r==n]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

# import bisect
# import math
# import itertools

# import numpy as np


"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    n, m = ip.IL()
    res = [[False for _ in r(m)] for _ in r(n)]

    for i in r(n):
        o = ip.IL()
        for j, x in e(o):
            if j != 0:
                res[i][x - 1] = True

    ans = 0
    for i in r(m):
        rr = 0
        for j in r(n):
            if res[j][i]:
                rr += 1
        if rr == n:
            ans += 1

    print(ans)


main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import sys
import random
from operator import itemgetter
input = sys.stdin.readline

# a = int(input().rstrip())
# a, b = map(int, input().rstrip().split())
# D = list(map(int, input().rstrip().split()))
# H = [int(input().rstrip()) for _ in range(L)]
# DD = [[0 for j in range(100)] for i in range(200)]
# dict = {} ## dictionary

# a = sorted(a, key=lambda x: x[1]))
# if __name__ == '__main__':


N, M = map(int, input().rstrip().split())
ans = []
for i in range(M):
	ans.append(i+1)
ans_set = set(ans)

for i in range(N):
	tmp = list(map(int, input().rstrip().split()))
	ans_set = ans_set & set(tmp[1::])
print(len(ans_set))

Submission status: Accepted

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


def main():
    n, m = map(int, input().split())
    ans = [0 for _ in range(30)]

    for i in range(n):
        ka = list(map(int, input().split()))

        for j in ka[1:]:
            ans[j - 1] += 1

    result = 0

    for a in ans:
        if a == n:
            result += 1

    print(result)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m = (int(i) for i in input().split())
like = {}
for i in range(n):
    tmp = list(int(i) for i in input().split())
    for j in range(len(tmp)):
        if not j==0:
            if not tmp[j] in like:
                like[tmp[j]] = 1
            else:
                like[tmp[j]] += 1

count = 0
for k, v in like.items():
    if v == n:
        count += 1

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
nm = [int(i) for i in input().split()]

tmp = [int(i) for i in input().split()]
tmp2 = tmp[1:]
list = set(tmp2)
for i in range(1,nm[0]):
  tmp = [int(i) for i in input().split()]
  tmp2 = tmp[1:]
  list = set(tmp2) & list 
print(len(list))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
preferances = [list(map(int, input().split()))[1:] for _ in range(N)]
all_kind_of_food = [i for i in range(1, M + 1)]
check_for_foods = [i for i in range(1, M + 1)]
for i in range(N):
  for j in range(M):
    if all_kind_of_food[j] in check_for_foods and (not all_kind_of_food[j] in preferances[i]):
      check_for_foods.remove(all_kind_of_food[j])
print(len(check_for_foods))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a = [list(map(int, input().split()))[1:] for _ in range(N)]
b = [i for i in range(1, M + 1)]
c = [i for i in range(1, M + 1)]
for i in range(N):
  for j in range(M):
    if b[j] in c and (not b[j] in a[i]):
      c.remove(b[j])
print(len(c))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a = [sorted(list(map(int, input().split()))[1:]) for _ in range(N)]
b = [i for i in range(1, M + 1)]
c = [i for i in range(1, M + 1)]
for i in range(N):
  for j in range(len(b)):
    if (not b[j] in a[i]) and b[j] in c:
      c.remove(b[j])
print(len(c))

Submission status: Accepted

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


def main():
    N, M = [int(a) for a in input().split()]
    A = [
        set([int(a) for a in input().split()][1:])
        for _ in range(N)
    ]

    r = A[0]
    for k in A[1:]:
        r = r.intersection(k)
    print(len(r))


if __name__ == '__main__':
    main()

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 j in range(1,K[0]+1):
        M[K[j] - 1] += 1

cnt = 0
for i in range(m):
    if M[i] >= n:
        cnt += 1
print(cnt)

Submission status: Accepted

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

count = 0
for y in S:
  if y == N:
    count+=1

print(count)

Submission status: Accepted

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

Submission status: Accepted

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

for i,p in enumerate(people):
    if i == 0:
        most_list = p[1:]
        continue
    tmp = []
    for j in range(1, len(p)):
        if p[j] in most_list:
            tmp.append(p[j])
    if len(tmp) == 0:
        print(0)
        exit()
    most_list = tmp
print(len(most_list))

Submission status: Accepted

Solution code:
import numpy as np
n,m = map(int, input().split())

flag = np.zeros(m, dtype = np.int32)
ka = []
for i in range(n):
    ka = np.array(list((map(int, input().split()))))
    ka -= 1
    flag[ka[1:]] += 1
    if np.max(flag) != i + 1:
        print("0")
        exit()
print(len(flag[flag==n]))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
like = [0 for _ in range(M + 1)]
for _ in range(N):
    t = list(map(int, input().split()))
    for tt in t[1:]:
        like[tt] += 1
print(sum(1 if x == N else 0 for x in like))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

s = [0] * m

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

ans = 0
for x in s:
    if x == n:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
num_of_person, num_of_foods = map(int, input().split())

if num_of_person == 0:
    print("0")

common_favorit_food_set = set()
for i in range(num_of_person):
    research = list(map(int, input().split()))
    num_of_favorit = research[0]
    favorit_set = set(research[1:])
    if i == 0:
        common_favorit_food_set = favorit_set
    else:
        common_favorit_food_set &= favorit_set


print("{}".format(len(common_favorit_food_set)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
array=[]
for i in range(n):
    k=input().split()
    k=list(map(int,k))
    array.append(k[1:])
items=[]
s=0
for v in array:
    for item in v:
        items.append(item)  
for i in range(1,m+1):
    cnt=0
    for j in range(len(items)):
        if items[j]==i:
            cnt+=1
    if cnt==n:
        s+=1
print(s)        
#print(items)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
l = [set([int(i) for i in input().split()][1:]) for j in range(n)]
ans = 0

for x in range(1, m+1):
	flag = 1
	for y in l:
		if x not in y:
			flag = 0
	ans += flag
print(ans)

Submission status: Accepted

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

r = [0 for x in range(0, m)]

for _ in range(0, n):
    a = [x for x in map(int, input().split())]
    for i in a[1:]:
        r[i - 1] += 1

print('{}'.format(len([x for x in r if x == n])))

Submission status: Accepted

Solution code:
print(len(set.intersection(*[set(input().split()[1:])for _ in[0]*int(input()[:2])])))

Submission status: Accepted

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


for i in range(1,M+1):
    flag = 1
    for j in range(N):
        if i not in A[j][1:]:
            flag = 0
    if flag == 1:
        count += 1

print(count)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a = {i for i in range(1, M + 1)}
for _ in range(N):
  b = [int(x) for x in input().split()];
  a &= set(b[1:])

print(len(a))

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())
food_list=[]
for i in range(N):
    data = list(map(int,input().split()))
    food_list = food_list + data[1:]
result =0
for j in range(M):
    if food_list.count(j+1) == N:
        result += 1
print(result)

Submission status: Accepted

Solution code:
from functools import reduce

if __name__ == '__main__':
    n, m = map(int, input().split())
    likes = [set(input().split()[1:]) for _ in range(n)]
    print(len(reduce(lambda x, y: x.intersection(y), likes, set(str(i) for i in range(1, m + 1)))))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import collections

N = int(sys.stdin.readline().strip().split()[0])

new = []
for i in range(N):
  tmp = sys.stdin.readline().strip().split()
  for j in range(len(tmp)-1):
    new.append(tmp[j+1])

c = collections.Counter(new)


cnt = 0
for i in range(len(c.most_common())):
  if int(c.most_common()[i][1]) == N:
    cnt += 1
  else:
    break
    
print(cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import collections
n,k = map(int, input().split())
l=[]
for i in range(n):
    x = list(map(int, input().split()))
    l+=x[1:]
c = collections.Counter(l)
s=0
for i in c.most_common():
    #print(i)
    if n == i[1]:
        s+=1
print(s)

Submission status: Accepted

Solution code:
N ,M = map(int,input().split())
L = []
import collections as col
for _ in range(N):
    l = list(map(int,input().split()))
    tmp = l.pop(0)
    for x in l:
        L.append(x)
c = list(col.Counter(L).items())
cnt = 0
for x in c:
    if x[1] == N:
        cnt += 1

print(cnt)

Submission status: Accepted

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

inputs = [[i for i in input().split()] for _ in range(N)]

ans = set(inputs[0])
for item in inputs:
    ans &= set(item[1:])

print(len(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n,m = list(map(int,input().split()))
for i in range(n):
    if i == 0:
        a = set(list(map(int,input().split()))[1:])
        continue
    else:
        b = set(list(map(int,input().split()))[1:])
        a = a&b
print(len(a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

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

KS= set([])
for i in range(N):
    IA = list(map(int, input().split()))
    if i == 0:
        KS = set(IA[1:])
    else:  
        KS = KS.intersection(set(IA[1:]))

print(len(KS))

Submission status: Accepted

Solution code:
I=lambda:map(int,input().split())
N,M=I()
R=set(range(1,M+1))
for _ in [0]*N:_,*A=I();R&=set(A)
print(len(R))

Submission status: Accepted

Solution code:
nb_people, nb_foods = [int(x) for x in input().split()]
like_count = {}
for _ in range(nb_people):
    _, *liked = [int(x) for x in input().split()]
    for i in liked:
        like_count[i] = like_count.get(i, 0) + 1
cnt = 0
for x in like_count.values():
    if x == nb_people:
       cnt += 1
print(cnt)

Submission status: Accepted

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

from itertools import chain
from functools import reduce
from collections import OrderedDict, Counter, deque
import operator

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

t = Counter()
for _ in range(n):
    t += Counter(input().split()[1:])

print(sum(v == n for v in t.values()))

Submission status: Accepted

Solution code:
N, M = map( int, input().split())
ANS = [1]*(M+1)
ANS[0] = 0
for _ in range(N):
    C = list( map( int, input().split()))[1:]
    for i in range(1, M+1):
        if i in C:
            pass
        else:
            ANS[i] = 0
print( sum(ANS))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
l = []
for i in range(N):
    l.append([int(i) for i in input().split()])

check_list = [False] * M
for i in range(M):
    flag = True
    for j in range(N):
        if i+1 not in l[j][1:]:
            flag = False
    if flag:
        check_list[i] = True

print(check_list.count(True))

Submission status: Accepted

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

from itertools import chain
from functools import reduce
from collections import OrderedDict, Counter, deque
import operator

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

t = Counter()
for _ in range(n):
    t += Counter([int(x) for x in input().split()][1:])

print(sum(v == n for v in t.values()))

Submission status: Accepted

Solution code:
n, _ = map(int, 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())
a = []
for i in range(n):
  a.append(list(map(int, input().split())))
  del a[i][0]
  
count = []
result = 0

for _ in range(m):
  count.append(0)

for i in range(n):
  for j in range(1, m+1):
      if j in a[i]:
        count[j-1] += 1
      
for _ in range(m):
  if n in count:
    count.remove(n)
    result += 1
      
print(result)

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
if n == 1:
    print(input().split()[0])
else:
    kdict = {i:0 for i in range(1,m+1)}
    for _ in range(n):
        for i in map(int, set(input().split()[1:])):
            kdict[i] += 1
    print(len([i for i in kdict.values() if i == n]))

Submission status: Accepted

Solution code:
n, m = map(int, input().split(' '))
ans = [0 for _ in range(m)]
f = 0 
for _ in range(n):
  tmp = map(int, input().split(' ')[1:])
  for num in tmp:
    ans[num - 1] += 1

for num in ans:
  if num == n:
    f += 1
print(f)

Submission status: Accepted

Solution code:
import sys
count = []
cnt = 0
N,M = map(int,input().split())
for _ in range(N):
    A = input().split()
    count.extend(A[1:])
for _ in range(M+1):
    c = count.count('%d' %_)
    if c == N:
        cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
# B
N, M = map(int, input().split())
r_list = [0]*M
for _ in range(N):
    A_list = list(map(int, input().split()))[1:]
    for a in A_list:
        r_list[a-1] += 1
        
res = 0
for r in r_list:
    if r == N:
        res += 1
print(res)

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
# from collections import Counter, defaultdict

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n, m = LI()
score = [0] * m
for i in range(n):
    A = LI_()
    for a in A[1:]:
        score[a] += 1

print(score.count(n))

Submission status: Accepted

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

res = 0
for i in range(1,M+1):
    flag = 1
    for a in A:
        if i not in a:
            flag = 0
            break
    res += flag

print(res)

Submission status: Accepted

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

unko = []
for j in range(1,M+1):
     unko.append(j)

count = 0
ans = 0

for k in range(M):
    for l in range(N):
        if unko[k] in KA[l][1:]:
            count += 1
    if count == N:
        ans += 1
    count = 0
        
          
print(ans)

Submission status: Accepted

Solution code:
# -*- coding utf-8 -*-
N, M = (int(_) for _ in input().split())

A = [[0]]*N
for i in range(N):
    A[i] = [int(_) for _ in input().split()]

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

food = A.pop(0)
K = food.pop(0)

for i in range(N - 1):
    K = A[i].pop(0)
    food = list(set(food) & set(A[i]))

print(len(food))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
cnt = [0]*(m+1)
for i in range(n):
  li = list(map(int,input().split()))
  for i in range(1, len(li)):
    cnt[li[i]] += 1
print(len(list(filter(lambda x:x==n, cnt))))

Submission status: Accepted

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

Submission status: Accepted

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