Harryxun/stf_run huggingface dataset:
from functools import reduce
import operator
MOD = 10**9+7
product = lambda it: reduce(lambda x,y: (x*y)%MOD,it,1)

N,K = map(int,input().split())
A = list(map(int,input().split()))

from fractions import Fraction

def solve():
    if N == K:
        return product(A)

    if all(v < 0 for v in A):
        A.sort()
        return product(A[-K:])

    A.sort(key=lambda x: abs(x))

    if A[-K] == 0:
        return 0

    parity = sum(v < 0 for v in A[-K:])%2
    if parity == 0:
        return product(A[-K:])

    fp = N-K
    while fp < N and A[fp] < 0:
        fp += 1

    fn = N-K
    while fn < N and A[fn] > 0:
        fn += 1


    lp = N-K-1
    while lp >= 0 and A[lp] < 0:
        lp -= 1

    ln = N-K-1
    while ln >= 0 and A[ln] > 0:
        ln -= 1

    if fp < N and ln >= 0:
        r1 = Fraction(-A[ln],A[fp])
    else:
        r1 = 0
    if fn < N and lp >= 0:
        r2 = Fraction(-A[lp],A[fn])
    else:
        r2 = 0
    if r1 > r2:
        return (product(A[-K:])*A[ln]*pow(A[fp],-1,MOD))%MOD
    else:
        return (product(A[-K:])*A[lp]*pow(A[fn],-1,MOD))%MOD

print(solve())

### FIXED CODE ###

from functools import reduce
import operator
MOD = 10**9+7
mprod = lambda it: reduce(lambda x,y: (x*y)%MOD,it,1)
nprod = lambda it: reduce(lambda x,y: (x*y),it,1)


from fractions import Fraction

def solve(A,K):
    N = len(A)
    if N == K:
        return mprod(A)

    if all(v <= 0 for v in A) and K%2 == 1:
        A.sort()
        return mprod(A[-K:])

    A.sort(key=lambda x: abs(x))

    if A[-K] == 0:
        return 0

    parity = sum(v < 0 for v in A[-K:])%2
    if parity == 0:
        return mprod(A[-K:])

    rp = N-K
    while rp < N and A[rp] < 0:
        rp += 1

    rn = N-K
    while rn < N and A[rn] > 0:
        rn += 1


    lp = N-K-1
    while lp >= 0 and A[lp] < 0:
        lp -= 1

    ln = N-K-1
    while ln >= 0 and A[ln] > 0:
        ln -= 1

    if rp < N and ln >= 0:
        r1 = Fraction(-A[ln],A[rp])
    else:
        r1 = 0
    if rn < N and lp >= 0:
        r2 = Fraction(-A[lp],A[rn])
    else:
        r2 = 0
    if r1 > r2:
        return (mprod(A[-K:])*A[ln]*pow(A[rp],-1,MOD))%MOD
    else:
        return (mprod(A[-K:])*A[lp]*pow(A[rn],-1,MOD))%MOD

from itertools import combinations
def naive(A,K):
    return max(nprod(p) for p in combinations(A,K))%MOD


if __name__ == '__main__':
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    
    print(solve(A,K)%MOD)

    # from random import randrange

    # N = 9
    # K = 8
    # for _ in range(100000):
    #     A = [randrange(-8,8) for _ in range(N)]
    #     if solve(A.copy(),K) != naive(A.copy(), K):
    #         print(A, solve(A.copy(),K),naive(A.copy(), K) )
n=int(input())

ans="no"

for i in range(9):
  if n%(9-i)==0:
    if n/(9-i)<10:
      ans="yes"
print(ans)

### FIXED CODE ###

a,b=map(int,input().split())

if 1<=a<=9 and 1<=b<=9:
    print(a*b)
else:
    print(-1)
n=int(input())
v=list(map(int, input().split())).sort()
sum=v[0]
for i in range(1,len(v)):
  sum=(sum+v[i])/2
print(sum)

### FIXED CODE ###

n=int(input())
v=list(map(int, input().split()))
v.sort()
sum=v[0]
for i in range(1,len(v)):
  sum=(sum+v[i])/2
print(sum)
import numpy as np

N, K = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(N)]
MOD = 10 ** 9 + 7

A = np.array(a, dtype = 'int64')
A = A.T

ans = np.eye(N, dtype = 'int64')
while K:
  if K & 1:
    ans = np.dot(ans, A)
    ans %= MOD
  A = np.dot(A, A)
  A %= MOD
  K >>= 1

print(int(np.sum(abs(ans))) % MOD)

### FIXED CODE ###

import numpy as np

N, K = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(N)]
MOD = 10 ** 9 + 7

A = np.array(a, dtype = 'O')
A = A.T

ans = np.eye(N, dtype = 'O')
while K:
  if K & 1:
    ans = np.dot(ans, A)
    ans %= MOD
  A = np.dot(A, A)
  A %= MOD
  K >>= 1

print(np.sum(abs(ans)) % MOD)
div = 1000000007

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

f = [0] * (n + 1)
f[0] = 1

if 1 not in a:
    f[1] = 1

for i in range(2, n + 1):
    if i in a:
        continue
    f[i] = (f[i - 1] + f[i - 2]) % div

print(f[-1])

### FIXED CODE ###

a_n = list(map(int, input().split()))

a_n = sorted(a_n)

print(a_n[0] + a_n[1])
def main():
    S = list(input())
    k = int(input())
    ans = []
    for s in S:
        if k == 0:
            break
        if s != 'a' and ord(s) >= 123 - k:
            ans.append('a')
            k -= 123 - ord(s)
        else:
            ans.append(s)
    if k > 0:
        ans[-1] = chr(ord(ans[-1]) + k)
    print(''.join(ans))



if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    S = list(input())
    k = int(input())
    ans = []
    for s in S:
        if s != 'a' and ord(s) >= 123 - k:
            ans.append('a')
            k -= 123 - ord(s)
        else:
            ans.append(s)
    if k > 0:
        ans[-1] = chr((ord(ans[-1]) + k - 97) % 26 + 97)
    print(''.join(ans))

if __name__ == '__main__':
    main()
S = input()
r = 0
L = []
for c in S:
  if c == "A" or c == "C" or c == "G" or c == "T":
    r += 1
  else:
    L.append(r)
    r = 0
print(max(L))


### FIXED CODE ###

S = input()
r = 0
L = []
for c in S:
  if c == "A" or c == "C" or c == "G" or c == "T":
    r += 1
  else:
    L.append(r)
    r = 0
L.append(r)
print(max(L))
def bomb(field,x,y):
    rfield = field[:][:]
    rfield[y][x] = 0
    for i in range(-3,4):
        if 0 <= x+i <= 7:
            if rfield[y][x+i] == 1:
                rfield = bomb(rfield,x+i,y)
        if 0 <= y+i <= 7:
            if rfield[y+i][x] == 1:
                rfield = bomb(rfield,x,y+i)
    return rfield


n = int(raw_input())
for data in range(1,n+1):
    # read condition
    dammy = raw_input
    field = []
    for line in range(8):
        field.append(map(int, list(raw_input())))
    x = int(raw_input())-1
    y = int(raw_input())-1

    # bombing!
    field = bomb(field,x,y)

    # print result
    print "Data %d:"%(data)
    for i in range(8):
        print "".join(map(str, field[i]))

### FIXED CODE ###

def bomb(f,x,y):
    rf = f[:][:]
    rf[y][x] = 0
    for i in [-3,-2,-1,1,2,3]:
        if 0 <= x+i <= 7:
            if rf[y][x+i] == 1: rf = bomb(rf,x+i,y)
        if 0 <= y+i <= 7:
            if rf[y+i][x] == 1: rf = bomb(rf,x,y+i)
    return rf


n = int(raw_input())
for data in range(1,n+1):
    f = []
    raw_input()
    for line in range(8):
        f.append(map(int, list(raw_input())))
    x = int(raw_input())-1
    y = int(raw_input())-1

    f = bomb(f,x,y)

    print "Data %d:"%(data)
    for i in range(8):
        print "".join(map(str, f[i]))
from collections import Counter

s = list(input())
t = list(input())

cs = Counter(s)
ct = Counter(t)

slist = list(cs.value())
tlist = list(cs.value())

slist.sort()
tlist.sort()

if slist == tlist:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

import collections

s = list(input())
t = list(input())

cs = collections.Counter(s)
ct = collections.Counter(t)

slist = list(cs.values())
tlist = list(ct.values())

slist.sort()
tlist.sort()

if slist == tlist:
    print("Yes")
else:
    print("No")
from fractions import gcd

d = int(input())
nums = list(map(int, input().split(' ')))

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

if d == 1:
  print(1)
else:
  lcm_num = nums[0]
  for i in range(len(nums)-1):
    lcm_num = lcm_base(lcm_num, nums[i+1])

  min_nums = []
  for n in nums:
    min_nums.append(int(lcm_num / n))
  ans = sum(min_nums)
  print(ans % (10**9 + 7))

### FIXED CODE ###

from fractions import gcd

def lcm_base(x, y):
  return x * y // gcd(x, y)

d = int(input())
nums = list(map(int, input().split(' ')))

lcm_num = 1
for n in nums:
  lcm_num = lcm_base(lcm_num, n)

ans = 0
mod = 10**9 + 7
for n in nums:
  ans += lcm_num//n
print(ans % mod)
s = input()
if s[0]!="A":
  print("WA")
  exit()
else:
  s.pop(0)
  if s[1]!="C" or s[-2]!="C":
    print("WA")
    exit()
  else:
    s.pop(1)
    s.pop(-2)
    if s.islower():
      print("AC")
    else:
      print("WA")

### FIXED CODE ###

s = list(input())
flg = "WA"
if s[0]=="A":
  if "C" in s[2:len(s)-1]:
    s.remove("A")
    s.remove("C")
    s = ''.join(s)
    if s.islower()==True:
      flg = "AC"
print(flg)
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    str_N = str(N)
    head_N, tail_N = int(str_N[0]), int(str_N[-1])
    digits = len(str_N)
    m = int(str_N[1:-1])
        
    def f(x):
        s = str(x)
        head, tail = int(s[0]), int(s[-1])
        res = 0
        if head == tail: res += 1 #1桁
        if digits >= 2: #2桁
            if digits == 2:
                if tail <= head_N: res += 1
            else: res += 1
        for d in range(3, digits+1): #3桁以上
            k = d - 2
            if d == digits: #Nと同じ桁数
                if tail < head_N:
                    res += 10**k
                elif tail == head_N:
                    res += m
            else: res += 10**k

        return res

    ans = 0
    for n in range(1,N+1):
        if n % 10 == 0: continue
        ans += f(n)
    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

N=int(input())

def cnt(i,j):
    ret=0
    si=str(i)
    for n in range(1,N+1):
        if n%10!=j:
            continue
        if str(n)[0]!=si:
            continue
        ret+=1
    return ret

ans=0
for i in range(10):
    for j in range(10):
        ans+=cnt(i,j)*cnt(j,i)
print(ans)
import numpy as np
import math

def main():
    N, X = map(int, input().split())
    x = np.asarray(list(map(int, input().split())))
    x = np.absolute(x - X)
    if N > 1:
        l = None
        for i, n in enumerate(x):
            if i == 0:
                l = n
            else:
                l = math.gcd(l, n)
        print(l)
    else:
        print(x[0])


if __name__ == '__main__':
    main()

### FIXED CODE ###


import numpy as np
import fractions

def main():
    N, X = map(int, input().split())
    x = np.asarray(list(map(int, input().split())))
    x = np.absolute(x - X)
    if N > 1:
        l = None
        for i, n in enumerate(x):
            if i == 0:
                l = n
            else:
                l = fractions.gcd(l, n)
        print(l)
    else:
        print(x[0])


if __name__ == '__main__':
    main()
r = input()
print(3*r**2)

### FIXED CODE ###

r = int(input())
print(3*r*r)
s = str(input())
s=s.lower(s)

if s.find('rr') != -1:
    print("2")
elif s.find('r') !=-1:
    print("1")
else :
    print ("0")


### FIXED CODE ###

s = str(input())
s=s.lower()

if s=="rrr":
    print('3')
elif s.find('rr') != -1:
    print("2")
elif s.find('r') != -1:
    print("1")
else:
    print ("0")
N, Q = map(int, input().split())
ki = [[[],0] for i in range(N)]
result = [0]*N

def dfs(i, num, ki, result, parent):
    num_tmp = num+ki[i][1]
    result[i] = num_tmp
    if not ki[i][0]:
        return
    for j in ki[i][0]:
        if j == parent:
            continue
        dfs(j, num_tmp, ki, result, i)
    return

for i in range(N-1):
    a, b = map(int, input().split())
    ki[a-1][0].append(b-1)
    ki[b-1][0].append(a-1)

for i in range(Q):
    p, x = map(int, input().split())
    ki[p-1][1] += x

dfs(0, 0, ki, result, -1)
print(*result)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
n,q=[int(_) for _ in input().split()]
ki=[[] for _ in range(n)]
ans=[0]*n
 
def dfs(numQ,parent):
    for child in ki[numQ]:
        if child==parent:
            continue
        ans[child]+=ans[numQ]
        dfs(child,numQ)
 
for i in range(n-1):
    a,b=[int(_) for _ in input().split()]
    ki[a-1].append(b-1)
    ki[b-1].append(a-1)
 
for i in range(q):
    p,x=[int(_) for _ in input().split()]
    ans[p-1]+=x
 
dfs(0,-1)
print(*ans)
S = input()

S_list=list(S)
for i in range(S_list):
  if S_list[i]=='h':
    if S_list[i+1] == 'i':
      if S_list[i+1] != 'i':
        print('Yes')
    
else:
  print('No')

### FIXED CODE ###

S = input()

List = ['hihi', 'hi', 'hihihi', 'hihihihi', 'hihihihihi']

if S in List:
  print('Yes')
  
else:
  print('No')
n=int(input());
num_list=[];
for i in range(n):
    num_list.append(int(input()));
    m=max(num_list)
for j in range(n):
    if(num_list[j]==m):
        print(m=max(num_list))
    print(m);


### FIXED CODE ###

a=int(input());
print(3*a**2);
# D
import numpy as np
N, K = map(int,input().split())
p = list(map(int,input().split()))

sums=np.cumsum([(s+1)/2 for s in p])

ans=np.max([ sums[i+K]-sums[i] for i in range(N-K)])

print(ans )

### FIXED CODE ###

# D
import numpy as np
N, K = map(int,input().split())
p = list(map(int,input().split()))

sums=np.cumsum([(s+1)/2 for s in p])

ans=np.max([ sums[i+K]-sums[i] for i in range(N-K)]+[sums[K-1]])

print(ans )
N = int(input())
a, w, t, r = 0, 0, 0, 0
for i in range(N):
    S = input()
    if S == 'AC':
        a += 1
    elif S == 'WA':
        w += 1
    elif S == 'TLE':
        t += 1
    else:
        r += 1
print('AC × ' + str(a))
print('WA × ' + str(w))
print('TLE × ' + str(t))
print('RE × ' + str(r))

### FIXED CODE ###

N = float(input())
if int(N) % 1000 == 0:
    print(0)
else:
    M = (int(N / 1000) + 1) * 1000
    print(int(M - N))
r = int(input())

print(3r^2)

### FIXED CODE ###

r = int(input())

print(3*r**2)
a = int(raw_input(""))
b = int(raw_input(""))
print a*b,2*a+2*b

### FIXED CODE ###

a,b = map(int,raw_input().split())
print a*b,a*2 + b*2
A = list(input())
A.sort()
cost =0
for i in range(len(A)-1):
  cost += abs(A[i]+A[i+1])
print(cost)

### FIXED CODE ###

A = list(map(int,input().split()))
A.sort()
ans = 0
for i in range(len(A)-1):
	ans += abs(A[i]-A[i+1])
print(ans)
N = int(input())
S = [int(i) for i in input().split()]

if "Y" in S:
    print("Four")
else:
    print("Three")

### FIXED CODE ###

N = int(input())
S = [i for i in input().split()]

if "Y" in S:
    print("Four")
else:
    print("Three")
n,m,k = map(int,input().split())

a = list(map(int,input().split()))
b = list(map(int,input().split()))

# まずaを全部読む
# 全部読めたならbも読む
# 最後の本を捨てて、それがなければどこまでいけるかを試す

ans = 0
cost = 0
b_i = 0
while cost <= k:
  ans += 1
  if ans >= n:
    cost += b[n-ans]
    b_i += 1
  else:
    cost += a[ans]

max_ans = ans
if b_i == 0:
  for i in range(ans-1,-1,-1):
    ans -= 1
    cost -= a[i]
    while cost <= k and b_i < m:
      ans += 1
      cost += b[b_i]
      b_i += 1
    max_ans = max(max_ans, ans)
else:
  for i in range(n-1,-1,-1):
    ans -= 1
    cost -= a[i]
    while cost <= k and b_i < m:
      ans += 1
      cost += b[b_i]
      b_i += 1
    max_ans = max(max_ans, ans)
    
if not a[0] >= k and b[0] >= k:
  print(max_ans)
else:
  print(0)

### FIXED CODE ###

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

a, b=[0], [0]
for i in range(N):
  a.append(a[i]+A[i])
for i in range(M):
    b.append(b[i]+B[i])
    
ans, j=0, M
for i in range(N+1):
  if a[i]>K:
    break
  while b[j]>K-a[i]:
    j-=1
  ans=max(ans, i+j)
  
print(ans)
n = int(input())
record = [ [ [ [0 for r in range(10)] for f in range(3)] ] for b in range(4)]
for i in range(n):
    b,f,r,v = [int(a) in input().split(" ")]
    record[b - 1][f - 1][r - 1] += v
for b in range(4):
    for f in record[b]:
        print( " "+" ".join( [str(x) for x in f] ) )
    if b != 3:
        print("#" * 20)
        

### FIXED CODE ###

n = int(input())
record = [ [ [0 for r in range(10)] for f in range(3)] for b in range(4)]
for _ in range(n):
    b,f,r,v = [int(i) for i in input().split(" ")]
    record[b - 1][f - 1][r - 1] += v
for b1 in range(4):
    for f in record[b1]:
        print(" "+" ".join([str(x) for x in f]))
    if b1 != 3:
        print("#" * 20)
from collections import Counter


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

v_odd = []
v_even = []
for index in range(len(v)):
    i = index + 1
    if i % 2 == 0:
        v_even.append(v[index])
    else:
        v_odd.append(v[index])
# print(v_odd)
# print(v_even)
# print(Counter(v_odd).most_common())
# print(Counter(v_even).most_common())

if Counter(v_odd).most_common()[0][1] != Counter(v_even).most_common()[0][1]:
    number_of_rewrites = len(v_odd) - Counter(v_odd).most_common()[0][1]
    number_of_rewrites += len(v_even) - Counter(v_even).most_common()[0][1]
else:
    if Counter(v_odd).most_common()[0][1] >= Counter(v_even).most_common()[0][1]:
        number_of_rewrites = len(v_odd) - Counter(v_odd).most_common()[0][1]
        number_of_rewrites += len(v_even) - Counter(v_even).most_common()[1][1]
    else:
        number_of_rewrites = len(v_odd) - Counter(v_odd).most_common()[1][1]
        number_of_rewrites += len(v_even) - Counter(v_even).most_common()[0][1]


print(number_of_rewrites)


### FIXED CODE ###

from collections import Counter


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

v_odd = []
v_even = []
for index in range(len(v)):
    i = index + 1
    if i % 2 == 0:
        v_even.append(v[index])
    else:
        v_odd.append(v[index])
# print(v_odd)
# print(v_even)
# print(Counter(v_odd).most_common())
# print(Counter(v_even).most_common())

if Counter(v_odd).most_common()[0][0] != Counter(v_even).most_common()[0][0]:
    number_of_rewrites = len(v_odd) - Counter(v_odd).most_common()[0][1]
    number_of_rewrites += len(v_even) - Counter(v_even).most_common()[0][1]
else:
    odd_1st = Counter(v_odd).most_common()[0][1]
    even_1st = Counter(v_even).most_common()[0][1]
    odd_2nd = Counter(v_odd).most_common()[1][1] if len(Counter(v_odd).most_common()) >= 2 else 0
    even_2nd = Counter(v_even).most_common()[1][1] if len(Counter(v_even).most_common()) >= 2 else 0

    number_of_rewrites = min(
        len(v_odd) - odd_1st + len(v_even) - even_2nd,
        len(v_odd) - odd_2nd + len(v_even) - even_1st,
    )

print(number_of_rewrites)
N = int(input())
print(N*(N+1))//2)

### FIXED CODE ###

N = int(input())
print((N*(N+1))//2)
while True:
    a, b, c = map(str, input().split())
    a = int(a)
    c = int(c)
    if(c == '+'):
        print(a + b)
    elif(c == '-'):
        print(a - b)
    elif(c == '*'):
        print(a * b)
    elif(c == '/')
        print(a / b)
    else:
        break


### FIXED CODE ###

while True:
    a, b, c = map(str, input().split())
    a = int(a)
    c = int(c)
    if(b == '+'):
        print(a + c)
    elif(b == '-'):
        print(a - c)
    elif(b == '*'):
        print(a * c)
    elif(b == '/'):
        print(a // c)
    else:
        break
n=int(input())
sp=[]
for i in range(n):
    s,p=map(str(input().split()))
    sp.append([s,int(p),i+1])
sp.sort(key=lambda x: x[1],reverse=True)
sp.sort(key=lambda x: x[0])

for e in sp:
    print(e[2])


### FIXED CODE ###

n=int(input())
sp=[]
for i in range(n):
    s,p=map(str,input().split())
    sp.append([s,int(p),i+1])
sp.sort(key=lambda x: x[1],reverse=True)
sp.sort(key=lambda x: x[0])

for e in sp:
    print(e[2])
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

H, W, A, B = list(map(int, sys.stdin.readline().split()))
if H % A == 0 and W % B == 0:
    print('No')
    exit()

print('Yes')
MAX = 998244353
ans = np.full((H, W), MAX // (A * B - 1), dtype=int)
if A > 1 and B > 1:
    ans[np.arange(A - 1, H, A), np.arange(B - 1, W, B)] = -MAX
elif A == 1:
    ans[:, np.arange(B - 1, W, B)] = -MAX
else:
    ans[np.arange(A - 1, H, A), :] = -MAX
print('\n'.join(map(lambda r: ' '.join(r), ans.astype(str))))


### FIXED CODE ###

import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

H, W, A, B = list(map(int, sys.stdin.readline().split()))
if H % A == 0 and W % B == 0:
    print('No')
    exit()

print('Yes')
MAX = 998244353
ans = np.full((H, W), MAX // (A * B - 1), dtype=int)
if A > 1 and B > 1:
    ans[np.meshgrid(np.arange(A - 1, H, A), np.arange(B - 1, W, B))] = -MAX-1
elif A == 1:
    ans[:, np.arange(B - 1, W, B)] = -MAX-1
else:
    ans[np.arange(A - 1, H, A), :] = -MAX-1
print('\n'.join(map(lambda r: ' '.join(r), ans.astype(str))))
n = int(input())

for i in range(1,n)
  if i%15==0:
    print('FizzBuzz')
  elif i%5==0:
    print('Buzz')
  elif i%3==0:
    print('Fizz')
  else:
    print(i)


### FIXED CODE ###

n = list(map(int, input()))
flg = 0
if n[0]==7:
  flg = 1
if n[1]==7:
  flg = 1
if n[2]==7:
  flg = 1

if flg == 1:
  print('Yes')
else:
  print('No')
n,m=map(int, input().split())
A=set(range(1, m+1))
for _ in range(n):
  a,*b=map(int, input().split())
  A = A & set(*b)
print(len(A))

### FIXED CODE ###

n,m=map(int, input().split())
A=set(range(1, m+1))
for _ in range(n):
  a,*b=map(int, input().split())
  A = A & set(b)
print(len(A))
N,m = list(map(int,input().split()))
data = {}
for i in range(N):
	a,b = list(map(int,input().split()))
	data[a] = b
sortedData = sorted(data.items())
cost = 0
for i in range(N):
	prices = sortedData[i][0]
	nums = sortedData[i][1]
	if m > nums:
		cost += price * nums
		m -= nums
	else:
		cost += prices * m
		print(cost)
		break

### FIXED CODE ###

N,m = list(map(int,input().split()))
data = [[0,0] for i in range(N)]
for i in range(N):
	data[i] = list(map(int,input().split()))
data.sort()
cost = 0
for i in range(N):
	prices,nums = data[i]
	if m > nums:
		cost += prices * nums
		m -= nums
	else:
		cost += prices * m
		print(cost)
		break
def main():
  t, x = map(int, input())
  print(float(t) / float(x))


main()

### FIXED CODE ###

def main():
  t, x = map(int, input().split())
  print(float(t) / float(x))


main()
import math
x,y,z = map(int, input().split())

a=math.sqrt(x)
b=math.sqrt(y)
c=math/sqrt(z)

aa=a**2
bb=b**2
cc=c**2
ab=2*a*b

if cc-aa-bb-ab>0:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

import math
a,b,c = map(int, input().split())
x=a**2+b**2+c**2+2*a*b-2*b*c-2*a*c
y=4*a*b

if c-b-a>0 and x-y>0 :
    print("Yes")
else:
    print("No")
N,M=map(int,input().split())

pair=[list(map(lambda x:int(x)-1,input().split())) for _ in range(M)]
graph=[[0]*N for _ in range(N)] #隣接行列の初期化


for p in pair:
	graph[p[0]][p[1]]= graph[p[1]][p[0]]=1
	
def DFS(v):
	if visited[v]:
		return 
	visited[v]=True
	for i in [i for i,v2 in enumerate(graph[v]) if v2==1]:
		DFS(i)
		
res = 0

for i in range(M):
	visited=[False for _ in range(N)] #訪問済みリストの初期化
	x,y=pair[i]
	graph[x][y]=graph[y][x]=0 #辺を取り除く
	DFS(0 if i>0 else 1)
	
	if not all(visited): #全ての頂点が訪問済みでなかった場合
		res+=1
	
	graph[x][y]=graph[y][x]=1

print(res)

### FIXED CODE ###

A,B,C=list(input().split())

if A==B:
	print(C)
elif B==C:
	print(A)
else:
	print(B)
import numpy as np
n, M, X = list(map(int, input().split()))
CA = []
A = []
for _ in range(N):
    L = list(map(int, input().split()))
    CA.append(L[:])
ans = np.zeros(M+1)
S = [0]*n
ANS = list()
def makeCombination():
    for i in range(0, n-1):
        S[i] = 0
    rec(0, ans)
def rec(i,ans):
    if i == n:
        #print(S)
        print(ans)
        print(ans[1:] >= X)
        if all(ans[1:] >= X) == True:
            ANS.append(ans[0])
        return
    rec(i + 1,ans)
    S[i] = 1
    ans = ans   + np.array(CA[i])
    rec(i + 1, ans)
    S[i] = 0
makeCombination()
ANS.sort()
if len(ANS) >= 1:
    print(ANS[0])
else:
    print(-1)

### FIXED CODE ###

import numpy as np
n, M, X = list(map(int, input().split()))
CA = []
A = []
for _ in range(n):
    L = list(map(int, input().split()))
    CA.append(L[:])
    
ans = np.zeros(M+1)
S = [0]*n
ANS = list()
def makeCombination():
    for i in range(0, n-1):
        S[i] = 0
    rec(0, ans)
def rec(i,ans):
    if i == n:
        if all(ans[1:] >= X) == True:
            ANS.append(ans[0])
        return
    rec(i + 1,ans)
    S[i] = 1
    ans = ans   + np.array(CA[i])
    rec(i + 1, ans)
    S[i] = 0
makeCombination()
ANS.sort()
if len(ANS) >= 1:
    print(int(ANS[0]))
else:
    print(-1)