local r_eat, g_eat, r_num, g_num, a_num
= io.read("*n", "*n", "*n", "*n", "*n")

local function writeList(num)
    local list = {}
    for i = 1, num do
        list[i] = io.read("*n")
    end
    return list
end

local r_taste = writeList(r_num)
local g_taste = writeList(g_num)
local a_taste = writeList(a_num)

table.sort(r_taste, function(x, y) return x > y end)
table.sort(g_taste, function(x, y) return x > y end)
table.sort(a_taste, function(x, y) return x > y end)
for i = 1, r_num - r_eat do
    r_taste[#r_taste] = nil
end
for i = 1, g_num - g_eat do
    g_taste[#g_taste] = nil
end

local function removeMin(list1, list2, list3)
    if     list3 and (list1[#list1] <= list2[#list2]) then
        table.remove((list1[#list1] <  list3[#list3]) and list1 or list3)
    elseif list3 and (list2[#list2] <  list1[#list1]) then
        table.remove((list2[#list2] <  list3[#list3]) and list2 or list3)
    else
        table.remove((list1[#list1] <  list2[#list2]) and list1 or list2)
    end
end

for i = 1, #a_taste do
    if r_taste[#r_taste] and g_taste[#g_taste] and a_taste[#a_taste] then
        removeMin(r_taste, g_taste, a_taste)
    elseif r_taste[#r_taste] and g_taste[#g_taste] then
        removeMin(r_taste, g_taste)
    elseif g_taste[#g_taste] and a_taste[#a_taste] then
        removeMin(g_taste, a_taste)
    elseif a_taste[#a_taste] and r_taste[#r_taste] then
        removeMin(a_taste, r_taste)
    elseif r_taste[#r_taste] then
        table.remove(r_taste)
    elseif g_taste[#g_taste] then
        table.remove(g_taste)
    elseif a_taste[#a_taste] then
        table.remove(a_taste)
    end
end

local function samList(list)
    local result_sam = 0LL
    for i = 1, #list do
        result_sam = result_sam + list[i]
    end
    return result_sam
end
local result = 0LL
result = samList(r_taste) + samList(g_taste) + samList(a_taste)

print(tostring(result):sub(1, -3))


local r_eat, g_eat, r_num, g_num, a_num
= io.read("*n", "*n", "*n", "*n", "*n")

local function writeList(num)
    local list = {}
    for i = 1, num do
        list[i] = io.read("*n")
    end
    return list
end

local r_taste = writeList(r_num)
local g_taste = writeList(g_num)
local a_taste = writeList(a_num)

table.sort(r_taste, function(x, y) return x > y end)
table.sort(g_taste, function(x, y) return x > y end)
table.sort(a_taste, function(x, y) return x > y end)
for i = 1, r_num - r_eat do
    r_taste[#r_taste] = nil
end
for i = 1, g_num - g_eat do
    g_taste[#g_taste] = nil
end

local function removeMin(list1, list2, list3)
    if     list3 and (list1[#list1] <= list2[#list2]) then
        table.remove((list1[#list1] <  list3[#list3]) and list1 or list3)
    elseif list3 and (list2[#list2] <  list1[#list1]) then
        table.remove((list2[#list2] <  list3[#list3]) and list2 or list3)
    else
        table.remove((list1[#list1] <  list2[#list2]) and list1 or list2)
    end
end

for i = 1, #a_taste do
    if r_taste[#r_taste] and g_taste[#g_taste] and a_taste[#a_taste] then
        removeMin(r_taste, g_taste, a_taste)
    elseif r_taste[#r_taste] and g_taste[#g_taste] then
        removeMin(r_taste, g_taste)
    elseif g_taste[#g_taste] and a_taste[#a_taste] then
        removeMin(g_taste, a_taste)
    elseif a_taste[#a_taste] and r_taste[#r_taste] then
        removeMin(a_taste, r_taste)
    elseif r_taste[#r_taste] then
        table.remove(r_taste)
    elseif g_taste[#g_taste] then
        table.remove(g_taste)
    elseif a_taste[#a_taste] then
        table.remove(a_taste)
    end
end

local function samList(list)
    local result_sam = 0
    for i = 1, #list do
        result_sam = result_sam + list[i]
    end
    return result_sam
end
local result = samList(r_taste) + samList(g_taste) + samList(a_taste)

print(result)

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Score : 500 points

Problem Statement

You are going to eat X red apples and Y green apples.

You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.

Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively.

From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible.

Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.

Constraints

1 \leq X \leq A \leq 10^5

1 \leq Y \leq B \leq 10^5

1 \leq C \leq 10^5

1 \leq p_i \leq 10^9

1 \leq q_i \leq 10^9

1 \leq r_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C

Output

Print the maximum possible sum of the deliciousness of the eaten apples.

Sample Input 1

1 2 2 2 1
2 4
5 1
3

Sample Output 1

12

The maximum possible sum of the deliciousness of the eaten apples can be achieved as follows:

Eat the 2-nd red apple.

Eat the 1-st green apple.

Paint the 1-st colorless apple green and eat it.

Sample Input 2

2 2 2 2 2
8 6
9 1
2 1

Sample Output 2

25

Sample Input 3

2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4

Sample Output 3

74

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


local r_eat, g_eat, r_num, g_num, a_num
= io.read("*n", "*n", "*n", "*n", "*n")

function writeList(num)
    local list = {}
    for i = 1, num do
        list[i] = io.read("*n")
    end
    return list
end

local r_taste = writeList(r_num)
local g_taste = writeList(g_num)
local a_taste = writeList(a_num)

table.sort(r_taste, function(x, y) return x > y end)
table.sort(g_taste, function(x, y) return x > y end)
for i = 1, r_num - r_eat do
    r_taste[#r_taste] = nil
end
for i = 1, g_num - g_eat do
    g_taste[#g_taste] = nil
end

local all_taste = a_taste
for i = 1, #r_taste do
    all_taste[#all_taste + 1] = r_taste[i]
end
for i = 1, #g_taste do
    all_taste[#all_taste + 1] = g_taste[i]
end
table.sort(all_taste, function(x, y) return x > y end)

local result = 0
for i = 1, r_eat + g_eat do
    result = result + all_taste[i]
end
print(result)


local r_eat, g_eat, r_num, g_num, a_num
= io.read("*n", "*n", "*n", "*n", "*n")

function writeList(num)
    local list = {}
    for i = 1, num do
        list[i] = io.read("*n")
    end
    return list
end

local r_taste = writeList(r_num)
local g_taste = writeList(g_num)
local a_taste = writeList(a_num)

table.sort(r_taste); table.sort(g_taste)
for i = 1, r_num - r_eat do
    table.remove(r_taste, 1)
end
for i = 1, g_num - g_eat do
    table.remove(g_taste, 1)
end

local all_taste = a_taste
for i = 1, #r_taste do
    table.insert(all_taste, r_taste[i])
end
for i = 1, #g_taste do
    table.insert(all_taste, g_taste[i])
end
table.sort(all_taste)

local result = 0
for i = #all_taste, #all_taste - r_eat -g_eat + 1, -1 do
    result = result + all_taste[i]
end
print(result)


--[[
食べる数の領域確保
rとgの最小の数を比較
小さい方をaの最大と比較
]]
local r_eat, g_eat, r_num, g_num, a_num
= io.read("*n", "*n", "*n", "*n", "*n")

function writeList(num)
    local list = {}
    for i = 1, num do
        list[i] = io.read("*n")
    end
    return list
end

local r_taste = writeList(r_num)
local g_taste = writeList(g_num)
local a_taste = writeList(a_num)

table.sort(r_taste); table.sort(g_taste); table.sort(a_taste)
for i = 1, r_num - r_eat do
    table.remove(r_taste, 1)
end
for i = 1, g_num - g_eat do
    table.remove(g_taste, 1)
end

while true do
    local a_taste_len = a_taste[#a_taste]
    if a_taste_len and (r_taste[1] <= g_taste[1]) and (r_taste[1] < a_taste[a_taste_len]) then
        table.remove(r_taste, 1)
        table.insert(r_taste, table.remove(a_taste))
    elseif a_taste_len and (g_taste[1] < r_taste[1]) and (g_taste[1] < a_taste[a_taste_len]) then
        table.remove(g_taste, 1)
        table.insert(g_taste, table.remove(a_taste))
    else
        break
    end
end

local result = 0
for i = 1, r_eat do
    result = result + r_taste[i]
end
for i = 1, g_eat do
    result = result + g_taste[i]
end

print(result)


--[[
食べる数の領域確保
rとgの最小の数を比較
小さい方をaの最大と比較
]]
local r_eat, g_eat, r_num, g_num, a_num
= io.read("*n", "*n", "*n", "*n", "*n")

function writeList(num)
    local list = {}
    for i = 1, num do
        list[i] = io.read("*n")
    end
    return list
end

local r_taste = writeList(r_num)
local g_taste = writeList(g_num)
local a_taste = writeList(a_num)

table.sort(r_taste); table.sort(g_taste); table.sort(a_taste)
for i = 1, r_num - r_eat do
    table.remove(r_taste, 1)
end
for i = 1, g_num - g_eat do
    table.remove(g_taste, 1)
end

while true do
    local a_taste_len = a_taste[#a_taste]
    if a_taste_len and (r_taste[1] <= g_taste[1]) and (r_taste[1] < a_taste_len) then
        table.remove(r_taste, 1)
        table.insert(r_taste, table.remove(a_taste))
    elseif a_taste_len and (g_taste[1] < r_taste[1]) and (g_taste[1] < a_taste_len) then
        table.remove(g_taste, 1)
        table.insert(g_taste, table.remove(a_taste))
    else
        break
    end
end

local result = 0
for i = 1, r_eat do
    result = result + r_taste[i]
end
for i = 1, g_eat do
    result = result + g_taste[i]
end

print(result)


local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
--read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimension, default_val) assert(type(default_val) ~= 'table') local n=dimension local m={}if default_val~=nil then m[1]={__index=function()return default_val end}end for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
----
local function readN(N)
    local t={}
    local s = read.l()
    local ins = table.insert
    for w in string.gmatch(s, "[^%s]+") do
        ins(t, tonumber(w))
    end
    return t
end
local X,Y,A,B,C,_ = read.nnnnnl()
local P = readN(A)
local Q = readN(B)
local R = readN(C)
table.sort(P, function(a,b) return a>b end)
table.sort(Q, function(a,b) return a>b end)
table.sort(R, function(a,b) return a>b end)
local t = {}
local sum = 0
local froma = math.min(X, A)
for i=1,froma do
    sum = sum + P[i]
    table.insert(t, {P[i], 'R'})
end
local ptrr = froma
local fromb = math.min(Y, B)
for i=1,fromb do
    sum = sum + Q[i]
    table.insert(t, {Q[i], 'G'})
end
local ptrg = fromb
local lacka = math.max(X-A, 0)
local lackb = math.max(Y-B, 0)
for i=1,lacka+lackb do
    sum = sum + R[i]
    table.insert(t, {R[i], 'W'})
end
assert(#t == X+Y)
local ptrw = lacka + lackb + 1
for i=#t,1,-1 do
    if ptrw > C then
        break
    end
    local val, color = t[i][1], t[i][2]
    --print(i, ptrw, R[ptrw], val, color)
    if color == 'W' then
        -- skip
    elseif color == 'R' then
        if val < R[ptrw] then
            sum = sum - val
            sum = sum + R[ptrw]
            ptrw = ptrw + 1
        end
    elseif color == 'G' then
        if val < R[ptrw] then
            sum = sum - val
            sum = sum + R[ptrw]
            ptrw = ptrw + 1
        end
    end
end
print(sum)


local x, y = io.read("*n", "*n")
local a, b, c = io.read("*n", "*n", "*n")
local p, q, r = {}, {}, {}
for i = 1, a do
  p[i] = io.read("*n")
end
for i = 1, b do
  q[i] = io.read("*n")
end
for i = 1, c do
  r[i] = io.read("*n")
end
table.sort(p, function(x, y) return x > y end)
table.sort(q, function(x, y) return x > y end)
table.sort(r, function(x, y) return x > y end)
local redsum = 0LL
for i = 1, x do
  redsum = redsum + p[i]
end
local greensum = 0LL
for i = 1, y do
  greensum = greensum + q[i]
end
local redpos, greenpos = x, y
local totsum = redsum + greensum
for i = 1, c do
  local changed = false
  local cv = r[i]
  if 0 < redpos and 0 < greenpos then
    if p[redpos] < q[greenpos] then
      if p[redpos] < cv then
        totsum = totsum - p[redpos] + cv
        redpos = redpos - 1
        changed = true
      end
    else
      if q[greenpos] < cv then
        totsum = totsum - q[greenpos] + cv
        greenpos = greenpos - 1
        changed = true
      end
    end
  elseif 0 < redpos then
    if p[redpos] < cv then
      totsum = totsum - p[redpos] + cv
      redpos = redpos - 1
      changed = true
    end
  elseif 0 < greenpos then
    if q[greenpos] < cv then
      totsum = totsum - q[greenpos] + cv
      greenpos = greenpos - 1
      changed = true
    end
  end
  if not changed then break end
end
local str = tostring(totsum):gsub("LL", "")
print(str)


local x, y = io.read("*n", "*n")
local a, b, c = io.read("*n", "*n", "*n")
local p, q, r = {}, {}, {}
for i = 1, a do
  p[i] = io.read("*n")
end
for i = 1, b do
  q[i] = io.read("*n")
end
for i = 1, c do
  r[i] = io.read("*n")
end
table.sort(p, function(x, y) return x > y end)
table.sort(q, function(x, y) return x > y end)
table.sort(r, function(x, y) return x > y end)
local redsum = 0LL
for i = 1, x do
  redsum = redsum + p[i]
end
local greensum = 0LL
for i = 1, y do
  greensum = greensum + q[i]
end
local redpos, greenpos = x, y
local totsum = redsum + greensum
for i = 1, c do
  local changed = false
  local cv = r[i]
  if 0 < redpos and 0 < greenpos then
    if p[redpos] < q[greenpos] then
      if p[redpos] < cv then
        totsum = totsum - p[redpos] + cv
        redpos = redpos - 1
      end
    else
      if q[greenpos] < cv then
        totsum = totsum - q[greenpos] + cv
        greenpos = greenpos - 1
      end
    end
  elseif 0 < redpos then
    if p[redpos] < cv then
      totsum = totsum - p[redpos] + cv
      redpos = redpos - 1
    end
  elseif 0 < greenpos then
    if q[greenpos] < cv then
      totsum = totsum - q[greenpos] + cv
      greenpos = greenpos - 1
    end
  end
  if not changed then break end
end
local str = tostring(totsum):gsub("LL", "")
print(str)


a,b,c=io.read("n","n","n") d=c-b-a print(d>0 and d*d>4*a*b and "Yes" or "No")

Score : 300 points

Problem Statement

Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?

Constraints

1 \leq a, b, c \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

a \ b \ c

Output

If \sqrt{a} + \sqrt{b} < \sqrt{c}, print Yes; otherwise, print No.

Sample Input 1

2 3 9

Sample Output 1

No

\sqrt{2} + \sqrt{3} < \sqrt{9} does not hold.

Sample Input 2

2 3 10

Sample Output 2

Yes

\sqrt{2} + \sqrt{3} < \sqrt{10} holds.


a,b,c=io.read("*n","*n","*n")
d=c-b-a
print(d>0 and d*d>4*a*b and "Yes" or "No")


m=math.sqrt
a,b,c=io.read("*n","*n","*n")
print(m(a)+m(b)<m(c) and "Yes" or "No")


local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimension, default_val) assert(type(default_val) ~= 'table') local n=dimension local m={}if default_val~=nil then m[1]={__index=function()return default_val end}end for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
----
local a,b,c = read.nnn()
--if c - a - b <= 0 then
--    print("No")
--else
    local r = (c-a-b)*(c-a-b)
    local l = 4 * a * b
    if l < r then
        print('Yes')
    else
        print('No')
    end
--end


local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimension, default_val) assert(type(default_val) ~= 'table') local n=dimension local m={}if default_val~=nil then m[1]={__index=function()return default_val end}end for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
----
local a,b,c = read.nnn()
if c - a - b <= 0 then
    print("No")
else
    local r = (c-a-b)*(c-a-b)
    local l = 4 * a * b
    if l < r then
        print('Yes')
    else
        print('No')
    end
end


local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimension, default_val) assert(type(default_val) ~= 'table') local n=dimension local m={}if default_val~=nil then m[1]={__index=function()return default_val end}end for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
----
local a,b,c = read.nnn()
s = math.sqrt
if s(a)+s(b)<s(c) then print("Yes")
else print("No") end


local a, b, c = io.read("*n", "*n", "*n")
local d = c - a - b
if d < 0 then
  print("No")
else
  local f = d * d > 4 * a * b
  print(f and "Yes" or "No")
end


local a, b, c = io.read("*n", "*n", "*n")
local d = c - a - b
local f = d * d > 4 * a * b
print(f and "Yes" or "No")


local read = io.read

local n, m = read("n", "n")
local key_s_t = {}
if n == 1 and m == 0 then
	print(0)
	os.exit()
end
for i = 1, m do
	local s_i, c_i = read("n", "n")
	if n ~= 1 and s_i == 1 and c_i == 0 then
		print(-1)
		os.exit()
	end
	if key_s_t[s_i] and key_s_t[s_i] ~= c_i then
		print(-1)
		os.exit()
	elseif not key_s_t[s_i] then
		key_s_t[s_i] = c_i
	end
end
for i = 1, n do
	if not key_s_t[i] then
		if i == 1 then
			key_s_t[i] = 1
		else
			key_s_t[i] = 0
		end
	end
end

print(table.concat(key_s_t, ""))

Score : 300 points

Problem Statement

If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print -1.

The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.)

The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right)

Constraints

All values in input are integers.

1 \leq N \leq 3

0 \leq M \leq 5

1 \leq s_i \leq N

0 \leq c_i \leq 9

Input

Input is given from Standard Input in the following format:

N M
s_1 c_1
\vdots
s_M c_M

Output

Print the answer.

Sample Input 1

3 3
1 7
3 2
1 7

Sample Output 1

702

702 satisfies the conditions - its 1-st and 3-rd digits are 7 and 2, respectively - while no non-negative integer less than 702 satisfies them.

Sample Input 2

3 2
2 1
2 3

Sample Output 2

-1

Sample Input 3

3 1
1 0

Sample Output 3

-1


local read = io.read

local n, m = read("n", "n")
local key_s_t = {}
for i = 1, m do
	local s_i, c_i = read("n", "n")
	if n ~= 1 and s_i == 1 and c_i == 0 then
		print(-1)
		os.exit()
	end
	if key_s_t[s_i] and key_s_t[s_i] ~= c_i then
		print(-1)
		os.exit()
	elseif not key_s_t[s_i] then
		key_s_t[s_i] = c_i
	end
end
for i = 1, n do
	if not key_s_t[i] then
		if i == 1 then
			key_s_t[i] = 1
		else
			key_s_t[i] = 0
		end
	end
end

print(table.concat(key_s_t, ""))


local read = io.read

local n, m = read("n", "n")
local key_s_t = {}
for i = 1, m do
	local s_i, c_i = read("n", "n")
	if s_i == 1 and c_i == 0 then
		print(-1)
		os.exit()
	end
	if key_s_t[s_i] and key_s_t[s_i] ~= c_i then
		print(-1)
		os.exit()
	elseif not key_s_t[s_i] then
		key_s_t[s_i] = c_i
	end
end
for i = 1, n do
	if not key_s_t[i] then
		if i == 1 then
			key_s_t[i] = 1
		else
			key_s_t[i] = 0
		end
	end
end

print(table.concat(key_s_t, ""))


local n, m = io.read("*n", "*n")
local t = {}
for i = 1, n do
  t[i] = -1
end
local valid = true
for i = 1, m do
  local s, c = io.read("*n", "*n")
  if s == 1 and c == 0 and 1 < n then
    valid = false
  end
  if 0 <= t[s] and t[s] ~= c then
    valid = false
  end
  t[s] = c
end
if not valid then
  print(-1)
else
  for i = 1, n do
    if t[i] == -1 then
      if i == 1 and n ~= 1 then io.write(1)
      else io.write(0)
      end
    else
      io.write(t[i])
    end
  end
  io.write("\n")
end


local n, m = io.read("*n", "*n")
local t = {}
for i = 1, n do
  t[i] = -1
end
local valid = true
for i = 1, m do
  local s, c = io.read("*n", "*n")
  if s == 1 and c == 0 and 1 < n then
    valid = false
  end
  if 0 <= t[s] and t[s] ~= c then
    valid = false
  end
  t[s] = c
end
if not valid then
  print(-1)
else
  for i = 1, n do
    if t[i] == -1 then
      if i == 1 or n == 1 then io.write(1)
      else io.write(0)
      end
    else
      io.write(t[i])
    end
  end
  io.write("\n")
end


n,m=io.read("*n","*n","*l")

t={}
if m>=1 then
    for i=1,m do
        s,c=io.read("*n","*n","*l")
        c=tostring(c)
        if not t[s] or t[s]==c then
            t[s]=c
        else
            print(-1)
            return
        end
    end
    for i=1,n do
        if not t[i] and i==1 then
            t[i]="1"
        elseif not t[i] then
            t[i]="0"
        end
    end
    x="0"
    for i=1,n do
        x=x..t[i]
    end
    if #x:sub(2,n+1)~=#tostring(tonumber(x)) then
        print(-1)
        return
    elseif #x:sub(2,n+1)==#tostring(tonumber(x)) then
        print(tonumber(x))
        return
    end
else
    if n==1 then
        print(0)
        return
    else
        x="100"
        print(x:sub(1,n))
        return
    end
end


N=io.read"*n"
M=io.read"*n"
sc={}
for i=1,M do
  sc[i]={io.read"*n",io.read"*n"}
end

function f(i,j,k)
    for _,v in ipairs(sc)do
        if(v[1]==1)then
            if(v[2]~=i)then return false end
        elseif(v[1]==2)then
            if(v[2]~=j)then return false end
        else
            if(v[2]~=k)then return false end
        end
    end
    return true
end
n=-1
function g()
for i=0,9 do for j=0,9 do for k=0,9 do
    if(f(i,j,k))then if(select(N,k,j,i)~=0)then n=i*100+j*10+k return end end
end end end
end
g()
print(n)


N=io.read"*n"
M=io.read"*n"
sc={}
for i=1,M do
  sc[i]={io.read("*n","*n")}
end
table.sort(sc,function(a,b)return a[1]<b[1]end)
function f(sc)
  r={}
  for _,v in ipairs(sc) do
    if(v[1]==1)then
	  if(v[2]==0)then return -1 end
    end
    if(r[v[1]] and r[v[1]]~=v[2])then return -1 end
    r[v[1]]=v[2]
  end
  if(r[1]==nil)then r[1]=1 end
  for i=2,N do
    if(r[i]==nil)then r[i]=0 end
  end
  return table.concat(r)
end
print(f(sc))


local n, m = io.read("*n", "*n")
local min, max = 0, 9
if n == 2 then
  min, max = 10, 99
elseif n == 3 then
  min, max = 100, 999
end
local s, c = {}, {}
for i = 1, m do
  local x, y = io.read("*n", "*n")
  s[i], c[i] = x, tostring(y)
end
local f = false
for ic = min, max do
  local str = tostring(ic)
  f = true
  for i = 1, m do
    if n < s[i] or str:sub(s[i], s[i]) ~= c[i] then
      f = false
      break
    end
  end
  if f then print(ic) break end
end
if not f then print(-1) end


local n, m = io.read("*n", "*n")
local min, max = 1, 9
if n == 2 then
  min, max = 10, 99
elseif n == 3 then
  min, max = 100, 999
end
local s, c = {}, {}
for i = 1, m do
  local x, y = io.read("*n", "*n")
  s[i], c[i] = x, tostring(y)
end
local f = false
for ic = min, max do
  local str = tostring(ic)
  f = true
  for i = 1, m do
    if n < s[i] or str:sub(s[i], s[i]) ~= c[i] then
      f = false
      break
    end
  end
  if f then print(ic) break end
end
if not f then print(-1) end


local mfl = math.floor

local n, k = io.read("*n", "*n", "*l")
local t = {}
local str = io.read()
for s in str:gmatch("(-?%d+)") do
  table.insert(t, tonumber(s))
end
table.sort(t)
local plus_start_pos = n + 1
local minus, plus = {}, {}
for i = n, 1, -1 do
  if t[i] < 0 then
    table.insert(minus, -t[i])
  else
    table.insert(plus, t[i])
    plus_start_pos = i
  end
end
do
  local hn = math.floor(#plus / 2)
  for i = 1, hn do
    plus[i], plus[#plus + 1 - i] = plus[#plus + 1 - i], plus[i]
  end
end
local ten9 = 1000000000LL
local minus_cnt = #minus * #plus
if k <= minus_cnt then
  local mmi = math.min
  local function solve(x)
    x = -x
    local cnt = 0
    local right = #plus
    local curj = #plus
    for i = 1, #minus do
      local dst = x / minus[i]
      if x % minus[i] ~= 0 then dst = dst + 1 end
      local z = #plus + 1
      for j = curj, 1, -1 do
        if dst <= plus[j] then
          z = j
        else break end
      end
      curj = mmi(#plus, z)
      cnt = cnt + (#plus + 1 - z)
      if z == 1 then
        cnt = cnt + (#minus - i) * #plus
        break
      else
        right = mmi(z, #plus)
      end
    end
    return cnt
  end
  local max = 1LL
  local min = -ten9 * ten9 - 1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    local r = solve(mid)
    if k <= r then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
else
  local mmi = math.min
  k = k - minus_cnt
  local function solveA(x)
    local cnt = 0
    local right = #minus
    local curj = #minus
    for i = 1, #minus - 1 do
      local dst = x / minus[i]
      local z = curj + 1
      for j = curj, i + 1, -1 do
        if dst < minus[j] then
          z = j
        else
          break
        end
      end
      curj = mmi(#minus, z)
      z = z - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
    end
    right = #plus
    curj = #plus
    for i = 1, #plus - 1 do
      local z = 0
      if plus[i] == 0 then
        if x < 0 then
          z = i
        else
          z = right
        end
      else
        local dst = x / plus[i]
        z = curj + 1
        for j = curj, i + 1, -1 do
          if dst < plus[j] then
            z = j
          else
            break
          end
        end
        curj = mmi(#plus, z)
        z = z - 1
      end
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #plus)
    end
    return cnt
  end
  local max = ten9 * ten9 + 1LL
  local min = -1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    local r = solveA(mid)
    if k <= r then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
end

Score: 400 points

Problem Statement

We have N integers A_1, A_2, ..., A_N.

There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list?

Constraints

All values in input are integers.

2 \leq N \leq 2 \times 10^5

1 \leq K \leq \frac{N(N-1)}{2}

-10^9 \leq A_i \leq 10^9\ (1 \leq i \leq N)

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \dots A_N

Output

Print the answer.

Sample Input 1

4 3
3 3 -4 -2

Sample Output 1

-6

There are six ways to form a pair. The products of those pairs are 9, -12, -6, -12, -6, 8.

Sorting those numbers in ascending order, we have -12, -12, -6, -6, 8, 9. The third number in this list is -6.

Sample Input 2

10 40
5 4 3 2 -1 0 0 0 0 0

Sample Output 2

6

Sample Input 3

30 413
-170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0

Sample Output 3

448283280358331064


local mfl = math.floor
local function lower_bound(ary, x, right)
  local num = #ary
  if num == 0 then return 1 end
  if not (ary[1] < x) then return 1 end
  if (ary[right] < x) then return right + 1 end
  local min, max = 1, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if (ary[mid] < x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n, k = io.read("*n", "*n", "*l")
local t = {}
local str = io.read()
for s in str:gmatch("(-?%d+)") do
  table.insert(t, tonumber(s))
end
table.sort(t)
local plus_start_pos = n + 1
local minus, plus = {}, {}
for i = n, 1, -1 do
  if t[i] < 0 then
    table.insert(minus, -t[i])
  else
    table.insert(plus, t[i])
    plus_start_pos = i
  end
end
do
  local hn = math.floor(#plus / 2)
  for i = 1, hn do
    plus[i], plus[#plus + 1 - i] = plus[#plus + 1 - i], plus[i]
  end
end
local ten9 = 1000000000LL
local minus_cnt = #minus * #plus
if k <= minus_cnt then
  local mmi = math.min
  local function solve(x)
    x = -x
    local cnt = 0
    local right = #plus
    for i = 1, #minus do
      local dst = x / (0LL + minus[i])
      if x % minus[i] ~= 0 then dst = dst + 1 end
      local z = lower_bound(plus, dst, right)
      cnt = cnt + (#plus + 1 - z)
      if z == 1 then
        cnt = cnt + (#minus - i) * #plus
        break
      else
        right = mmi(z, #plus)
      end
    end
    return cnt
  end
  local max = 1LL
  local min = -ten9 * ten9 - 1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    local r = solve(mid)
    if k <= r then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
else
  local mmi = math.min
  k = k - minus_cnt
  local function solveA(x)
    local cnt = 0
    local right = #minus
    local curj = #minus
    for i = 1, #minus - 1 do
      local dst = x / minus[i]
      local z = curj + 1
      for j = curj, i + 1, -1 do
        if dst < minus[j] then
          z = j
        else
          break
        end
      end
      curj = mmi(#minus, z)
      z = z - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
    end
    right = #plus
    curj = #plus
    for i = 1, #plus - 1 do
      local z = 0
      if plus[i] == 0 then
        if x < 0 then
          z = i
        else
          z = right
        end
      else
        local dst = x / plus[i]
        z = curj + 1
        for j = curj, i + 1, -1 do
          if dst < plus[j] then
            z = j
          else
            break
          end
        end
        curj = mmi(#plus, z)
        z = z - 1
      end
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #plus)
    end
    return cnt
  end
  local max = ten9 * ten9 + 1LL
  local min = -1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    local r = solveA(mid)
    if k <= r then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
end


local mfl = math.floor
local function lower_bound(ary, x, right)
  local num = #ary
  if num == 0 then return 1 end
  if not (ary[1] < x) then return 1 end
  if (ary[right] < x) then return right + 1 end
  local min, max = 1, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if (ary[mid] < x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end
local g_tgt = 0LL
local function upper_bound(ary, left, right)
  local num = #ary
  if num == 0 then return 1 end
  if (g_tgt < ary[left] ) then return left end
  if not (g_tgt < ary[right] ) then return right + 1 end
  local min, max = left, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not (g_tgt < ary[mid] ) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n, k = io.read("*n", "*n", "*l")
local t = {}
local str = io.read()
for s in str:gmatch("(-?%d+)") do
  table.insert(t, tonumber(s))
end
table.sort(t)
local plus_start_pos = n + 1
local minus, plus = {}, {}
for i = n, 1, -1 do
  if t[i] < 0 then
    table.insert(minus, -t[i])
  else
    table.insert(plus, t[i])
    plus_start_pos = i
  end
end
do
  local hn = math.floor(#plus / 2)
  for i = 1, hn do
    plus[i], plus[#plus + 1 - i] = plus[#plus + 1 - i], plus[i]
  end
end
local ten9 = 1000000000LL
local minus_cnt = #minus * #plus
if k <= minus_cnt then
  local mmi = math.min
  local function solve(x)
    x = -x
    local cnt = 0
    local right = #plus
    for i = 1, #minus do
      local dst = x / (0LL + minus[i])
      if x % minus[i] ~= 0 then dst = dst + 1 end
      local z = lower_bound(plus, dst, right)
      cnt = cnt + (#plus + 1 - z)
      if z == 1 then
        cnt = cnt + (#minus - i) * #plus
        break
      else
        right = mmi(z, #plus)
      end
    end
    return cnt
  end
  local max = 1LL
  local min = -ten9 * ten9 - 1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    local r = solve(mid)
    if k <= r then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
else
  local mmi = math.min
  k = k - minus_cnt
  local function solveA(x)
    local cnt = 0
    local right = #minus
    local curj = #minus
    for i = 1, #minus - 1 do
      local dst = x / minus[i]
      local z = curj + 1
      for j = curj, i + 1, -1 do
        if dst < minus[j] then
          z = j
        else
          break
        end
      end
      curj = mmi(#minus, z)
      z = z - 1
      -- g_tgt = x / minus[i]
      -- local z = upper_bound(minus, i + 1, right) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      -- right = mmi(z + 1, #minus)
    end
    right = #plus
    for i = 1, #plus - 1 do
      local z = 0
      if plus[i] == 0 then
        if x < 0 then
          z = i
        else
          z = right
        end
      else
        g_tgt = x / plus[i]
        z = upper_bound(plus, i + 1, right) - 1
      end
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #plus)
    end
    return cnt
  end
  local max = ten9 * ten9 + 1LL
  local min = -1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    local r = solveA(mid)
    if k <= r then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
end


local mfl = math.floor
local function lower_bound(ary, x, right)
  local num = #ary
  if num == 0 then return 1 end
  if not (ary[1] < x) then return 1 end
  if (ary[right] < x) then return right + 1 end
  local min, max = 1, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if (ary[mid] < x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end
local g_tgt = 0LL
local function upper_bound(ary, left, right)
  local num = #ary
  if num == 0 then return 1 end
  if (g_tgt < ary[left] ) then return left end
  if not (g_tgt < ary[right] ) then return right + 1 end
  local min, max = left, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not (g_tgt < ary[mid] ) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n, k = io.read("*n", "*n", "*l")
local t = {}
local str = io.read()
for s in str:gmatch("(-?%d+)") do
  table.insert(t, tonumber(s))
end
table.sort(t)
local plus_start_pos = n + 1
local minus, plus = {}, {}
for i = n, 1, -1 do
  if t[i] < 0 then
    table.insert(minus, -t[i])
  else
    table.insert(plus, t[i])
    plus_start_pos = i
  end
end
do
  local hn = math.floor(#plus / 2)
  for i = 1, hn do
    plus[i], plus[#plus + 1 - i] = plus[#plus + 1 - i], plus[i]
  end
end
local ten9 = 1000000000LL
local minus_cnt = #minus * #plus
if k <= minus_cnt then
  local mmi = math.min
  local function solve(x)
    x = -x
    local cnt = 0
    local right = #plus
    for i = 1, #minus do
      local dst = x / (0LL + minus[i])
      if x % minus[i] ~= 0 then dst = dst + 1 end
      local z = lower_bound(plus, dst, right)
      cnt = cnt + (#plus + 1 - z)
      if z == 1 then
        cnt = cnt + (#minus - i) * #plus
        break
      else
        right = mmi(z, #plus)
      end
    end
    return cnt
  end
  local max = 1LL
  local min = -ten9 * ten9 - 1LL
  local mid = (min + max) / 2LL
  while 1LL < max - min do
    local r = solve(mid)
    if max - min < 10LL then
      if k <= r then
        max = mid
      else
        min = mid
      end
      mid = (min + max) / 2LL
    else
      if k <= r then
        max = mid
        if k * 10 < r then
          mid = (min * 3 + max) / 4LL
        else
          mid = (min + max) / 2LL
        end
      else
        min = mid
        if r * 10 < k then
          mid = (min + max * 3) / 4LL
        else
          mid = (min + max) / 2LL
        end
      end
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
else
  local mmi = math.min
  k = k - minus_cnt
  local function solveA(x)
    local cnt = 0
    local right = #minus
    for i = 1, #minus - 1 do
      g_tgt = x / minus[i]
      local z = upper_bound(minus, i + 1, right) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #minus)
    end
    right = #plus
    for i = 1, #plus - 1 do
      local z = 0
      if plus[i] == 0 then
        if x < 0 then
          z = i
        else
          z = right
        end
      else
        g_tgt = x / plus[i]
        z = upper_bound(plus, i + 1, right) - 1
      end
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #plus)
    end
    return cnt
  end
  local max = ten9 * ten9 + 1LL
  local min = -1LL
  local mid = (min + max) / 2LL
  while 1LL < max - min do
    local r = solveA(mid)
    if max - min < 10LL then
      if k <= r then
        max = mid
      else
        min = mid
      end
      mid = (min + max) / 2LL
    else
      if k <= r then
        max = mid
        if k * 10 < r then
          mid = (min * 3 + max) / 4LL
        else
          mid = (min + max) / 2LL
        end
      else
        min = mid
        if r * 10 < k then
          mid = (min + max * 3) / 4LL
        else
          mid = (min + max) / 2LL
        end
      end
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
end


local mfl = math.floor
local function lower_bound(ary, x, right)
  local num = #ary
  if num == 0 then return 1 end
  if not (ary[1] < x) then return 1 end
  if (ary[right] < x) then return right + 1 end
  local min, max = 1, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if (ary[mid] < x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end
local g_tgt = 0LL
local function upper_bound(ary, left, right)
  local num = #ary
  if num == 0 then return 1 end
  if (g_tgt < ary[left] ) then return left end
  if not (g_tgt < ary[right] ) then return right + 1 end
  local min, max = left, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not (g_tgt < ary[mid] ) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n, k = io.read("*n", "*n", "*l")
local t = {}
local str = io.read()
for s in str:gmatch("(-?%d+)") do
  table.insert(t, tonumber(s))
end
table.sort(t)
local plus_start_pos = n + 1
local minus, plus = {}, {}
for i = n, 1, -1 do
  if t[i] < 0 then
    table.insert(minus, -t[i])
  else
    table.insert(plus, t[i])
    plus_start_pos = i
  end
end
do
  local hn = math.floor(#plus / 2)
  for i = 1, hn do
    plus[i], plus[#plus + 1 - i] = plus[#plus + 1 - i], plus[i]
  end
end
local ten9 = 1000000000LL
local minus_cnt = #minus * #plus
if k <= minus_cnt then
  local mmi = math.min
  local function solve(x)
    x = -x
    local cnt = 0
    local right = #plus
    for i = 1, #minus do
      local dst = x / (0LL + minus[i])
      if x % minus[i] ~= 0 then dst = dst + 1 end
      local z = lower_bound(plus, dst, right)
      cnt = cnt + (#plus + 1 - z)
      if z == 1 then
        cnt = cnt + (#minus - i) * #plus
        break
      else
        right = mmi(z, #plus)
      end
    end
    return k <= cnt
  end
  local max = 1LL
  local min = -ten9 * ten9 - 1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solve(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
else
  local mmi = math.min
  k = k - minus_cnt
  local function solveA(x)
    local cnt = 0
    local right = #minus
    for i = 1, #minus - 1 do
      g_tgt = x / minus[i]
      local z = upper_bound(minus, i + 1, right) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #minus)
    end
    right = #plus
    for i = 1, #plus - 1 do
      local z = 0
      if plus[i] == 0 then
        if x < 0 then
          z = i
        else
          z = right
        end
      else
        g_tgt = x / plus[i]
        z = upper_bound(plus, i + 1, right) - 1
      end
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #plus)
    end
    return cnt
  end
  local max = ten9 * ten9 + 1LL
  local min = -1LL
  local mid = (min + max) / 2LL
  while 1LL < max - min do
    local r = solveA(mid)
    if max - min < 10LL then
      if k <= r then
        max = mid
      else
        min = mid
      end
      mid = (min + max) / 2LL
    else
      if k <= r then
        max = mid
        if k * 10 < r then
          mid = (min * 3 + max) / 4LL
        else
          mid = (min + max) / 2LL
        end
      else
        min = mid
        if r * 10 < k then
          mid = (min + max * 3) / 4LL
        else
          mid = (min + max) / 2LL
        end
      end
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
end


local mfl = math.floor
local function lower_bound(ary, x, right)
  local num = #ary
  if num == 0 then return 1 end
  if not (ary[1] < x) then return 1 end
  if (ary[right] < x) then return right + 1 end
  local min, max = 1, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if (ary[mid] < x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end
local g_tgt = 0LL
local function upper_bound(ary, left, right)
  local num = #ary
  if num == 0 then return 1 end
  if (g_tgt < ary[left] ) then return left end
  if not (g_tgt < ary[right] ) then return right + 1 end
  local min, max = left, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not (g_tgt < ary[mid] ) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n, k = io.read("*n", "*n", "*l")
local t = {}
local str = io.read()
for s in str:gmatch("(-?%d+)") do
  table.insert(t, tonumber(s))
end
table.sort(t)
local plus_start_pos = n + 1
local minus, plus = {}, {}
for i = n, 1, -1 do
  if t[i] < 0 then
    table.insert(minus, -t[i])
  else
    table.insert(plus, t[i])
    plus_start_pos = i
  end
end
do
  local hn = math.floor(#plus / 2)
  for i = 1, hn do
    plus[i], plus[#plus + 1 - i] = plus[#plus + 1 - i], plus[i]
  end
end
local ten9 = 1000000000LL
local minus_cnt = #minus * #plus
if k <= minus_cnt then
  local mmi = math.min
  local function solve(x)
    x = -x
    local cnt = 0
    local right = #plus
    for i = 1, #minus do
      local dst = x / (0LL + minus[i])
      if x % minus[i] ~= 0 then dst = dst + 1 end
      local z = lower_bound(plus, dst, right)
      cnt = cnt + (#plus + 1 - z)
      if z == 1 then
        cnt = cnt + (#minus - i) * #plus
        break
      else
        right = mmi(z, #plus)
      end
    end
    return k <= cnt
  end
  local max = 1LL
  local min = -ten9 * ten9 - 1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solve(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
else
  local mmi = math.min
  k = k - minus_cnt
  local function solveA(x)
    local cnt = 0
    local right = #minus
    for i = 1, #minus - 1 do
      g_tgt = x / minus[i]
      local z = upper_bound(minus, i + 1, right) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #minus)
    end
    right = #plus
    for i = 1, #plus - 1 do
      local z = 0
      if plus[i] == 0 then
        if x < 0 then
          z = i
        else
          z = right
        end
      else
        g_tgt = x / plus[i]
        z = upper_bound(plus, i + 1, right) - 1
      end
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #plus)
    end
    return k <= cnt
  end
  local max = ten9 * ten9 + 1LL
  local min = -1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solveA(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
end


local mfl = math.floor
local function lower_bound(ary, x, right)
  local num = #ary
  if num == 0 then return 1 end
  if not (ary[1] < x) then return 1 end
  if (ary[right] < x) then return right + 1 end
  local min, max = 1, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if (ary[mid] < x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end
local function upper_bound(ary, left, right, x)
  local num = #ary
  if num == 0 then return 1 end
  if (x < ary[left] ) then return left end
  if not (x < ary[right] ) then return right + 1 end
  local min, max = left, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not (x < ary[mid] ) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n, k = io.read("*n", "*n", "*l")
local t = {}
local str = io.read()
for s in str:gmatch("(-?%d+)") do
  table.insert(t, tonumber(s))
end
table.sort(t)
local plus_start_pos = n + 1
local minus, plus = {}, {}
for i = n, 1, -1 do
  if t[i] < 0 then
    table.insert(minus, -t[i])
  else
    table.insert(plus, t[i])
    plus_start_pos = i
  end
end
do
  local hn = math.floor(#plus / 2)
  for i = 1, hn do
    plus[i], plus[#plus + 1 - i] = plus[#plus + 1 - i], plus[i]
  end
end
local ten9 = 1000000000LL
local minus_cnt = #minus * #plus
if k <= minus_cnt then
  local mmi = math.min
  local function solve(x)
    x = -x
    local cnt = 0
    local right = #plus
    for i = 1, #minus do
      local dst = x / (0LL + minus[i])
      local tmp = tostring(dst):gsub("LL", "")
      dst = tonumber(tmp)
      if x % (0LL + minus[i]) ~= 0 then dst = dst + 1 end
      local z = lower_bound(plus, dst, right)
      cnt = cnt + (#plus + 1 - z)
      if z == 1 then
        cnt = cnt + (#minus - i) * #plus
        break
      else
        right = mmi(z, #plus)
      end
    end
    return k <= cnt
  end
  local max = 1LL
  local min = -ten9 * ten9 - 1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solve(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
else
  local mmi = math.min
  k = k - minus_cnt
  local function solveA(x)
    local cnt = 0
    local right = #minus
    for i = 1, #minus - 1 do
      local dst = x / (0LL + minus[i])
      local tmp = tostring(dst):gsub("LL", "")
      dst = tonumber(tmp)
      local z = upper_bound(minus, i + 1, right, dst) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #minus)
    end
    right = #plus
    for i = 1, #plus - 1 do
      local z = 0
      if plus[i] == 0 then
        if x < 0 then
          z = i
        elseif x == 0 then
          z = right
        else
          z = right
        end
      else
        local dst = x / (0LL + plus[i])
        z = upper_bound(plus, i + 1, right, dst) - 1
      end
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #plus)
    end
    return k <= cnt
  end
  local max = ten9 * ten9 + 1LL
  local min = -1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solveA(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
end


local mfl = math.floor
local function lower_bound(ary, x, right)
  local num = #ary
  if num == 0 then return 1 end
  if not (ary[1] < x) then return 1 end
  if (ary[right] < x) then return right + 1 end
  local min, max = 1, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if (ary[mid] < x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end
local function upper_bound(ary, left, right, x)
  local num = #ary
  if num == 0 then return 1 end
  if (x < ary[left] ) then return left end
  if not (x < ary[right] ) then return right + 1 end
  local min, max = left, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not (x < ary[mid] ) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n, k = io.read("*n", "*n", "*l")
local t = {}
local str = io.read()
for s in str:gmatch("(-?%d+)") do
  table.insert(t, tonumber(s))
end
table.sort(t)
local plus_start_pos = n + 1
local minus, plus = {}, {}
for i = n, 1, -1 do
  if t[i] < 0 then
    table.insert(minus, -t[i])
  else
    table.insert(plus, t[i])
    plus_start_pos = i
  end
end
do
  local hn = math.floor(#plus / 2)
  for i = 1, hn do
    plus[i], plus[#plus + 1 - i] = plus[#plus + 1 - i], plus[i]
  end
end
local ten9 = 1000000000LL
local minus_cnt = #minus * #plus
if k <= minus_cnt then
  local mmi = math.min
  local function solve(x)
    x = -x
    local cnt = 0
    local right = #plus
    for i = 1, #minus do
      local dst = x / (0LL + minus[i])
      if x % (0LL + minus[i]) ~= 0 then dst = dst + 1 end
      local z = lower_bound(plus, dst, right)
      cnt = cnt + (#plus + 1 - z)
      if z == 1 then
        cnt = cnt + (#minus - i) * #plus
        break
      else
        right = mmi(z, #plus)
      end
    end
    return k <= cnt
  end
  local max = 1LL
  local min = -ten9 * ten9 - 1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solve(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
else
  local mmi = math.min
  k = k - minus_cnt
  local function solveA(x)
    local cnt = 0
    local right = #minus
    for i = 1, #minus - 1 do
      local dst = x / (0LL + minus[i])
      local z = upper_bound(minus, i + 1, right, dst) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #minus)
    end
    right = #plus
    for i = 1, #plus - 1 do
      local z = 0
      if plus[i] == 0 then
        if x < 0 then
          z = i
        elseif x == 0 then
          z = right
        else
          z = right
        end
      else
        local dst = x / (0LL + plus[i])
        z = upper_bound(plus, i + 1, right, dst) - 1
      end
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #plus)
    end
    return k <= cnt
  end
  local max = ten9 * ten9 + 1LL
  local min = -1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solveA(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
end


local mfl = math.floor
local g_tgt = 0
local function lower_bound(ary, x, mul, right)
  local num = #ary
  if num == 0 then return 1 end
  if not (1LL*ary[1] * mul < x) then return 1 end
  if (1LL*ary[right] * mul < x) then return right + 1 end
  local min, max = 1, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if (1LL*ary[mid] * mul < x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end
local function upper_bound(ary, left, right, x)
  -- local x = g_tgt
  local num = #ary
  if num == 0 then return 1 end
  if (x < ary[left] ) then return left end
  if not (x < ary[right] ) then return right + 1 end
  local min, max = left, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not (x < ary[mid] ) then
      min = mid
    else
      max = mid
    end
  end
  return max
end
local function upper_bound2(ary, left, right, mul)
  local x = g_tgt
  local num = #ary
  if num == 0 then return 1 end
  if (x < 1LL*ary[left] *mul) then return left end
  if not (x < 1LL*ary[right] *mul) then return right + 1 end
  local min, max = left, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not (x < 1LL*ary[mid] *mul) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local function upper_bound3(ary, left, right)
  local num = #ary
  if num == 0 then return 1 end
  if (0 < ary[left] ) then return left end
  if not (0 < ary[right] ) then return right + 1 end
  local min, max = left, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not (0 < ary[mid] ) then
      min = mid
    else
      max = mid
    end
  end
  return max
end
local n, k = io.read("*n", "*n", "*l")
local t = {}
local str = io.read()
for s in str:gmatch("(-?%d+)") do
  table.insert(t, tonumber(s))
end
table.sort(t)
local plus_start_pos = n + 1
local minus, plus = {}, {}
for i = n, 1, -1 do
  if t[i] < 0 then
    table.insert(minus, -t[i])
  else
    table.insert(plus, t[i])
    plus_start_pos = i
  end
end
do
  local hn = math.floor(#plus / 2)
  for i = 1, hn do
    plus[i], plus[#plus + 1 - i] = plus[#plus + 1 - i], plus[i]
  end
end
local ten9 = 1000000000LL
local minus_cnt = #minus * #plus
if k <= minus_cnt then
  local mmi = math.min
  local function solve(x)
    x = -x
    local cnt = 0
    local right = #plus
    for i = 1, #minus do
      local z = lower_bound(plus, x, 0LL+ minus[i], right)
      cnt = cnt + (#plus + 1 - z)
      if z == 1 then
        cnt = cnt + (#minus - i) * #plus
        break
      else
        right = mmi(z, #plus)
      end
    end
    return k <= cnt
  end
  local max = 1LL
  local min = -ten9 * ten9 - 1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solve(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
else
  local mmi = math.min
  k = k - minus_cnt
  local function solveA(x)
    g_tgt = x
    local cnt = 0
    local right = #minus
    for i = 1, #minus - 1 do
      local dst = x / (0LL + minus[i])
      local z = upper_bound(minus, i + 1, right, dst) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #minus)
    end
    right = #plus
    for i = 1, #plus - 1 do
      local z = 0
      if plus[i] == 0 then
        if x < 0 then
          z = i
        elseif x == 0 then
          z = right
        else
          z = right
        end
        -- z = upper_bound2(plus, i + 1, right, plus[i]) - 1
      else
        local dst = x / (0LL + plus[i])
        z = upper_bound(plus, i + 1, right, dst) - 1
      end
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #plus)
    end
    return k <= cnt
  end
  local max = ten9 * ten9 + 1LL
  local min = -1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solveA(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
end


local mfl = math.floor
local g_tgt = 0
local function lower_bound(ary, x, mul, right)
  local num = #ary
  if num == 0 then return 1 end
  if not (1LL*ary[1] * mul < x) then return 1 end
  if (1LL*ary[right] * mul < x) then return right + 1 end
  local min, max = 1, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if (1LL*ary[mid] * mul < x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end
local function upper_bound(ary, left, right, x)
  -- local x = g_tgt
  local num = #ary
  if num == 0 then return 1 end
  if (x < ary[left] ) then return left end
  if not (x < ary[right] ) then return right + 1 end
  local min, max = left, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not (x < ary[mid] ) then
      min = mid
    else
      max = mid
    end
  end
  return max
end
local function upper_bound2(ary, left, right, mul)
  local x = g_tgt
  local num = #ary
  if num == 0 then return 1 end
  if (x < 1LL*ary[left] *mul) then return left end
  if not (x < 1LL*ary[right] *mul) then return right + 1 end
  local min, max = left, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not (x < 1LL*ary[mid] *mul) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n, k = io.read("*n", "*n", "*l")
local t = {}
local str = io.read()
for s in str:gmatch("(-?%d+)") do
  table.insert(t, tonumber(s))
end
table.sort(t)
local plus_start_pos = n + 1
local minus, plus = {}, {}
for i = n, 1, -1 do
  if t[i] < 0 then
    table.insert(minus, -t[i])
  else
    table.insert(plus, t[i])
    plus_start_pos = i
  end
end
do
  local hn = math.floor(#plus / 2)
  for i = 1, hn do
    plus[i], plus[#plus + 1 - i] = plus[#plus + 1 - i], plus[i]
  end
end
local ten9 = 1000000000LL
local minus_cnt = #minus * #plus
if k <= minus_cnt then
  local mmi = math.min
  local function solve(x)
    x = -x
    local cnt = 0
    local right = #plus
    for i = 1, #minus do
      local z = lower_bound(plus, x, 0LL+ minus[i], right)
      cnt = cnt + (#plus + 1 - z)
      if z == 1 then
        cnt = cnt + (#minus - i) * #plus
        break
      else
        right = mmi(z, #plus)
      end
    end
    return k <= cnt
  end
  local max = 1LL
  local min = -ten9 * ten9 - 1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solve(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
else
  local mmi = math.min
  k = k - minus_cnt
  local function solveA(x)
    g_tgt = x
    local cnt = 0
    local right = #minus
    for i = 1, #minus - 1 do
      local dst = x / (0LL + minus[i])
      local z = upper_bound(minus, i + 1, right, dst) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #minus)
    end
    right = #plus
    for i = 1, #plus - 1 do
      local z = upper_bound2(plus, i + 1, right, plus[i]) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #plus)
    end
    return k <= cnt
  end
  local max = ten9 * ten9 + 1LL
  local min = -1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solveA(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
end


local mfl = math.floor
local g_tgt = 0
local function lower_bound(ary, x, mul, right)
  local num = #ary
  if num == 0 then return 1 end
  if not (1LL*aary[1] * mul < x) then return 1 end
  if (1LL*aary[right] * mul < x) then return right + 1 end
  local min, max = 1, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if (1LL*aary[mid] * mul < x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end
local function upper_bound(ary, left, right, x)
  -- local x = g_tgt
  local num = #ary
  if num == 0 then return 1 end
  if (x < ary[left] ) then return left end
  if not (x < ary[right] ) then return right + 1 end
  local min, max = left, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not (x < ary[mid] ) then
      min = mid
    else
      max = mid
    end
  end
  return max
end
local function upper_bound2(ary, left, right, mul)
  local x = g_tgt
  local num = #ary
  if num == 0 then return 1 end
  if (x < 1LL*ary[left] *mul) then return left end
  if not (x < 1LL*ary[right] *mul) then return right + 1 end
  local min, max = left, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not (x < 1LL*ary[mid] *mul) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n, k = io.read("*n", "*n", "*l")
local t = {}
local str = io.read()
for s in str:gmatch("(-?%d+)") do
  table.insert(t, tonumber(s))
end
table.sort(t)
local plus_start_pos = n + 1
local minus, plus = {}, {}
for i = n, 1, -1 do
  if t[i] < 0 then
    table.insert(minus, -t[i])
  else
    table.insert(plus, t[i])
    plus_start_pos = i
  end
end
do
  local hn = math.floor(#plus / 2)
  for i = 1, hn do
    plus[i], plus[#plus + 1 - i] = plus[#plus + 1 - i], plus[i]
  end
end
local ten9 = 1000000000LL
local minus_cnt = #minus * #plus
if k <= minus_cnt then
  local mmi = math.min
  local function solve(x)
    x = -x
    local cnt = 0
    local right = #plus
    for i = 1, #minus do
      local z = lower_bound(plus, x, 0LL+ minus[i], right)
      cnt = cnt + (#plus + 1 - z)
      if z == 1 then
        cnt = cnt + (#minus - i) * #plus
        break
      else
        right = mmi(z, #plus)
      end
    end
    return k <= cnt
  end
  local max = 1LL
  local min = -ten9 * ten9 - 1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solve(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
else
  local mmi = math.min
  k = k - minus_cnt
  local function solveA(x)
    g_tgt = x
    local cnt = 0
    local right = #minus
    for i = 1, #minus - 1 do
      local dst = x / (0LL + minus[i])
      local z = upper_bound(minus, i + 1, right, dst) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #minus)
    end
    right = #plus
    for i = 1, #plus - 1 do
      local z = upper_bound2(plus, i + 1, right, plus[i]) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #plus)
    end
    return k <= cnt
  end
  local max = ten9 * ten9 + 1LL
  local min = -1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solveA(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
end


local mfl = math.floor

local function lower_bound(ary, x, mul, right)
  local num = #ary
  if num == 0 then return 1 end
  if not (1LL*ary[1] * mul < x) then return 1 end
  if 1LL*ary[right] * mul < x then return right + 1 end
  local min, max = 1, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if (1LL*ary[mid] * mul < x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end
local function upper_bound(ary, left, right, x, mul)
  local num = #ary
  if num == 0 then return 1 end
  if (x < 1LL* ary[left] * mul) then return left end
  if not (x < 1LL*ary[right] * mul) then return right + 1 end
  local min, max = left, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not (x < 1LL*ary[mid] * mul) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n, k = io.read("*n", "*n", "*l")
local t = {}
local str = io.read()
for s in str:gmatch("(-?%d+)") do
  table.insert(t, tonumber(s))
end
-- for i = 1, n do
--   t[i] = io.read("*n")
-- end
table.sort(t)
local plus_start_pos = n + 1
local minus, plus = {}, {}
for i = n, 1, -1 do
  if t[i] < 0 then
    table.insert(minus, -t[i])
  else
    table.insert(plus, t[i])
    plus_start_pos = i
  end
end
do
  local hn = math.floor(#plus / 2)
  for i = 1, hn do
    plus[i], plus[#plus + 1 - i] = plus[#plus + 1 - i], plus[i]
  end
end
local ten9 = 1000000000LL
local minus_cnt = #minus * #plus
if k <= minus_cnt then
  local mmi = math.min
  local function solve(x)
    x = -x
    local cnt = 0
    local right = #plus
    for i = 1, #minus do
      local z = lower_bound(plus, x, minus[i], right)
      cnt = cnt + (#plus + 1 - z)
      if z == 1 then
        cnt = cnt + (#minus - i) * #plus
        break
      else
        right = mmi(z, #plus)
      end
    end
    return k <= cnt
  end
  local max = 1LL
  local min = -ten9 * ten9 - 1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solve(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
else
  local mmi = math.min
  k = k - minus_cnt
  local function solveA(x)
    local cnt = 0
    local right = #minus
    for i = 1, #minus - 1 do
      local z = upper_bound(minus, i + 1, right, x, minus[i]) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #minus)
    end
    right = #plus
    for i = 1, #plus - 1 do
      local z = upper_bound(plus, i + 1, right, x, plus[i]) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #plus)
    end
    return k <= cnt
  end
  local max = ten9 * ten9 + 1LL
  local min = -1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solveA(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
end


local mfl = math.floor

local function comp(a, b)
  return a < b
end

local function lower_bound(ary, x, mul, right)
  local num = #ary
  if num == 0 then return 1 end
  if not comp(1LL*ary[1] * mul, x) then return 1 end
  if comp(1LL*ary[right] * mul, x) then return right + 1 end
  local min, max = 1, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if comp(1LL*ary[mid] * mul, x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end
local function upper_bound(ary, left, right, x, mul)
  local num = #ary
  if num == 0 then return 1 end
  if comp(x, 1LL* ary[left] * mul) then return left end
  if not comp(x, 1LL*ary[right] * mul) then return right + 1 end
  local min, max = left, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not comp(x, 1LL*ary[mid] * mul) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n, k = io.read("*n", "*n")
local t = {}
for i = 1, n do
  t[i] = io.read("*n")
end
table.sort(t)
local plus_start_pos = n + 1
local minus, plus = {}, {}
for i = n, 1, -1 do
  if t[i] < 0 then
    table.insert(minus, -t[i])
  else
    table.insert(plus, t[i])
    plus_start_pos = i
  end
end
do
  local hn = math.floor(#plus / 2)
  for i = 1, hn do
    plus[i], plus[#plus + 1 - i] = plus[#plus + 1 - i], plus[i]
  end
end
local ten9 = 1000000000LL
local minus_cnt = #minus * #plus
if k <= minus_cnt then
  local mmi = math.min
  local function solve(x)
    x = -x
    local cnt = 0
    local right = #plus
    for i = 1, #minus do
      local z = lower_bound(plus, x, minus[i], right)
      cnt = cnt + (#plus + 1 - z)
      if z == 1 then
        cnt = cnt + (#minus - i) * #plus
        break
      else
        right = mmi(z, #plus)
      end
    end
    return k <= cnt
  end
  local max = 1LL
  local min = -ten9 * ten9 - 1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solve(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
else
  local mmi = math.min
  k = k - minus_cnt
  local function solveA(x)
    local cnt = 0
    local right = #minus
    for i = 1, #minus - 1 do
      local z = upper_bound(minus, i + 1, right, x, minus[i]) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #minus)
    end
    right = #plus
    for i = 1, #plus - 1 do
      local z = upper_bound(plus, i + 1, right, x, plus[i]) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #plus)
    end
    return k <= cnt
  end
  local max = ten9 * ten9 + 1LL
  local min = -1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solveA(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
end


local mfl = math.floor

local function comp(a, b)
  return a < b
end

local function lower_bound(ary, x, mul, right)
  local num = #ary
  if num == 0 then return 1 end
  if not comp(ary[1] * mul, x) then return 1 end
  if comp(ary[right] * mul, x) then return right + 1 end
  local min, max = 1, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if comp(ary[mid] * mul, x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end
local function upper_bound(ary, left, right, x, mul)
  local num = #ary
  if num == 0 then return 1 end
  if comp(x, ary[left] * mul) then return left end
  if not comp(x, ary[right] * mul) then return right + 1 end
  local min, max = left, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not comp(x, ary[mid] * mul) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n, k = io.read("*n", "*n")
local t = {}
for i = 1, n do
  t[i] = 0LL + io.read("*n")
end
table.sort(t)
local plus_start_pos = n + 1
local minus, plus = {}, {}
for i = n, 1, -1 do
  if t[i] < 0 then
    table.insert(minus, -t[i])
  else
    table.insert(plus, t[i])
    plus_start_pos = i
  end
end
do
  local hn = math.floor(#plus / 2)
  for i = 1, hn do
    plus[i], plus[#plus + 1 - i] = plus[#plus + 1 - i], plus[i]
  end
end
local ten9 = 1000000000LL
local minus_cnt = #minus * #plus
if k <= minus_cnt then
  local mmi = math.min
  local function solve(x)
    x = -x
    local cnt = 0
    local right = #plus
    for i = 1, #minus do
      local z = lower_bound(plus, x, minus[i], right)
      cnt = cnt + (#plus + 1 - z)
      if z == 1 then
        cnt = cnt + (#minus - i) * #plus
        break
      else
        right = mmi(z, #plus)
      end
    end
    return k <= cnt
  end
  local max = 1LL
  local min = -ten9 * ten9 - 1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solve(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
else
  local mmi = math.min
  k = k - minus_cnt
  local function solveA(x)
    local cnt = 0
    local right = #minus
    for i = 1, #minus - 1 do
      local z = upper_bound(minus, i + 1, right, x, minus[i]) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #minus)
    end
    right = #plus
    for i = 1, #plus - 1 do
      local z = upper_bound(plus, i + 1, right, x, plus[i]) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #plus)
    end
    return k <= cnt
  end
  local max = ten9 * ten9 + 1LL
  local min = -1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solveA(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
end


local mfl = math.floor

local function comp(a, b)
  return a < b
end

local function lower_bound(ary, x, mul, right)
  local num = #ary
  if num == 0 then return 1 end
  if not comp(ary[1] * mul, x) then return 1 end
  if comp(ary[right] * mul, x) then return right + 1 end
  local min, max = 1, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if comp(ary[mid] * mul, x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end
local function upper_bound(ary, left, right, x, mul)
  local num = #ary
  if num == 0 then return 1 end
  if comp(x, ary[left] * mul) then return left end
  if not comp(x, ary[right] * mul) then return right + 1 end
  local min, max = left, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not comp(x, ary[mid] * mul) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n, k = io.read("*n", "*n")
local t = {}
for i = 1, n do
  t[i] = 0LL + io.read("*n")
end
table.sort(t)
local plus_start_pos = n + 1
local minus, plus = {}, {}
for i = n, 1, -1 do
  if t[i] < 0 then
    table.insert(minus, -t[i])
  else
    table.insert(plus, t[i])
    plus_start_pos = i
  end
end
do
  local hn = math.floor(#plus / 2)
  for i = 1, hn do
    plus[i], plus[#plus + 1 - i] = plus[#plus + 1 - i], plus[i]
  end
end
local ten9 = 1000000000LL
local minus_cnt = #minus * #plus
if k <= minus_cnt then
  local function solve(x)
    x = -x
    local cnt = 0
    local right = #plus
    for i = 1, #minus do
      local z = lower_bound(plus, x, minus[i], right)
      cnt = cnt + (#plus + 1 - z)
      if z == 1 then
        cnt = cnt + (#minus - i) * #plus
        break
      else
        right = mmi(z, #plus)
      end
    end
    return k <= cnt
  end
  local max = 1LL
  local min = -ten9 * ten9 - 1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solve(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
else
  local mmi = math.min
  k = k - minus_cnt
  local function solveA(x)
    local cnt = 0
    local right = #minus
    for i = 1, #minus - 1 do
      local z = upper_bound(minus, i + 1, right, x, minus[i]) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #minus)
    end
    right = #plus
    for i = 1, #plus - 1 do
      local z = upper_bound(plus, i + 1, right, x, plus[i]) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #plus)
    end
    return k <= cnt
  end
  local max = ten9 * ten9 + 1LL
  local min = -1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solveA(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
end


local mfl = math.floor

local function comp(a, b)
  return a < b
end

local function lower_bound(ary, x, mul)
  local num = #ary
  if num == 0 then return 1 end
  if not comp(ary[1] * mul, x) then return 1 end
  if comp(ary[num] * mul, x) then return num + 1 end
  local min, max = 1, num
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if comp(ary[mid] * mul, x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end
local function upper_bound(ary, left, right, x, mul)
  local num = #ary
  if num == 0 then return 1 end
  if comp(x, ary[left] * mul) then return left end
  if not comp(x, ary[right] * mul) then return right + 1 end
  local min, max = left, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not comp(x, ary[mid] * mul) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n, k = io.read("*n", "*n")
local t = {}
for i = 1, n do
  t[i] = 0LL + io.read("*n")
end
table.sort(t)
local plus_start_pos = n + 1
local minus, plus = {}, {}
for i = n, 1, -1 do
  if t[i] < 0 then
    table.insert(minus, -t[i])
  else
    table.insert(plus, t[i])
    plus_start_pos = i
  end
end
do
  local hn = math.floor(#plus / 2)
  for i = 1, hn do
    plus[i], plus[#plus + 1 - i] = plus[#plus + 1 - i], plus[i]
  end
end
local ten9 = 1000000000LL
local minus_cnt = #minus * #plus
if k <= minus_cnt then
  local function solve(x)
    x = -x
    local cnt = 0
    for i = 1, #minus do
      local z = lower_bound(plus, x, minus[i])
      cnt = cnt + (#plus + 1 - z)
    end
    return k <= cnt
  end
  local max = 1LL
  local min = -ten9 * ten9 - 1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solve(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
else
  local mmi = math.min
  k = k - minus_cnt
  local function solveA(x)
    local cnt = 0
    local right = #minus
    for i = 1, #minus - 1 do
      local z = upper_bound(minus, i + 1, right, x, minus[i]) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #minus)
    end
    right = #plus
    for i = 1, #plus - 1 do
      local z = upper_bound(plus, i + 1, right, x, plus[i]) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #plus)
    end
    return k <= cnt
  end
  local max = ten9 * ten9 + 1LL
  local min = -1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solveA(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
end


local mfl = math.floor

local function comp(a, b)
  return a < b
end

local function lower_bound(ary, x, mul)
  local num = #ary
  if num == 0 then return 1 end
  if not comp(ary[1] * mul, x) then return 1 end
  if comp(ary[num] * mul, x) then return num + 1 end
  local min, max = 1, num
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if comp(ary[mid] * mul, x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end
local function upper_bound(ary, left, right, x, mul)
  local num = #ary
  if num == 0 then return 1 end
  if comp(x, ary[left] * mul) then return left end
  if not comp(x, ary[right] * mul) then return right + 1 end
  local min, max = left, right
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not comp(x, ary[mid] * mul) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n, k = io.read("*n", "*n")
local t = {}
for i = 1, n do
  t[i] = 0LL + io.read("*n")
end
table.sort(t)
local plus_start_pos = n + 1
local minus, plus = {}, {}
for i = n, 1, -1 do
  if t[i] < 0 then
    table.insert(minus, -t[i])
  else
    table.insert(plus, t[i])
    plus_start_pos = i
  end
end
do
  local hn = math.floor(#plus / 2)
  for i = 1, hn do
    plus[i], plus[#plus + 1 - i] = plus[#plus + 1 - i], plus[i]
  end
end
local ten9 = 1000000000LL
local minus_cnt = #minus * #plus
if k <= minus_cnt then
  local function solve(x)
    x = -x
    local cnt = 0
    for i = 1, #minus do
      local z = lower_bound(plus, x, minus[i])
      cnt = cnt + (#plus + 1 - z)
      if #plus + 1 - z == 0 then break end
    end
    return k <= cnt
  end
  local max = 1LL
  local min = -ten9 * ten9 - 1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solve(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
else
  local mmi = math.min
  k = k - minus_cnt
  local function solveA(x)
    local cnt = 0
    local right = #minus
    for i = 1, #minus - 1 do
      local z = upper_bound(minus, i + 1, right, x, minus[i]) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #minus)
    end
    right = #plus
    for i = 1, #plus - 1 do
      local z = upper_bound(plus, i + 1, right, x, plus[i]) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
      right = mmi(z + 1, #plus)
    end
    return k <= cnt
  end
  local max = ten9 * ten9 + 1LL
  local min = -1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solveA(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
end


local mfl = math.floor

local function comp(a, b)
  return a < b
end

local function lower_bound(ary, x, mul)
  local num = #ary
  if num == 0 then return 1 end
  if not comp(ary[1] * mul, x) then return 1 end
  if comp(ary[num] * mul, x) then return num + 1 end
  local min, max = 1, num
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if comp(ary[mid] * mul, x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end
local function upper_bound(ary, left, x, mul)
  local num = #ary
  if num == 0 then return 1 end
  if comp(x, ary[left] * mul) then return left end
  if not comp(x, ary[num] * mul) then return num + 1 end
  local min, max = left, num
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not comp(x, ary[mid] * mul) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n, k = io.read("*n", "*n")
local t = {}
for i = 1, n do
  t[i] = 0LL + io.read("*n")
end
table.sort(t)
local plus_start_pos = n + 1
local minus, plus = {}, {}
for i = n, 1, -1 do
  if t[i] < 0 then
    table.insert(minus, -t[i])
  else
    table.insert(plus, t[i])
    plus_start_pos = i
  end
end
do
  local hn = math.floor(#plus / 2)
  for i = 1, hn do
    plus[i], plus[#plus + 1 - i] = plus[#plus + 1 - i], plus[i]
  end
end
local ten9 = 1000000000LL
local minus_cnt = #minus * #plus
if k <= minus_cnt then
  local function solve(x)
    x = -x
    local cnt = 0
    for i = 1, #minus do
      local z = lower_bound(plus, x, minus[i])
      cnt = cnt + (#plus + 1 - z)
    end
    return k <= cnt
  end
  local max = 1LL
  local min = -ten9 * ten9 - 1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solve(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
else
  k = k - minus_cnt
  local function solveA(x)
    local cnt = 0
    for i = 1, #minus - 1 do
      local z = upper_bound(minus, i + 1, x, minus[i]) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
    end
    for i = 1, #plus - 1 do
      local z = upper_bound(plus, i + 1, x, plus[i]) - 1
      cnt = cnt + (z - i)
      if z - i == 0 then break end
    end
    return k <= cnt
  end
  local max = ten9 * ten9 + 1LL
  local min = -1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solveA(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
end


local mfl = math.floor

local function comp(a, b)
  return a < b
end

local function lower_bound(ary, x, mul)
  local num = #ary
  if num == 0 then return 1 end
  if not comp(ary[1] * mul, x) then return 1 end
  if comp(ary[num] * mul, x) then return num + 1 end
  local min, max = 1, num
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if comp(ary[mid] * mul, x) then
      min = mid
    else
      max = mid
    end
  end
  return max
end
local function upper_bound(ary, left, x, mul)
  local num = #ary
  if num == 0 then return 1 end
  if comp(x, ary[left] * mul) then return left end
  if not comp(x, ary[num] * mul) then return num + 1 end
  local min, max = left, num
  while 1 < max - min do
    local mid = mfl((min + max) / 2)
    if not comp(x, ary[mid] * mul) then
      min = mid
    else
      max = mid
    end
  end
  return max
end

local n, k = io.read("*n", "*n")
local t = {}
for i = 1, n do
  t[i] = 0LL + io.read("*n")
end
table.sort(t)
local plus_start_pos = n + 1
local minus, plus = {}, {}
for i = n, 1, -1 do
  if t[i] < 0 then
    table.insert(minus, -t[i])
  else
    table.insert(plus, t[i])
    plus_start_pos = i
  end
end
table.sort(minus)
table.sort(plus)
local ten9 = 1000000000LL
local minus_cnt = #minus * #plus
if k <= minus_cnt then
  local function solve(x)
    x = -x
    local cnt = 0
    for i = 1, #minus do
      local z = lower_bound(plus, x, minus[i])
      cnt = cnt + (#plus + 1 - z)
    end
    return k <= cnt
  end
  local max = 1LL
  local min = -ten9 * ten9 - 1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solve(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
else
  k = k - minus_cnt
  local function solveA(x)
    local cnt = 0
    for i = 1, #minus - 1 do
      local z = upper_bound(minus, i + 1, x, minus[i]) - 1
      cnt = cnt + (z - i)
    end
    for i = 1, #plus - 1 do
      local z = upper_bound(plus, i + 1, x, plus[i]) - 1
      cnt = cnt + (z - i)
    end
    return k <= cnt
  end
  local max = ten9 * ten9 + 1LL
  local min = -1LL
  while 1LL < max - min do
    local mid = (min + max) / 2LL
    if solveA(mid) then
      max = mid
    else
      min = mid
    end
  end
  local str = tostring(max):gsub("LL", "")
  print(str)
end


local arr = {}
local arr_temp = io.read()
for token in string.gmatch(arr_temp, "[^%s]+") do
   arr[#arr + 1] = tonumber(token)
end
local a, b = arr[1], arr[2]

if a <= 9 and b <= 9 then
	print(a * b)
else
	print(-1)
end

Score : 100 points

Problem Statement

Having learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together. He cannot do any other calculation.

Given are two integers A and B.

If Takahashi can calculate A \times B, print the result; if he cannot, print -1 instead.

Constraints

1 \leq A \leq 20

1 \leq B \leq 20

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B

Output

If Takahashi can calculate A \times B, print the result; if he cannot, print -1.

Sample Input 1

2 5

Sample Output 1

10

2 \times 5 = 10.

Sample Input 2

5 10

Sample Output 2

-1

5\times 10 = 50, but Takahashi cannot do this calculation, so print -1 instead.

Sample Input 3

9 9

Sample Output 3

81


local arr = {}
local arr_temp = io.read()
for token in string.gmatch(arr_temp, "[^%s]+") do
   arr[#arr + 1] = token
end
local a, b = arr[1], arr[2]

if a <= 9 and b <= 9 then
	print(a * b)
else
	print(-1)
end


local arr = {}
local arr_temp = io.read()
for token in string.gmatch(arr_temp, "[^%s]+") do
   arr[#arr] = token
end
local a, b = arr[1], arr[2]

if a <= 9 and b <= 9 then
	print(a * b)
else
	print(-1)
end


local arr = {}
local arr_temp = io.read()
for token in string.gmatch(arr_temp, "[^%s]+") do
   arr[#arr_i] = token
end
local a, b = arr[1], arr[2]

if a <= 9 and b <= 9 then
	print(a * b)
else
	print(-1)
end


local a, b = io.read("*n", "*n", "*l")
if a <= 9 and b <= 9 then
	print(a * b)
else
	print(-1)
end


local a = io.read("*n")
local b = io.read("*n")
io.read()
if a <= 9 and b <= 9 then
	print(a * b)
else
	print(-1)
end


A=io.read"*n"
B=io.read"*n"
print((
	A<=9 and B<=9
)and A*B or -1)


a,b=io.read("*n","*n")
if a<10 and b<10 then
  print(a*b)
else
  print(-1)
end


local a,b,x=io.read("*n","*n","*n")
if a*a*b/2<=x then
  print(math.atan(2*(a*a*b-x)/(a*a*a))*180/math.pi)
else
  print((math.pi/2 - math.atan(2*x/(a*b*b)))*180/math.pi)
end


local n=io.read("*n")
for i=1,9 do
  for j=1,9 do
    if i*j==n then
      return print("Yes")
    end
  end
end
print("No")


local a,b=io.read("*n","*n")
if a>9 or b>9 then
  print(-1)
else
  print(a*b)
end


local a, b = io.read("*n", "*n")
if a > 9 or b > 9 then
	print(-1)
else
	print(a * b)
end


local a,b,c,d = io.read(1,1,1,1)
if b == ' ' and d == '\n' then
    print(math.floor(a*c))
else
    print(-1)
end


    n=io.read("*n")

    ans=n-1

    for i=2, 9 do
      if n%i==0 then
        ans=(n/i)+i-2
      end
    end

	print(ans)


    a=io.read("*n")
    b=io.read("*n")

    if a < 10 and b < 10 then
      print(a*b)
    else
      print(-1)
    end


local s = io.read()
local k = io.read("*n")
local t = {}
local left = 1
for i = 2, #s do
  if s:byte(i) ~= s:byte(left) then
    table.insert(t, i - left)
    left = i
  end
end
table.insert(t, #s + 1 - left)
if #t == 1 then
  local tot = k * #s
  print(tot // 2)
elseif s:byte(1, 1) == s:byte(#s, #s) then
  local first = t[1]
  local last = t[#t]
  local ret = 0
  for i = 2, #t - 1 do
    ret = ret + t[i] // 2
  end
  ret = ret * k + first // 2 + last // 2
  ret = ret + ((first + last) // 2) * (k - 1)
  print(ret)
else
  local ret = 0
  for i = 1, #t do
    ret = ret + t[i] // 2
  end
  print(ret * k)
end

Score : 300 points

Problem Statement

Given is a string S. Let T be the concatenation of K copies of S.
We can repeatedly perform the following operation: choose a character in T and replace it with a different character.
Find the minimum number of operations required to satisfy the following condition: any two adjacent characters in T are different.

Constraints

1 \leq |S| \leq 100

S consists of lowercase English letters.

1 \leq K \leq 10^9

K is an integer.

Input

Input is given from Standard Input in the following format:

S
K

Output

Print the minimum number of operations required.

Sample Input 1

issii
2

Sample Output 1

4

T is issiiissii. For example, we can rewrite it into ispiqisyhi, and now any two adjacent characters are different.

Sample Input 2

qq
81

Sample Output 2

81

Sample Input 3

cooooooooonteeeeeeeeeest
999993333

Sample Output 3

8999939997


local s=io.read()
local k=io.read("n")

local t={}
for i=1,#s do
    t[i]=s:sub(i,i)
end

local a=0
local b=0
if t[1]==t[#s] then
    for i=1,#s do
        a=a+1
        if t[i]~=t[i+1] then
            break
        end
    end
    for i=#s,1,-1 do
        b=b+1
        if t[i]~=t[i-1] then
            break
        end
    end
end

local c=0
for i=1,#s-1 do
    if t[i]==t[i+1] then
        t[i+1]=0
        c=c+1
    end
end

if a==#s then
    print(#s*k//2)
elseif a==0 then
    print(c*k)
else
    print(c*k-(a//2+b//2-(a+b)//2)*(k-1))
end


local s=io.read()
local k=io.read("n")

local t={}
for i=1,#s do
    t[i]=s:sub(i,i)
end

local a=0
local b=0
if t[1]==t[#s] then
    for i=1,#s do
        a=a+1
        if t[i]~=t[i+1] then
            break
        end
    end
    for i=#s,1,-1 do
        b=b+1
        if t[i]~=t[i-1] then
            break
        end
    end
end

local c=0
for i=1,#s-1 do
    if t[i]==t[i+1] then
        t[i+1]=0
        c=c+1
    end
end

if a==#s or a==0 then
    print(c*k)
else
    print(c*k-(a//2+b//2-(a+b)//2)*(k-1))
end


local s=io.read()
local k=io.read("n")

local t={}
for i=1,#s do
    t[i]=s:sub(i,i)
end

local a=0
local b=0
if t[1]==t[#s] then
    for i=1,#s-1 do
        a=a+1
        if t[i]~=t[i+1] then
            break
        end
    end
    for i=#s,2,-1 do
        b=b+1
        if t[i]~=t[i-1] then
            break
        end
    end
end

local c=0
for i=1,#s-1 do
    if t[i]==t[i+1] then
        t[i+1]=0
        c=c+1
    end
end

if a==#s or a==0 then
    print(c*k)
else
    print(c*k-(a//2+b//2-(a+b)//2)*(k-1))
end


local s=io.read()
local k=io.read("n")

local t={}
for i=1,#s do
    t[i]=s:sub(i,i)
end
t[#s+1]=s:sub(1,1)

local counter=0
for i=1,#s do
    if t[i]==t[i+1] then
        t[i+1]=0
        counter=counter+1
    end
end
print(counter*k)


local s = io.read()
local k = io.read("*n")
local n = #s
s = s .. s
local t = {}
for i = 1, 2 * n do
  t[i] = s:sub(i, i)
end
local spos = 1
for i = 1, n - 1 do
  if t[i] ~= t[i + 1] then
    spos = i + 1
    break
  end
end
if spos == 1 then
  print(math.floor(n * k / 2))
else
  local edgelen = spos - 1
  local epos = n
  local ecnt = 0
  for i = n, 1, -1 do
    if t[1] == t[i] then
      ecnt = ecnt + 1
    else
      epos = i
      break
    end
  end
  edgelen = edgelen + ecnt
  local intcost = 0
  local len = 1
  for i = spos + 1, epos do
    if t[i] == t[i - 1] then
      len = len + 1
      if len % 2 == 0 then
        intcost = intcost + 1
      end
    else
      len = 1
    end
    -- print(i, len)
  end
  local edgecost = math.floor(edgelen / 2)
  -- print(intcost)
  -- print(intcost * k + edgecost * (k - 1))
  -- print(edgecost)
  -- print(intcost * k, edgecost * (k - 1),  math.floor((spos - 1) / 2) , math.floor(ecnt / 2))
  print(intcost * k + edgecost * (k - 1) + math.floor((spos - 1) / 2) + math.floor(ecnt / 2))
end
--  8999939997
-- 11999919996


local s = io.read()
local k = io.read("*n")
local n = #s
s = s .. s
local t = {}
for i = 1, 2 * n do
  t[i] = s:sub(i, i)
end
local spos = 1
for i = 1, n - 1 do
  if t[i] ~= t[i + 1] then
    spos = i + 1
    break
  end
end
if spos == 1 then
  print(math.floor(n * k / 2))
else
  local edgelen = spos - 1
  local epos = n
  local ecnt = 0
  for i = n, 1, -1 do
    if t[1] == t[i] then
      ecnt = ecnt + 1
    else
      epos = i
      break
    end
  end
  edgelen = edgelen + ecnt
  local intcost = 0
  local len = 1
  for i = spos + 1, epos do
    if t[i] == t[i - 1] then
      len = len + 1
      if len % 2 == 0 then
        intcost = intcost + 1
      end
    else
      len = 1
    end
    -- print(i, len)
  end
  local edgecost = math.floor(len / 2)
  -- print(intcost)
  -- print(intcost * k + edgecost * (k - 1))
  print(intcost * k + edgecost * (k - 1) + math.floor((spos - 1) / 2) + math.floor(ecnt / 2))
end
--  8999939997
-- 11999919996


local function meld(a,b)
    if not a then
        return b
    elseif not b then
        return a
    elseif a[1]<b[1] then
        b[4]=a[3]
        a[3]=b
        return a
    else
        a[4]=b[3]
        b[3]=a
        return b
    end
end

local function pair(a,d)
    local b=a and a[4]
    if b then
        local c=b[4]
        a=meld(a,b)
        a[4]=d
        d=a
        return pair(c,d)
    else
        local e
        while d do
            e=d
            d=d[4]
            a=meld(a,e)
        end
        return a
    end
end

local PairingHeap={}

PairingHeap.empty=function(self)
    return not self[1]
end

PairingHeap.push=function(self,key,value)
    self[1]=meld(self[1],{key,value,false,false})
end

PairingHeap.top=function(self)
    return self[1][2]
end

PairingHeap.pop=function(self)
    self[1]=pair(self[1][3],false)
end

PairingHeap.join=function(self,other)
    self[1]=meld(self[1],other[1])
    return self
end

PairingHeap.new=function(self)
    local obj={false}
    setmetatable(obj,{__index=PairingHeap})
    return obj
end

----------

local n,m=io.read("n","n")
local a=PairingHeap:new()
for i=1,n do
    local input=io.read("n")
    a:push(-input,input)
end

for i=1,m do
    local x=a:top()
    x=(x//2)
    a:pop()
    a:push(-x,x)
end

local total=0
for i=1,n do
    total=total+a:top()
    a:pop()
end
print(total)

Score : 400 points

Problem Statement

Takahashi is going to buy N items one by one.

The price of the i-th item he buys is A_i yen (the currency of Japan).

He has M discount tickets, and he can use any number of them when buying an item.

If Y tickets are used when buying an item priced X yen, he can get the item for \frac{X}{2^Y} (rounded down to the nearest integer) yen.

What is the minimum amount of money required to buy all the items?

Constraints

All values in input are integers.

1 \leq N, M \leq 10^5

1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N M
A_1 A_2 ... A_N

Output

Print the minimum amount of money required to buy all the items.

Sample Input 1

3 3
2 13 8

Sample Output 1

9

We can buy all the items for 9 yen, as follows:

Buy the 1-st item for 2 yen without tickets.

Buy the 2-nd item for 3 yen with 2 tickets.

Buy the 3-rd item for 4 yen with 1 ticket.

Sample Input 2

4 4
1 9 3 5

Sample Output 2

6

Sample Input 3

1 100000
1000000000

Sample Output 3

0

We can buy the item priced 1000000000 yen for 0 yen with 100000 tickets.

Sample Input 4

10 1
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

Sample Output 4

9500000000


local function meld(a,b)
    if not a then
        return b
    elseif not b then
        return a
    elseif a[1]<b[1] then
        b[4]=a[3]
        a[3]=b
        return a
    else
        a[4]=b[3]
        b[3]=a
        return b
    end
end

local function pair(a,d)
    local b=a and a[4]
    if b then
        local c=b[4]
        a=meld(a,b)
        a[4]=d
        d=a
        return pair(c,d)
    else
        local e
        while d do
            e=d
            d=d[4]
            a=meld(a,e)
        end
        return a
    end
end

local PairingHeap={}

PairingHeap.empty=function(self)
    return not self[1]
end

PairingHeap.push=function(self,key,value)
    self[1]=meld(self[1],{key,value,false,false})
end

PairingHeap.top=function(self)
    return self[1][2]
end

PairingHeap.pop=function(self)
    self[1]=pair(self[1][3],false)
end

PairingHeap.join=function(self,other)
    self[1]=meld(self[1],other[1])
    return self
end

PairingHeap.new=function(self)
    local obj={false}
    setmetatable(obj,{__index=PairingHeap})
    return obj
end

----------

local n,m=io.read("n","n")
local a=PairingHeap:new()
for i=1,n do
    local input=io.read("n")
    a:push(-input,input)
end

for i=1,m do
    local x=a:top()
    x=math.floor(x/2)
    a:pop()
    a:push(-x,x)
end

local total=0
for i=1,n do
    total=total+a:top()
    a:pop()
end
print(string.format("%d",total))


local function meld(a,b)
    if not a then
        return b
    elseif not b then
        return a
    elseif a[1]<b[1] then
        b[4]=a[3]
        a[3]=b
        return a
    else
        a[4]=b[3]
        b[3]=a
        return b
    end
end

local function pair(a)
    local b,c,d,e
    while a do
        c=false
        b=a
        a=a[4]
        b[4]=false
        if a then
            c=a
            a=a[4]
            c[4]=false
        end
        b=meld(b,c)
        b[4]=d
        d=b
    end
    while d do
        e=d
        d=d[4]
        a=meld(a,e)
    end
    return a
end

local PairingHeap={}

PairingHeap.empty=function(self)
    return not self[1]
end

PairingHeap.push=function(self,key,value)
    self[1]=meld(self[1],{key,value,false,false})
end

PairingHeap.top=function(self)
    return self[1][2]
end

PairingHeap.pop=function(self)
    self[1]=pair(self[1][3])
end

PairingHeap.join=function(self,other)
    if self[1][1]<other[1][1]then
		other[1][4]=self[1][3]
        self[1][3]=other[1]
	else
		self[1][4]=other[1][3]
        other[1][3]=self[1]
        self[1]=other[1]
    end
    return self
end

PairingHeap.new=function(self)
    local obj={}
    setmetatable(obj,{__index=PairingHeap})
    return obj
end

----------

local n,m=io.read("n","n")
local a=PairingHeap:new()
for i=1,n do
    local input=io.read("n")
    a:push(-input,input)
end

for i=1,m do
    local x=a:top()
    x=math.floor(x/2)
    a:pop()
    a:push(-x,x)
end

local total=0
for i=1,n do
    total=total+a:top()
    a:pop()
end
print(string.format("%d",total))


local function meld(a,b)
    if not a then
        return b
    elseif not b then
        return a
    elseif a[1]<b[1] then
        b[4]=a[3]
        a[3]=b
        return a
    else
        a[4]=b[3]
        b[3]=a
        return b
    end
end

local function pair(a)
    local b,c,d,e
    while a do
        c=false
        b=a
        a=a[4]
        b[4]=false
        if a then
            c=a
            a=a[4]
            c[4]=false
        end
        b=meld(b,c)
        b[4]=d
        d=b
    end
    while d do
        e=d
        d=d[4]
        a=meld(a,e)
    end
    return a
end

local PairingHeap={}

PairingHeap.empty=function(self)
    return not self[1]
end

PairingHeap.push=function(self,key,value)
    self[1]=meld(self[1],{key,value,false,false})
end

PairingHeap.top=function(self)
    return self[1][2]
end

PairingHeap.pop=function(self)
    self[1]=pair(self[1][3])
end

PairingHeap.join=function(self,other)
    if self[1][1]<other[1][1]then
		other[1][4]=self[1][3]
        self[1][3]=other[1]
	else
		self[1][4]=other[1][3]
        other[1][3]=self[1]
        self[1]=other[1]
    end
    return self
end

PairingHeap.new=function(self)
    local obj={}
    setmetatable(obj,{__index=PairingHeap})
    return obj
end

----------

local n,m=io.read("n","n")
local a=PairingHeap:new()
for i=1,n do
    local input=io.read("n")
    a:push(-input,input)
end

for i=1,m do
    local x=a:top()
    x=(x//2)
    a:pop()
    a:push(-x,x)
end

local total=0
for i=1,n do
    total=total+a:top()
    a:pop()
end
print(total)