#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def jo(n,d)
  return n if(d == 1)
  a = jo(n,d/2)
  return a if(a > 100000)
  return a * jo(n,d-d/2)
  return jo(n,d/2) * jo(n,d-d/2)
end

require 'prime'

trr = Hash.new(0)

n,k = inp
t = inp
per = 0
ans = 0
t.each.with_index do |d,i|
  f = true
  tt = d.prime_division
  ttt = 1
  tttttt = 1
  f = false
  tt.each.with_index do |a,i|
    r = a[1]%k
    next if r == 0
    ttt *= jo(a[0],r)
    tttttt *= jo(a[0],(k-r))
    if(tttttt > 100000)
      f = true
      break
    end
  end
  next if f
  ans += trr[tttttt]
  trr[ttt] += 1
end

p ans

#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def jo(n,d)
  return n if(d == 1)
  return jo(n,d/2) * jo(n,d-d/2)
end

require 'prime'

trr = Hash.new(0)

n,k = inp
t = inp
per = 0
ans = 0
hh = {}
t.each.with_index do |d,i|
  f = true
  tt = d.prime_division
  ttt = 1
  tttttt = 1
  f = false
  tt.each.with_index do |a,i|
    r = a[1]%k
    if(hh[a[0]] == true)
      f = true
      break
    elsif(hh[a[0]] == nil)
      hh[a[0]] = (jo(a[0],k) > 100000)
      f = hh[a[0]]
      break if f
    end
    next if r == 0
    ttt *= jo(a[0],r)
    tttttt *= jo(a[0],(k-r))
  end
  next if f == true
  ans += trr[tttttt]
  trr[ttt] += 1
end

p ans

#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

require 'prime'

h = Hash.new(0)

n,k = inp
t = inp
tf = na(n,false)
per = 0
t.each.with_index do |d,i|
  f = true
  tt = d.prime_division
  ttt = []
  tt.each.with_index do |a,i|
    f = false if a[1]%k != 0
    ttt << [a[0],a[1]%k] if a[1]%k != 0
  end
  if f
    tf[i] = true
    per += 1
  end
  h[ttt] += 1
end
ans = 0

t.each.with_index do |d,i|
  if tf[i]
    per -= 1
    ans += per
  else
    tt = d.prime_division
    h[tt] -= 1
    ttt = []
    tt.each do |a|
      ttt << [a[0],k-a[1]%k]
    end
    ans += h[ttt]
  end
end

p ans

#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

require 'prime'

h = Hash.new(0)

n,k = inp
t = inp
tf = na(n,false)
per = 0
t.each.with_index do |d,i|
  f = true
  tt = d.prime_division
  ttt = []
  tt.each.with_index do |a,i|
    f = false if a[1] != k
    ttt << a if a[1]%3 != 0
  end
  if f
    tf[i] = true
    per += 1
  end
  h[ttt] += 1
end
ans = 0
t.each.with_index do |d,i|
  if tf[i]
    per -= 1
    ans += per
  else
    tt = d.prime_division
    h[tt] -= 1
    ttt = []
    tt.each do |a|
      ttt << [a[0],k-a[1]%3]
    end
    ans += h[ttt]
  end
end

p ans


n=gets.to_i
a=gets.split.map &:to_i
x=a.min
res=n+1
l=-n, r=-n
a.each_with_index{|e, i|
    next if e!=x
    if r<0
        r=i
    else
        l=r
        r=i
        res=r-l if res>r-l
    end
}
puts res

n,*a=$<.read.split.map &:to_i
b=[]
m=1<<30
a.each_with_index{|e,i|(b=[];m=e)if m>e;b<<i if m==e}
p b.each_cons(2).map{|x,y|y-x}.min


def run
  n, k = ARGF.readline.split.map(&:to_i)
  if k * 3 > n
    puts "-1"
  else
    ret = []
    n.times do |i|
      if i < k * 2
        ret << (i / 2) + 1
      else
        ret << (i % k) + 1
      end
    end
    puts ret.join(" ")
  end
end

run if $0 == __FILE__

n, k = gets.split.map &:to_i

if n < 3*k
	puts -1
	exit
end

t = 1
for i in 1..k
	print t.to_s + " " + t.to_s + " "
	t+=1
end

t=1
for i in 1..k
	print t.to_s + " "
	t+=1
end

for i in 1..(n-3*k)
	print 1, " "
end

#!/usr/bin/ruby1.9

n, k = STDIN.readline.split.collect {|s| s.to_i }
if 3*k > n
	puts -1
	exit
end

keepers = (1..k).collect {|x| x }
assignments = []
(1..k).each do |i|
	assignments.push(i)
	assignments.push(i)
end
(2*k..n-1).each do |i|
	assignments.push(keepers[i%k])
end
puts assignments.join(' ')

n, k = gets.split(' ').collect!{|i| i.to_i}

# def arifm?(arr)
# 	result = true
# 	arr.each_index do |i|
# 		if i < arr.length - 3
# 			result = false if !arr[i+1] - arr[i] == arr[i+2] - arr[i+1]
# 		end
# 	end
# 	return result
# end

# p arifm?([1, 5, 9])

if 3*k > n
	p -1
else
	mydr = Array.new(k)
	mydr.each_index do |i|
		mydr[i] = i % k + 1
	end
	# p mydr
	ans = Array.new(n)
	rot = false
	j = 0
	n.times do |i|
		if i < 2*k
			ans[i] = mydr[j]
			j += 1 if rot
			rot = !rot
			j = 0 if j > k-1
		else
			ans[i] = mydr[i % k]
		end
	end

	print ans.join(' ')
	# print "\n"
end

#!/usr/bin/ruby1.9

n, k = STDIN.readline.split.collect {|s| s.to_i }
if 3*k > n
	puts -1
	exit
end

keepers = (1..k).collect {|x| x }
assignments = []
keeper_ix = 0
(1..n).each do |pos|
	assignments.push(keepers[keeper_ix])
	keeper_ix += 1
	if keeper_ix == keepers.length
		keepers = keepers.rotate
		keeper_ix = 0
	end
end
puts assignments.join(' ')

def run
  n, k = ARGF.readline.split.map(&:to_i)
  if k * 3 > n
    puts "-1"
  else
    ret = []
    for i in 0..n
      if i < k * 2
        ret << (i / 2) + 1
      else
        ret << (i % k) + 1
      end
    end
    puts ret.join(" ")
  end
end

run if $0 == __FILE__

n, k = gets.split(' ').collect!{|i| i.to_i}

# def arifm?(arr)
# 	result = true
# 	arr.each_index do |i|
# 		if i < arr.length - 3
# 			result = false if !arr[i+1] - arr[i] == arr[i+2] - arr[i+1]
# 		end
# 	end
# 	return result
# end

# p arifm?([1, 5, 9])

if n / 3.0 < k
	p -1
else
	ans = Array.new(n)

	n.times do |i|
		if i < k
			ans[i] = k - i
		elsif i < 2*k
			ans[i] = i % k + 1
		elsif i < 3*k
			ans[i] = 3*k - i
		else
			ans[i] = i % k + 1
		end
	end

	print ans.join(' ')
	# print "\n"
end

n, k = gets.split(' ').collect!{|i| i.to_i}

# def arifm?(arr)
# 	result = true
# 	arr.each_index do |i|
# 		if i < arr.length - 3
# 			result = false if !arr[i+1] - arr[i] == arr[i+2] - arr[i+1]
# 		end
# 	end
# 	return result
# end

# p arifm?([1, 5, 9])

if n / 3.0 < k
	p -1
else
	mydr = Array.new(k)
	mydr.each_index do |i|
		mydr[i] = i % k + 1
	end
	mydr.rotate!
	# p mydr
	ans = Array.new(n)

	n.times do |i|
		if i < k
			ans[i] = k - i
		elsif i < 2*k
			ans[i] = i % k + 1
		# elsif i < 3*k
		# 	ans[i] = 3*k - i
		else
			ans[i] = mydr[i % k]
		end
	end

	print ans.join(' ')
	# print "\n"
end

n, k = gets.split(' ').collect!{|i| i.to_i}

# def arifm?(arr)
# 	result = true
# 	arr.each_index do |i|
# 		if i < arr.length - 3
# 			result = false if !arr[i+1] - arr[i] == arr[i+2] - arr[i+1]
# 		end
# 	end
# 	return result
# end

# p arifm?([1, 5, 9])

if n / 3.0 < k
	p -1
else
	ans = Array.new(n)

	n.times do |i|
		if i < k
			ans[i] = k - i
		else
			ans[i] = i % k + 1
		end

	end

	print ans.join(' ')
	# print "\n"
end

n, k = gets.split(' ').collect!{|i| i.to_i}

# def arifm?(arr)
# 	result = true
# 	arr.each_index do |i|
# 		if i < arr.length - 3
# 			result = false if !arr[i+1] - arr[i] == arr[i+2] - arr[i+1]
# 		end
# 	end
# 	return result
# end

# p arifm?([1, 5, 9])

if 3*k > n
	p -1
else
	mydr = Array.new(k)
	mydr.each_index do |i|
		mydr[i] = i % k + 1
	end
	p mydr
	ans = Array.new(n)
	rot = false
	j = 0
	n.times do |i|
		if i < 2*k
			ans[i] = mydr[j]
			j += 1 if rot
			rot = !rot
			j = 0 if j > k-1
		else
			ans[i] = mydr[i % k]
		end
	end

	print ans.join(' ')
	# print "\n"
end

n, k = gets.split(' ').collect!{|i| i.to_i}

# def arifm?(arr)
# 	result = true
# 	arr.each_index do |i|
# 		if i < arr.length - 3
# 			result = false if !arr[i+1] - arr[i] == arr[i+2] - arr[i+1]
# 		end
# 	end
# 	return result
# end

# p arifm?([1, 5, 9])

if n / 3.0 < k
	p -1
else
	mydr = Array.new(k)
	mydr.each_index do |i|
		mydr[i] = i % k + 1
	end
	mydr.rotate!
	# p mydr
	ans = Array.new(n)
	rot = false
	rot2 = false
	n.times do |i|
		if i < k
			ans[i] = k - i
		elsif i < 2*k
			ans[i] = i % k + 1
		elsif i < 3*k
			ans[i] = mydr[i % k]
		elsif i < 4*k
			ans[i] = i % k + 1
		elsif i < 5*k
			if !rot
				mydr.rotate!
				rot = true
			end
			ans[i] = mydr[i % k]
		else
			if !rot2
				mydr.rotate!.reverse!
				rot2 = true
			end
			ans[i] = mydr[i % k]
		end
	end

	print ans.join(' ')
	# print "\n"
end

n, k = gets.split(' ').collect!{|i| i.to_i}

# def arifm?(arr)
# 	result = true
# 	arr.each_index do |i|
# 		if i < arr.length - 3
# 			result = false if !arr[i+1] - arr[i] == arr[i+2] - arr[i+1]
# 		end
# 	end
# 	return result
# end

# p arifm?([1, 5, 9])

if n / 3.0 < k
	p -1
else
	mydr = Array.new(k)
	mydr.each_index do |i|
		mydr[i] = i % k + 1
	end
	mydr.rotate!
	# p mydr
	ans = Array.new(n)
	rot = false
	rot2 = false
	n.times do |i|
		if i < k
			ans[i] = k - i
		elsif i < 2*k
			ans[i] = i % k + 1
		elsif i < 100*k
			ans[i] = mydr[i % k]
		elsif i < 1000*k
			ans[i] = i % k + 1
		elsif i < 10000*k
			if !rot
				mydr.rotate!
				rot = true
			end
			ans[i] = mydr[i % k]
		else
			if !rot2
				mydr.rotate!
				rot2 = true
			end
			ans[i] = mydr[i % k]
		end
	end

	print ans.join(' ')
	# print "\n"
end

n, k = gets.split(' ').collect!{|i| i.to_i}

# def arifm?(arr)
# 	result = true
# 	arr.each_index do |i|
# 		if i < arr.length - 3
# 			result = false if !arr[i+1] - arr[i] == arr[i+2] - arr[i+1]
# 		end
# 	end
# 	return result
# end

# p arifm?([1, 5, 9])

if n / 3.0 < k
	p -1
else
	mydr = Array.new(k)
	mydr.each_index do |i|
		mydr[i] = i % k + 1
	end
	mydr.rotate!
	# p mydr
	ans = Array.new(n)
	rot = false
	rot2 = false
	n.times do |i|
		if i < k
			ans[i] = k - i
		elsif i < 2*k
			ans[i] = i % k + 1
		elsif i < 100*k
			ans[i] = mydr[i % k]
		elsif i < 1000*k
			ans[i] = i % k + 1
		elsif i < 10000*k
			if !rot
				mydr.rotate!
				rot = true
			end
			ans[i] = mydr[i % k]
		else
			if !rot2
				mydr.rotate!.reverse!
				rot2 = true
			end
			ans[i] = mydr[i % k]
		end
	end

	print ans.join(' ')
	# print "\n"
end

n, k = gets.split(' ').collect!{|i| i.to_i}

# def arifm?(arr)
# 	result = true
# 	arr.each_index do |i|
# 		if i < arr.length - 3
# 			result = false if !arr[i+1] - arr[i] == arr[i+2] - arr[i+1]
# 		end
# 	end
# 	return result
# end

# p arifm?([1, 5, 9])

if n / 3.0 < k
	p -1
else
	mydr = Array.new(k)
	mydr.each_index do |i|
		mydr[i] = i % k + 1
	end
	mydr.rotate!
	# p mydr
	ans = Array.new(n)
	rot = false
	n.times do |i|
		if i < k
			ans[i] = k - i
		elsif i < 2*k
			ans[i] = i % k + 1
		elsif i < 100*k
			ans[i] = mydr[i % k]
		elsif i < 1000*k
			ans[i] = i % k + 1
		else
			if !rot
				mydr.rotate!
				rot = true
			end
			ans[i] = mydr[i % k]
		end
	end

	print ans.join(' ')
	# print "\n"
end

n, k = gets.split(' ').collect!{|i| i.to_i}

# def arifm?(arr)
# 	result = true
# 	arr.each_index do |i|
# 		if i < arr.length - 3
# 			result = false if !arr[i+1] - arr[i] == arr[i+2] - arr[i+1]
# 		end
# 	end
# 	return result
# end

# p arifm?([1, 5, 9])

if n / 3.0 < k
	p -1
else
	mydr = Array.new(k)
	mydr.each_index do |i|
		mydr[i] = i % k + 1
	end
	mydr.rotate!
	# p mydr
	ans = Array.new(n)
	rot = false
	n.times do |i|
		if i < k
			ans[i] = mydr[i % k]
		elsif i < 2*k
			ans[i] = i % k + 1
		elsif i < 3*k
			if !rot
				mydr.reverse!
				rot = true
			end
			ans[i] = mydr[i % k]
		elsif i < 4*k
			ans[i] = i % k + 1
		elsif i < 5*k
			if rot
				mydr.rotate!
				rot = false
			end
			ans[i] = mydr[i % k]
		else
			if !rot
				mydr.rotate!.reverse!
				rot = true
			end
			ans[i] = mydr[i % k]
		end
	end

	print ans.join(' ')
	# print "\n"
end

n, k = gets.split(' ').collect!{|i| i.to_i}

# def arifm?(arr)
# 	result = true
# 	arr.each_index do |i|
# 		if i < arr.length - 3
# 			result = false if !arr[i+1] - arr[i] == arr[i+2] - arr[i+1]
# 		end
# 	end
# 	return result
# end

# p arifm?([1, 5, 9])

if n / 3.0 < k
	p -1
else
	mydr = Array.new(k)
	mydr.each_index do |i|
		mydr[i] = i % k + 1
	end
	mydr.rotate!
	# p mydr
	ans = Array.new(n)
	rot = false
	n.times do |i|
		if i < k
			ans[i] = k - i
		elsif i < 2*k
			ans[i] = i % k + 1
		elsif i < 3*k
			if !rot
				mydr.rotate!.reverse!
				rot = true
			end
			ans[i] = mydr[i % k]
		else
			if rot
				mydr.rotate!.reverse!
				rot = false
			end
			ans[i] = mydr[i % k]
		end
	end

	print ans.join(' ')
	# print "\n"
end

n, k = gets.split.map &:to_i

if n < 3*k
	puts -1
	exit
end

t = 1
for i in 1..k
	print t.to_s + " " + t.to_s + " "
	t+=1
end

t=1
for i in 1..k
	print t.to_s + " "
	t+=1
end

for i in 1..(n-k)
	print 1, " "
end


n = gets.to_i
m = n/2+1
puts m
(1..m).each do |i|
    puts "#{1} #{i}"
end
(2..m).each do |i|
    puts "#{m} #{i}" if n.odd? || i < m
end

def lscan;gets.split.map(&:to_i);end

n = gets.to_i

w = n / 2 + 1

p w
x = 1
y = 1
vx = 1
vy = 0
n.times do |i|
  puts "#{x} #{y}"
  x += vx
  y += vy
  if x > w
    x -= vx
    y -= vy
    vx,vy = vy,vx
    x += vx
    y += vy
  end
end


# f = File.open 'input.txt', 'r'
f = STDIN

def fuzzy_equal?(a, b)
  a == b || a - 1 == b
end

def find_pairs(sticks)
  marked_indices = []
  start_idx = 0
  sticks.each_with_index do |item, idx|
    next if idx < start_idx
    break if idx >= sticks.length - 1
    if fuzzy_equal?(item, sticks[idx + 1])
      start_idx = idx + 2
      marked_indices << sticks[idx + 1]
    end
  end
  marked_indices
end

def area(width, height)
  width * height
end

def total_areas(marked_indices)
  total_area = 0

  marked_indices.each_with_index do |item, idx|
    next if idx % 2 == 0
    total_area += area item, marked_indices[idx - 1]
  end
  total_area
end

def compute(n, sticks)
  marked_indices = find_pairs sticks
  total_areas marked_indices
end

while true
  raw_n = f.gets
  break unless raw_n
  n = raw_n.chomp.to_i
  sticks = f.gets.chomp.split.map &:to_i
  desc_sticks = sticks.sort{ |a, b| b <=> a }
  p compute(n, desc_sticks)
end

n=gets.chomp.to_i
a=gets.chomp.split(" ").map{|x| x.to_i}
b=a.sort
i=n-1
x=1
c=0
s=0
while i>=1 do
	if (b[i]==b[i-1])
		x=x*b[i]
		i=i-1
		c=c+1
	else
		if (b[i-1]==b[i]-1)
			x=x*b[i-1]
			i=i-1
			c=c+1
		end
	end
	if c==2
		s=s+x
		x=1
		c=0
	end
i=i-1
end

puts s

gets
a = gets.split.map(&:to_i)

a.sort!

s = 0
t = 0

while a.size > 1
  ta, tb = a[-2..-1]

  if (ta - tb).abs <= 1
    if t == 0
      t = [ta, tb].min
    else
      s += t * [ta, tb].min
      t = 0
    end
    a = a[0..-3]
  else
    a = a[0..-2]
  end
end

puts s

n = gets.to_i
l = Hash.new(0)
ll = Hash.new(0)
gets.split.each{|i| l[i.to_i]+=1}
l = l.sort_by{|key, value| key}.reverse
(0...l.size).each do |i|
    if i > 0 and l[i-1][0] == l[i][0]+1 and l[i-1][1] > 0 and l[i][1] > 0
        ll[l[i][0]] += 1
        l[i-1][1] = 0
        l[i][1] -= 1
    end
    if l[i][1] >= 2
        ll[l[i][0]] += l[i][1]/2
        l[i][1] %= 2
    end
end
ll = ll.sort_by{|key, value| key}.reverse
ans = 0
(0...ll.size).each do |i|
    if ll[i][1] >= 2
        ans += ll[i][1]/2*ll[i][0]*ll[i][0]
        ll[i][1] %= 2
    end
    if ll[i][1] > 0 and i < ll.size-1
        ans += ll[i][0]*ll[i+1][0]
        ll[i][1] = 0
        ll[i+1][1] -= 1
    end
end
puts ans

n = gets.to_i
l = gets.split.map(&:to_i).sort.reverse
ans = 0
a = 0
b = 0
for i in 0...l.size - 1 do
  if l[i] == l[i + 1]
    if a == 0
      a = l[i]
    elsif b == 0
      b = l[i]
      ans += a * b
      a = 0
      b = 0
    end
    l[i] = 0
    l[i + 1] = 0
  elsif l[i] == l[i + 1] + 1
    if a == 0
      a = l[i + 1]
    elsif b == 0
      b = l[i + 1]
      ans += a * b
      a = 0
      b = 0
    end
    l[i] = 0
    l[i + 1] = 0
  end
end
puts ans

n=gets.chomp.to_i
a=gets.chomp.split(" ").map{|x| x.to_i}
b=a.sort
i=n-1
f=0
x=[]
y=[]
while i>=1 do
	if (b[i]==b[i-1])
		x<<(b[i])
		i=i-1
	end
	if x.length==2
		f=1
		break
	end
	if (b[i-1]==b[i]-1)
		y<<(b[i-1])
		i=i-1
	end
i=i-1
end
if f==1
puts x[0]*x[1]
else
	if x.length==0
		if y.length>=2
			puts y[0]*y[1]
		else
			puts 0
		end
	else
		if y.length>=1
			puts x[0]*y[0]
		else
			puts 0
		end
	end
end

n=gets.chomp.to_i
a=gets.chomp.split(" ").map{|x| x.to_i}
b=a.sort
i=n-1
x=[]
y=[]
c=0
while i>=1 do
	if (b[i]==b[i-1])
		x<<(b[i])
		i=i-1
		c=c+1
	end
	if (b[i-1]==b[i]-1)
		y<<(b[i-1])
		i=i-1
		c=c+1
	end
	if c==2
		break
	end
i=i-1
end

if c==2
	if x.length==2
	puts x[0]*x[1]
	else
		if y.length==2
		puts y[0]*y[1]
		else
		puts x[0]*y[0]
		end
	end
else
puts 0
end

n = gets.to_i
l = Hash.new(0)
ll = Hash.new(0)
gets.split.each{|i| l[i.to_i]+=1}
l = l.sort_by{|key, value| key}.reverse
(0...l.size).each do |i|
    if l[i][1] >= 2
        ll[l[i][0]] += l[i][1]/2
        l[i][1] %= 2
    end
end
(1...l.size).each do |i|
    if l[i-1][0] == l[i][0]+1 and l[i-1][1] > 0 and l[i][1] > 0
        ll[l[i][0]] += 1
        l[i-1][1] = 0
        l[i][1] = 0
    end
end
ll = ll.sort_by{|key, value| key}.reverse
ans = 0
(0...ll.size).each do |i|
    if ll[i][1] >= 2
        ans += ll[i][1]/2*ll[i][0]*ll[i][0]
        ll[i][1] %= 2
    end
    if ll[i][1] > 0 and i < ll.size-1
        ans += ll[i][0]*ll[i+1][0]
        ll[i][1] = 0
        ll[i+1][1] -= 1
    end
end
puts ans

# f = File.open 'input.txt', 'r'
f = STDIN

def fuzzy_equal?(a, b)
  a == b || a + 1 == b
end

def find_eql_sticks(n, sticks)
  [*0...(n - 1)].rindex{ |idx| fuzzy_equal? sticks[idx], sticks[idx + 1] }
end

def length(idx, sticks)
  idx ? sticks[idx] : 0
end

def area(width_idx, height_idx, sticks)
  length(width_idx, sticks) * length(height_idx, sticks)
end

def compute(n, sticks)
  first_pair_index = find_eql_sticks(n, sticks)
  second_pair_index = find_eql_sticks(first_pair_index, sticks)
  area(first_pair_index, second_pair_index, sticks)
end

while true
  raw_n = f.gets
  break unless raw_n
  n = raw_n.chomp.to_i
  sticks = f.gets.chomp.split.map &:to_i
  sorted_sticks = sticks.sort
  puts compute(n, sorted_sticks)
end


n,k=gets.split.map(&:to_i)
puts k>n ? -1 : "#{gets.split.map(&:to_i).sort[-k]} 0"

n, k = gets.split(' ').map(&:to_i)
ar = gets.split(' ').map(&:to_i).sort
if k<=n
  puts "#{ar[-k]} #{ar[-k]}"
else
  puts -1
end

st = gets.split
n = st[0].to_i
k = st[1].to_i

st = gets.split
quad = []
n.times do |i|
    quad << st[i].to_i
end

quad = quad.sort
if quad[-k] then
    result = quad[-k].to_s + " " + quad[-k].to_s
else
    result = -1
end

puts result

 n,k=gets.split.map(&:to_i)
 a=gets.split.map(&:to_i)
 f=a.find_all{|ch| ch>0}.size
 if f<k and  n-f<k then
 puts -1
 else
   if n==k then
     print 0, " ", 0
     else
       if f <=n-f then
         a.sort!
         else
         a.sort!
         a.reverse!
       end
       print a[k-1]," ", a[k-1]
    end
 end

# -*- encoding: utf-8 -*-

def solve(n, k, points)
  return [- 1] if k > n

  points.sort!

  x = points[n - k]
  y = 0

  return [x, y]
end

n, k = gets.chomp.split(" ").map{|n| n.to_i}
points = gets.chomp.split(" ").map{|n| n.to_i}

puts solve(n, k, points).join(" ")

#!/usr/bin/ruby1.9

n, k = STDIN.readline.split.collect {|s| s.to_i }
as = STDIN.readline.split.collect {|s| s.to_i }
as.sort!
if k > n
	puts -1
	exit
end

ix = n-k
puts '%d %d' % [as[ix], as[ix]]

n, k = gets.split.map(&:to_i)
nums = gets.split.map(&:to_i).sort.reverse
puts n >= k ? "#{nums[k - 1]} #{nums[k - 1]}" : "-1"

def run
  n, k = ARGF.readline.split.map(&:to_i)
  ary = ARGF.readline.split.map(&:to_i).sort

  if ary.length - k >= 0
    puts ary[ary.length - k].to_s + " 0"
  else
    puts "-1"
  end
end

run if $0 == __FILE__

a=gets.chomp.split(" ").map {|i| i.to_i}
b=gets.chomp.split(" ").map {|i| i.to_i}
b.sort!
if a[0]-a[1]>=0
c=b[a[0]-a[1]]
puts "#{c} #{c-1}"
else
puts "-1"
end

n,k=gets.split.map(&:to_i)
p=gets.split.map(&:to_i).sort
print k>n ? -1 : "#{p[-k]} 0"

n,k=gets.split.map(&:to_i)
p=gets.split.map(&:to_i).sort
print ((k>n)? -1 : "#{p[-k]} #{0}")

require 'set'
require 'rational'
require 'mathn'
include Math
$stdin = File.open("./input.txt", "r") if ENV["USER"] == "new"
# ====================================

n, k = gets.split.map(&:to_i)
points = gets.split.map(&:to_i)

# -1
if k > n then
  puts -1
  exit
end

# other
points.sort!
puts "#{points[-k]} #{0}"

n, k = gets.split.map(&:to_i)
p = gets.split.map(&:to_i)
(puts -1) & exit if k>n
print ([p.sort[-k]]*2).join ' '

n,k = gets.split.map &:to_i
if k>n
    p -1
else
    v = []
    v = gets.split.map &:to_i
    v = v.sort
    puts "#{v[n-k]} #{v[n-k]}"
end

n,k=gets.split.map(&:to_i)
a=gets.split.map(&:to_i).sort
puts n<k ? -1 : ([a[n-k]]*2).join(' ')

input = gets.chomp
num = input.split
n = Integer(num[0])
k = Integer(num[1])
input2 = gets.chomp
nums = input2.split
a = Array.new
for i in 0...n
    a[i] = Integer(nums[i])
end

a = a.sort
if n >= k
    print a[n-k], " ", 0
else
    print -1
end

m,k = gets.split.map &:to_i
v = gets.split.map &:to_i
if k>m
    puts "-1"
else
    v = v.sort
    puts v[m-k].to_s+" 0"
end

n,k = gets.split.map &:to_i
v = gets.split.map &:to_i
if k>n
    puts "-1"
else
    v = v.sort
    puts v[n-k].to_s+" 0"
end

x, m = STDIN.readline.split.map(&:to_i)
arr = STDIN.readline.split.map(&:to_i).sort
if arr.size - m >= 0
	print "#{arr[arr.size-m]} #{arr[arr.size-m]}\n"
else
	p -1
end

n,k = gets.chomp.split(" ").collect! {|x| x.to_i}
line = gets.chomp.split(" ").collect! {|x| x.to_i}
line.sort!
if k > n
  puts "-1"
else
puts "#{line[n-k]} #{line[n-k]}"
end

def read_line
  gets.chomp.split.map &:to_i
end

n, k = read_line
a = read_line.sort

if k>n
	puts -1
else
	print a[n-k]
	print ' '
	puts a[n-k]
end

n,k = gets.split.map(&:to_i)
a=gets.split.map(&:to_i).sort.reverse

if k>n
  puts -1
else
  puts "%d %d" % [a[k-1],a[k-1]]
end

n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort
if k > n
  p -1
else
  print a[n-k],' ',a[n-k]
end

n, k = gets.chomp.split.map { |x| x.to_i }
a = gets.chomp.split.map { |x| x.to_i }.sort
puts(k <= n ? "#{a[n - k]} 0" : -1)

n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort
if k > n
    puts(-1)
else
    puts(([a[n - k]] * 2).join(' '))
end

#!/usr/bin/env ruby

n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort.reverse
i, t = 0, 0
while i < n
	c, j = 0, i
	c, j = c + 1, j + 1 while a[j] == a[i]
	t = t + c
	if t == k
		puts "#{a[i]} #{a[i]}"
		exit 0
	end
	i = j
end
puts -1

BEGIN{
	def gint()
		return gets.split.map(&:to_i)
	end
	def main()
		n, k = gint
		a = gint
		a = [0] + a
		a.sort!
		puts -1 if k > n
		return if k > n
		print a[-1] + 1, " ", a[-1] + 1, "\n" if k == 0
		return if k == 0
		p = n - k + 1
		print a[p], " ", a[p], "\n"
	end
	Test_case = 1
	Test_case.times do
		main()
	end
}

t = gets.split.collect{|x| x.to_i}
n = t[0]
k = t[1]

a = gets.split.collect{|x| x.to_i}
a.sort!{|x,y| y <=> x}

x = 10**9

a.each{|ai|
	if k > 0
		x = ai
		k -= 1
	elsif ai == x
		k -= 1
	end
}

if k != 0
	puts -1
else
	print x, ' ', x
end

n,k=gets.split.map(&:to_i)
a=gets.split.map(&:to_i).sort
puts k<n ? ([a[n-k]]*2).join(' ') : -1

n,k = gets.chomp.split(" ").collect! {|x| x.to_i}
line = gets.chomp.split(" ").collect! {|x| x.to_i}
line.sort!
puts "#{line[n-k]} #{line[n-k]}"


N = gets.to_i
vals = STDIN.read.split.map(&:to_i)
firsts = []
seconds = []
first = 0
second = 0
last_player = nil
vals.each{|val|
    if val>0
        first += val
        last_player = "first"
        firsts << val
    else
        second +=  - val
        last_player = "second"
        seconds << - val
    end
}
seq_first = false
seq_second = false

(0...[firsts.size, seconds.size].max).each{|i|
    if(firsts[i].to_i > seconds[i].to_i)
        seq_first = true
        break
    elsif(firsts[i].to_i < seconds[i].to_i)
        seq_second = true
        break
    end
}
# puts "first=#{first}, second=#{second}"
if first > second then
    puts "first"
    exit 0
elsif second > first then
    puts "second"
    exit 0
end
if seq_first then
    puts "first"
    exit 0
elsif seq_second then
    puts "second"
    exit 0
end
puts last_player

# 493B

a_sum = b_sum = 0
a_ary, b_ary = [], []
val = nil
gets.to_i.times {
  val = gets.to_i
  if val > 0
    a_sum += val
    a_ary << val
  else
    b_sum += -val
    b_ary << -val
  end
}
res = if a_sum > b_sum
        true
      elsif a_sum < b_sum
        false
      else
        res = a_ary <=> b_ary
        if res > 0
          true
        elsif res < 0
          false
        else
          val > 0
        end
      end
puts res ? 'first' : 'second'

n = STDIN.readline.to_i
a, b = [], []
last = nil
n.times do
  x = STDIN.readline.to_i
  if x > 0
    a.push(x)
    last = 'first'
  else
    b.push(-x)
    last = 'second'
  end
end

sum_a, sum_b = a.inject(0, :+), b.inject(0, :+)
if sum_a > sum_b
  puts 'first'
  exit
end
if sum_a < sum_b
  puts 'second'
  exit
end

if a == b
  puts last
  exit
end

greater = ([a, b].sort)[1]
if greater == a
  puts 'first'
else
  puts 'second'
end

#! /usr/bin/env ruby
# coding: utf-8

n = gets.to_i

t = nil
a = [[0], [0]]
n.times do
  c = gets.to_i
  t = c < 0 ? 1 : 0
  a[t] << c.abs
  a[t][0] += c.abs
end
a[t] << 1
result = [a[0] ,a[1]].max == a[0] ? "first" : "second"
puts result

n=gets.to_i
ar,br,a,b,flag,i,t=Array.new(200001,0),Array.new(200001,0),0,0,0,0,nil
sumA,sumB=0,0
n.times do
	t=gets.to_i
	if t>0
		sumA+=t
		ar[a]=t
		a+=1
	else
		sumB-=t
		br[b]=-t
		b+=1
	end
end
flag=1 if sumA>sumB
flag=2 if sumB>sumA
if flag==0
	while i<a && i<b
		if ar[i]>br[i]
			flag=1
			break
		elsif br[i]>ar[i]
			flag=2
			break
		end
		i+=1
	end
	if flag==0
		flag = (t>0) ? 1 : 2
	end
end
puts (flag==1) ? "first" : "second"

#! /usr/bin/env ruby
# coding: utf-8

class GameProcess
  def initialize(n)
    @n = n
    @f = Wrestler.new
    @s = Wrestler.new
    @f_w = "first"
    @s_w = "second"
    @last = @f_w
    start
  end

  def start
    if @n == 1
      @last = gets.chomp.to_i < 0 ? @s_w : @f_w
      return
    end
    @n.times do |i|
      p = gets.chomp.to_i
      distribute_point(p)
      @last = 0 < p ? @f_w : @s_w
    end
  end

  def distribute_point(p)
    return @f.get_point(p) if 0 < p
    @s.get_point(-1 * p)
  end

  def result
    f_s = @f.sum_points
    s_s = @s.sum_points
    return @f_w if s_s < f_s
    return @s_w if f_s < s_s
    return lexicographic_order
  end

  def lexicographic_order
    f_l = @f.number_of_point
    s_l = @s.number_of_point
    result = @last
    n = 0
    if f_l < s_l
      n = f_l
    else
      n = s_l
    end
    n.times do |i|
      f_p = @f.point_at(i)
      s_p = @s.point_at(i)
      next if f_p == s_p
      if f_p < s_p
        result = @s_w
        break
      else
        result = @f_w
        break
      end
    end
    return result
  end
end

class Wrestler
  def initialize()
    @sum = 0
    @points = []
  end

  def get_point(p)
    @points << p
    @sum += p
  end

  def point_at(i)
    @points[i]
  end

  def sum_points
    @sum
  end

  def number_of_point
    @points.length
  end
end

gp = GameProcess.new(gets.chomp.to_i)
puts gp.result

l=(1..gets.to_i).map{gets.to_i}
a={true=>[0],false=>[0]}.merge(l.group_by{|i|i>0})
a[true]#.sort!
a[false].map!{|i|-i}#.sort!
#a.values.map(&:sort!)
b=Hash[a.map{|k,v|[k,v.inject(:+)]}]
#p a,b
puts (if b[true]==b[false]
  if a[true]==a[false]
    l[-1]>0
  else
    a.keys.max_by{|i|a[i]}
  end
else
  b[true]>b[false]
end)?"first":"second"

def min(a, b)
    (a < b)? a : b
end

def cmp(a, b)
    (a < b)? -1 : ((a == b)? 0 : +1)
end

n = gets.to_i
p, u = 0, []
q, v = 0, []
l = 0

for i in 0...n
    x = gets.to_i
    y = x.abs

    if x > 0
        p += y
        u << y
        l = 1
    else
        q += y
        v << y
        l = -1
    end
end

ans = cmp(p, q)

if ans == 0
    min = min(u.size, v.size)

    for i in 0...min
        ans = cmp(u[i], v[i])
        break if ans != 0
    end

    ans = l if ans == 0
end

data = {1 => 'first', -1 => 'second'}

puts data[ans]

def lex(first,second)
	lexi = true
	i = 0
	j = 0
	ans = nil
	while i < first.length && j < second.length
		if first[i] < second[i]
			ans = "second"
			break
		elsif first[i] > second[i]
			ans = "first"
			break
		end
		i += 1
		j += 1
	end
	if !ans && first.length != second.length
		if first.length < second.length
			ans = "second"
		else
			ans = "first"
		end
	end
	ans
end

n = gets.to_i
arr = []
n.times do
	arr << gets.to_i
end
first = arr.select{|a| a > 0}
second = arr.select{|a| a < 0}.map { |e| e.abs  }

first_score = first.inject(0,:+)
second_score = second.inject(0,:+)

if first_score < second_score
	ans = "second"
elsif first_score > second_score
	ans = "first"
else
	ans = lex(first,second)
	unless ans
		if arr[-1] > 0
			ans = "first"
		else
			ans = "second"
		end
	end

end
puts ans

def compare_arrays(f, s)

  for i in f.zip s
    if i[0] > i[1]
      return 1
    elsif i[1] > i[0]
      return 2
    end
  end

  if f.length > s.length
    return 1
  elsif f.length < s.length
    return 2
  end

  0
end

n = gets.to_i

sum = 0
first = []
second = []

for _ in 1..n
  cur = gets.to_i

  sum += cur

  if cur > 0
    first << cur.abs
  else
    second << cur.abs
  end
end

if sum > 0
  puts "first"
elsif sum < 0
  puts "second"
else
  case compare_arrays(first, second)
    when 0
      if cur > 1
        puts "first"
      elsif cur < 2
        puts "second"
      end
    when 1
      puts "first"
    else
      puts "second"
  end

end

# puts "First #{first}"
# puts "Second #{second}"

pa=Array.new
pb=Array.new
x=y=k=sa=sb=0

n=gets.to_i
for i in 0..n-1
  h=gets.to_i
  if h>0
    k=1
    pa[x]=h
    x+=1
    sa+=h
  else
    k=2
    pb[y]=-h
    y+=1
    sb+=-h
  end
end

g=0
if sa>sb
  puts "first"
  g=1
elsif sa<sb
  puts "second"
  g=1
end

if g==0
  i=0
  while i<x&&i<y
    if pa[i]>pb[i]
      puts "first"
      g=1
      break
    elsif pa[i]<pb[i]
      puts "second"
      g=1
      break
    end
    i+=1
  end
end

if g==0
  if k==1
    puts "first"
  elsif k==2
    puts "second"
  end
end

n=gets.to_i
ar,br,a,b,flag,i=Array.new(200001,0),Array.new(200001,0),0,0,0,0
sumA,sumB=0,0
n.times do
	t=gets.to_i
	if t>0
		sumA+=t
		ar[a]=t
		a+=1
	else
		sumB-=t
		br[b]=-t
		b+=1
	end
end
flag=1 if sumA>sumB
flag=2 if sumB>sumA
if flag==0
	while i<a && i<b
		if ar[i]>br[i]
			flag=1
			break
		elsif br[i]>ar[i]
			flag=2
			break
		end
		i+=1
	end
end
puts (flag==1) ? "first" : "second"

ans = {}
ans[-1] = 'second'
ans[ 0] = ''
ans[+1] = 'first'

n = gets.to_i
u = []
v = []

for i in 0...n
    x = gets.to_i
    y = x.abs

    if x > 0
        u << y
        ans[0] = 'first'
    else
        v << y
        ans[0] = 'second'
    end
end

u << 0 if u.size == 0
v << 0 if v.size == 0

p = u.map{|x| x.to_i}.reduce(:+)
q = v.map{|x| x.to_i}.reduce(:+)

if p > q
    puts ans[1]
elsif p < q
    puts ans[-1]
else
    puts ans[u.join.casecmp(v.join)]
end

ans = {}
ans[-1] = 'second'
ans[ 0] = ''
ans[+1] = 'first'

n = gets.to_i
u = []
v = []

for i in 0...n
    x = gets.to_i
    y = x.abs

    if x > 0
        u << y
        ans[0] = 'first'
    else
        v << y
        ans[0] = 'second'
    end
end

puts ans[u.join.casecmp(v.join)]

N = gets.to_i
vals = STDIN.read.split.map(&:to_i)
firsts = []
seconds = []
first = 0
second = 0
last_player = nil
vals.each{|val|
    if val>0
        first += val
        last_player = "first"
        firsts << val
    else
        second +=  - val
        last_player = "second"
        seconds << - val
    end
}
seq_first = false
seq_second = false

(0...[firsts.size, seconds.size].max).each{|i|
    if(firsts[i].to_i > seconds[i].to_i)
        seq_first = true
    elsif(firsts[i].to_i < seconds[i].to_i)
        seq_second = true
    end
}
# puts "first=#{first}, second=#{second}"
if first > second then
    puts "first"
    exit 0
elsif second > first then
    puts "second"
    exit 0
end
if seq_first then
    puts "first"
    exit 0
elsif seq_second then
    puts "second"
    exit 0
end
puts last_player

l=(1..gets.to_i).map{gets.to_i}
a=l.group_by{|i|i>0}
a[true].sort!
a[false].map!{|i|-i}.sort!
a.values.map(&:sort!)
b=Hash[a.map{|k,v|[k,v.inject(:+)]}]
puts (if b[true]==b[false]
  if a[true]==a[false]
    l[-1]>0
  else
    a.keys.max_by{|i|a[i]}
  end
else
  a.keys.max_by{|i|b[i]}
end)?"first":"second"

l=(1..gets.to_i).map{gets.to_i}
a=l.group_by{|i|i>0}
#a[true].sort!
a[false].map!{|i|-i}#.sort!
a.values.map(&:sort!)
b=Hash[a.map{|k,v|[k,v.inject(:+)]}]
#p a,b
puts (if b[true]==b[false]
  if a[true]==a[false]
    l[-1]>0
  else
    a.keys.max_by{|i|a[i]}
  end
else
  a.keys.max_by{|i|b[i]}
end)?"first":"second"

l=(1..gets.to_i).map{gets.to_i}
a={true=>[0],false=>[0]}.merge(l.group_by{|i|i>0})
a[true].sort!
a[false].map!{|i|-i}.sort!
a.values.map(&:sort!)
b=Hash[a.map{|k,v|[k,v.inject(:+)]}]
#p a,b
puts (if b[true]==b[false]
  if a[true]==a[false]
    l[-1]>0
  else
    a.keys.max_by{|i|a[i]}
  end
else
  a.keys.max_by{|i|b[i]}
end)?"first":"second"

l=(1..gets.to_i).map{gets.to_i}
a={true=>[0],false=>[0]}.merge(l.group_by{|i|i>0})
#a[true].sort!
a[false].map!{|i|-i}#.sort!
a.values.map(&:sort!)
b=Hash[a.map{|k,v|[k,v.inject(:+)]}]
#p a,b
puts (if b[true]==b[false]
  if a[true]==a[false]
    l[-1]>0
  else
    a.keys.max_by{|i|a[i]}
  end
else
  a.keys.max_by{|i|b[i]}
end)?"first":"second"

l=(1..gets.to_i).map{gets.to_i}
a={true=>[0],false=>[0]}.merge(l.group_by{|i|i>0})
a[true].sort!
a[false].map!{|i|-i}.sort!
#a.values.map(&:sort!)
b=Hash[a.map{|k,v|[k,v.inject(:+)]}]
#p a,b
puts (if b[true]==b[false]
  if a[true]==a[false]
    l[-1]>0
  else
    a.keys.max_by{|i|a[i]}
  end
else
  b[true]>b[false]
end)?"first":"second"

pa=Array.new
pb=Array.new
x=y=k=sa=sb=0

n=gets.to_i
for i in 0..n-1
  h=gets.to_i
  if h>0
    k=1
    pa[x]=h
    x+=1
    sa+=h
  else
    k=2
    pb[y]=-h
    y+=1
    sb+=-h
  end
end

flag=0
if sa>sb
  puts "first"
  flag=1
elsif sa<sb
  puts "second"
  flag=1
end

if flag==0
  i=0
  while i<x&&i<y
    if x[i]>y[i]
      puts "first"
      flag=1
      break
    elsif x[i]<y[i]
      puts "second"
      puts "jh"
      flag=1
      break
    end
    i+=1
  end
end

if flag==0
  if k==1
    puts "first"
  elsif k==2
    puts "second"
  end
end

pa=Array.new
pb=Array.new
x=y=k=sa=sb=0

n=gets.to_i
for i in 0..n-1
  h=gets.to_i
  if h>0
    k=1
    pa[x]=h
    x+=1
    sa+=h
  else
    k=2
    pb[y]=-h
    y+=1
    sb+=-h
  end
end
sta=pa.join
stb=pb.join

if sa!=sb
  if sa>sb
    puts "first"
  else
    puts "second"
  end
elsif sta!=stb
  if sta>stb
    puts "first"
  else
    puts "second"
  end
else
  if k==1
    puts "first"
  elsif k==2
    puts "second"
  end
end

pa=Array.new
pb=Array.new
x=y=k=sa=sb=0

n=gets.to_i
for i in 0..n-1
  h=gets.to_i
  if h>0
    k=1
    pa[x]=h
    x+=1
    sa+=h
  else
    k=2
    pb[y]=-h
    y+=1
    sb+=-h
  end
end

flag=0
if sa>sb
  puts "first"
  flag=1
else
  puts "second"
  flag=1
end

if flag==0
  i=0
  while i<x and i<y
    if x[i]>y[i]
      puts "first"
      flag=1
      break
    elsif x[i]<y[i]
      puts "second"
      flag=1
      break
    end
    i+=1
  end
end

if flag==0
  if k==1
    puts "first"
  elsif k==2
    puts "second"
  end
end

pa=Array.new
pb=Array.new
x=y=k=sa=sb=0

n=gets.to_i
for i in 0..n-1
  h=gets.to_i
  if h>0
    k=1
    pa[x]=h
    x+=1
    sa+=h
  else
    k=2
    pb[y]=-h
    y+=1
    sb+=-h
  end
end

g=0
if sa>sb
  puts "first"
  g=1
elsif sa<sb
  puts "second"
  g=1
end

if g==0
  i=0
  while i<x&&i<y
    if x[i]>y[i]
      puts "first"
      g=1
      break
    elsif x[i]<y[i]
      puts "second"
      g=1
      break
    end
    i+=1
  end
end

if g==0
  if k==1
    puts "first"
  elsif k==2
    puts "second"
  end
end

# 493B

a_sum = b_sum = 0
a_str = b_str = ''
val = nil
gets.to_i.times {
  val = gets.to_i
  if val > 0
    a_sum += val
    a_str << val
  else
    b_sum += -val
    b_str << -val
  end
}
res = if a_sum > b_sum
        true
      elsif a_sum < b_sum
        false
      elsif a_str > b_str
        true
      elsif a_str < b_str
        false
      else
        val > 0
      end
puts res ? 'first' : 'second'


gets.to_i.times do
    x,y = gets.split.map(&:to_i)
    puts (x-y > 1) ? "Yes" : "No"
end

t = gets.to_i
t.times do
  x, y = gets.split.map(&:to_i)
  d = x - y
  puts d == 1 ? 'NO' : 'YES'
end

# coding: utf-8

# if __FILE__ == $0
# end

t = gets.to_i
primes = [2,3]
t.times {
    x, y = gets.split.map(&:to_i)
    # x > y, guaranteed
    d = x - y
    if d < 2
        puts "NO"
    else
        puts "YES"
    end
}

t = gets.to_i
for i in 1..t
    a,b = gets.split.map(&:to_i);
    flag = 0
    if (a-b>=2)
        print "YES"
        puts "\n"
        flag = 1
    end
    if flag != 1
        print "NO"
        puts "\n"
    end
end

t = gets.to_i
t.times do
  x, y = gets.split.map &:to_i
  puts x - y == 1 ? 'NO' : 'YES'
end

# coding: utf-8

# if __FILE__ == $0
# end

t = gets.to_i
primes = [2,3]
t.times {
    x, y = gets.split.map(&:to_i)
    # x > y, guaranteed
    d = x - y
    if d < 2
        puts "NO"
    else
        if d%2 == 0
            puts "YES"
        else
            # prime sub check
            is_prime_sub = false
            for i in primes
                break if i > d
                if d%i == 0
                    is_prime_sub = true
                    break
                end
            end

            # generate primes and check prime sub
            sqd = Math.sqrt(d).ceil
            if primes.last < sqd
                for i in (primes.last)..sqd
                    is_prime = true
                    for j in primes
                        if i%j == 0
                            is_prime = false
                            break
                        end
                    end

                    primes << i if is_prime

                    if d%i == 0
                        is_prime_sub = true
                        break
                    end
                end
            end

            if is_prime_sub
                puts "YES"
            else
                puts "NO"
            end
        end
    end
}

# coding: utf-8

# if __FILE__ == $0
# end

t = gets.to_i
primes = [2,3]
t.times {
    x, y = gets.split.map(&:to_i)
    # x > y, guaranteed
    d = x - y
    if d < 2
        puts "NO"
    else
        if d%2 == 0
            puts "YES"
        else
            # prime sub check
            is_prime_sub = false
            sqd = Math.sqrt(d).floor

            for j in primes
                break if j > sqd
                if sqd%j == 0
                    is_prime_sub = true
                    break
                end
            end

            if is_prime_sub == false
                for i in (primes.last)..sqd
                    next if i%2 == 0
                    is_prime = true
                    for j in primes
                        if i%j == 0
                            is_prime = false
                            break
                        end
                    end

                    if is_prime
                        primes << i

                        if sqd%i == 0
                            is_prime_sub = true
                            break
                        end
                    end
                end
            end

            # 안되면 끝까지 구해야지 별 수 있나
            # 가즈아! (근데 이걸로는 submission 못해봄.)
            # 1
            # 999984 1

            # p primes
            if is_prime_sub
                puts "YES"
            else
                puts "NO"
            end
        end
    end
}


n = gets.to_i

n.times{
  s = gets
  n = s.length-1
  if n <= 10
    puts s
   else
    puts s[0] + (n-2).to_s + s[n-1]
  end
}

array = STDIN
array.each { |x| if x.size > 11 then puts "#{x[0]}#{x.size - 3}#{x[-2]}" elsif x =~ /[0-9]/ then nil else puts x end }

n = gets.to_i
n.times.map { gets.chomp }.each do |word|
    if (s = word.size - 2) > 8
        puts "#{word[0]}#{s}#{word[-1]}"
    else
        puts word
    end
end

n = gets.to_i
n.times do
  str = gets.chomp
  if str.length>10
    puts str[0]+(str.length-2).to_s+str[-1]
  else
    puts str
  end

end

n = gets.to_i
while n > 0 do
    word = gets.chomp
    if (s = word.size - 2) > 8
        puts [word[0], s, word[-1]].join
    else
        puts word
    end
    n -= 1
end

n = gets.to_i
words = n.times.map { gets.chomp }
words.map do |word|
    if (s = word.size - 2) > 8
        "#{word[0]}#{s}#{word[-1]}"
    else
        word
    end
end.each { |w| puts w }

n = gets.to_i
while n > 0 do
    word = gets.chomp
    if word.size > 10
        puts [word[0], word.size-2, word[-1]].join
    else
        puts word
    end
    n -= 1
end

n = gets.to_i

n.times{
  s = gets
  n = s.length-1
  if n <= 10
    puts s
   else
    puts s[0] + (s[1..n-2].length.to_s) + s[n-1]
  end
}

n = gets.chomp.to_i
words = []
(1..n).each do |_i|
  words << gets.chomp
end

words.each do |w|
  if w.size < 11
    puts w
  else
    puts "#{w[0]}#{w.size - 2}#{w[-1]}"
  end
end

n = gets.to_i

$i = 0

while $i < n
    s = gets
    if s.length < 12
        puts s
    elsif
        puts "#{s[0]}#{s.length - 3}#{s[s.length - 2]}"
    end

    $i += 1
end

t = gets.to_i

lines = []
t.times do
  current = gets.chomp
  if current.length > 10
    lines.push(current[0] + (current.length - 2).to_s + current[current.length-1])
  else
    lines.push(current)
  end
end

lines.each do |line|
  puts line
end

n = gets.to_i

n.times do
  input = gets.chomp
  if input.size > 10
    puts "#{input.chars.first}#{input.length - 2}#{input.chars.last}"
  else
    puts input
  end
end

ans=Array.new
gets.to_i.times{s=gets; s.size>11? (ans<<"#{s[0]}#{s.size-3}#{s[-2]}"):(ans<<s)};
puts ans

gets.chomp.to_i.times do |_|
  word = gets.chomp.each_char
  printf(word.size > 10 ? "#{word.first}#{word.size-2}#{word.to_a.last}\n" : "#{word.to_a.join}\n")
end

t=gets.to_i
t.times{

  s=gets.chomp
  n=s.size
  if n<=10
    puts s
  else
    puts "#{s[0]}#{n-2}#{s[-1]}"
  end

}

number = gets.chomp.to_i
number.times do
  word = gets.chomp

  if word.size > 10
    puts word[0] + (word.size - 2).to_s + word[-1]
  else
    puts word
  end
end

gets.to_i.times do
s=gets.chomp
	if s.length > 10
	puts s[0] << (s.length - 2).to_s << s[s.length - 1]
	else
	puts s
	end
end

n = gets.to_i
a =[]
for i in 0..n-1 do
  a = a + [gets]
  if a[i].size > 11
    a[i] = (a[i][0] + (a[i].size - 3).to_s + a[i][a[i].size - 2])
  end
end
puts a

n = gets.to_i
n.times do |i|
  l = gets.strip
  s = l.size
  puts s>10 ? l[0]+(s-2).to_s+l[s-1] : l
end

#!/usr/bin/ruby
n = STDIN.gets.chop.to_i

n.times do
  word = STDIN.gets
  word.chop!

  if word.length > 10
    print word[0, 1]
    print word.length-2
    print word[-1, 1]
  else
    print word
  end

  print "\n"
end

n=gets.to_i

n.times {
i=gets
a=i.length
if (a <= 11)
 puts i
else
 out= i[0] + (a-3).to_s + i[a-2]
 puts out
end
}

n = gets.to_i

a = Array.new(n)
for i in 0..(n - 1)
  a[i] = gets.to_s
end

a.each {|b|
if b.length >= 12
  f = b.split("")[0]
  l = b.split("")[(b.length-2)]
  c = b.split("")[1..(b.length-3)].join("")
  puts "#{f}#{c.length}#{l}"
else
  puts "#{b}"
end
}

lines = STDIN.read.split("\n")
if 2 <= lines.size
  lines[1..(lines.size - 1)].each do |word|
    puts word.length <= 10 ? word : "#{word[0]}#{word.length - 2}#{word[word.length - 1]}"
  end
end

limit =gets.chomp()
limit = limit.to_i
while limit>0
	word = gets.chomp()
	if word.length>10
		print word[0],word.length-2,word[-1]
		print "\n"
	else
		puts word
	end
	limit-=1
end

gets.to_i.times do
	word = gets.chomp
	if word.length <= 10
		puts word
	else
		print word[0], word.length - 2, word[-1], "\n"
	end
end

T = gets.chomp.to_i
for i in (0...T)
  a = gets.chomp
  if(a.length > 10)
    puts a[0] + (a.length - 2).to_s + a[a.length - 1]
  else
    puts a
  end
end

number = gets.chomp.to_i

number.times do
word = gets.chomp

if word.length > 10
str = ''
number = word.length - 2
str = word[0] + number.to_s + word[word.length - 1]
puts str
else
puts word
end
end

def abb ()
    n = gets.to_i
  words = Array.new(n)
    for i in 0...n
      word = gets.to_s
      words[i] = word.chomp!
    end
  words.each{ |word|
        if word.length <= 10
            puts word
        else
            puts "#{word[0]}#{word.length-2}#{word[-1]}"
        end
  }
end

abb

n = gets.to_i
n.times do
a = gets.chomp
d = Array.new
b = a[0]
c = a[-1, 1]
x = a[1..-2]
s = x.size.to_i
 if s > 8
 d << b << s << c
 d.map { |sammy| sammy}
 puts d.join
 else
 puts a
 end
 end

num = gets.chomp
num = num.to_i

num.times do
    input = gets.chomp #get the next lines of input
    if (input.size > 10) #if the size of the string is 10 or more..
         firstLetter = input.split("").first
         lastLetter = input.split("").last
         input = input.split("")
         input.pop
         input.shift
         input = input.join
         new_word = "#{firstLetter}#{input.length}#{lastLetter}\n"
         print new_word
    else
        word = "#{input}\n"
        print word
    end
end

x = gets.chomp.to_i

for i in 0...x do
   words = gets.chomp.to_s
   if words.length > 10
    puts words[0].to_s + (words.length-2).to_s + words[-1]
   else
    puts words
   end
end

input = STDIN.read

n, lines = input.split("\n", 2)

lines = lines.split("\n")
# n = n.to_i
lines.each do |line|
  if line.length < 11
    puts line
  else
    puts "#{line[0]}#{line.length - 2}#{line[line.length - 1]}"
  end
end

# frozen_string_literal: true

n = gets.to_i

1.upto(n).each do |_i|
  str = gets.strip
  if str.length <= 10
    puts str
    next
  end
  len = str.length - 2
  puts "#{str[0]}#{len}#{str[str.length - 1]}"
end

(gets.to_i).times do
  ss=gets
  if(ss.length>11)
    ss[1,ss.length-3] = (ss.length-3).to_s
  end
  puts (ss)
end

n = gets.chomp.to_i
i = 0
while i < n  do
   s = gets.chomp
   t = s.size
   if t > 10
    print s[0]
    print t - 2
    puts s[t-1]
   else
    puts s
   end
   i += 1
 end

class LongWord
  def initialize(word)
    @word = word
  end

  def short_version
    return @word if @word.size <= 10

    first_char = @word[0]
    last_char = @word[-1]
    rest_word_count = @word[1..-2].size

    "#{first_char}#{rest_word_count}#{last_char}"
  end
end

# Main
count_of_input = gets.strip.to_i
word_collection = []
count_of_input.times do
  word = gets.strip
  word_collection << word
end

word_collection.each do |word|
  long_word = LongWord.new(word)
  puts long_word.short_version
end

n=gets.chomp.to_i
n.times do
	a=gets.chomp.to_s
	num=a.length - 2
	if a.length>10
		word=a[0]+num.to_s+a[num+1]
	else
		word=a
	end
	puts word
end

n=gets.chomp.strip.to_i
n.times do
	a=gets.chomp.to_s
	num=a.length - 2
	if a.length>10
		word=a[0]+num.to_s+a[num+1]
	else
		word=a
	end
	puts word
end

n = gets.chomp.to_i
for i in(0...n)
    s = gets.chomp
    if s.length() < 11
        puts s
    else
        print s[0],s.length()-2,s[s.length()-1]
        puts
    end
end

gets.chomp.to_i.times do
    word = gets.chomp
    if word.length > 10
        print word[0], ((word.length)-2).to_s, word[-1], "\n"
    else
        print word, "\n"
    end
end

gets.to_i.times do
  s = gets.chomp
  puts s.size>10?"#{s[0]}#{s.size-2}#{s[-1]}":s
end

n = gets.strip.to_i
n.times do |i|
  word = gets.strip
  result = ""
  if word.length > 10 then
    result = "#{word[0]}#{word[1..-2].length}#{word[-1]}"
  else
    result = word
  end
  puts result
end

n=gets.to_i
a= []
for i in 0..n-1
	a[i] = gets
end
a.each do |val|
	val = val.gsub("\n","")
	len = val.length
	puts  len <= 10 ? val : "#{val[0]}#{len-2}#{val[len-1]}"
end

#!/usr/bin/ruby

n = gets.chomp.to_i

n.times do
  s = gets.chomp.to_s

  if s.length > 10
    first_letter = s[0]
    last_letter = s[s.length-1]
    abbr = (s.length - 2).to_s
    puts (first_letter + abbr + last_letter)
  else
    puts s
  end
end

n = gets.chomp.to_i
0.upto n-1 do |i|
  w = gets.chomp
  if w.length > 10 then
	ww = "#{w[0]}#{w.length-2}#{w[w.length-1]}"
	puts ww
  else
    puts w
  end
end

n = gets.to_i

for i in 0...n
  x = gets;
  if x.size > 11
  print x[0]
  print x.size-3;
  print x[x.size-2].chr;
    puts
  elsif
    puts x;
  end
end

n = gets.chomp.to_i.times do |i| a = gets.chomp.to_s; if a.length>10 then print(a[0]); print(a.length-2); puts(a[a.length-1]); else puts(a) end end

#!/usr/bin/env ruby
class Test
	kol = gets.chomp
	ik = kol.to_i
	for num in 1..ik
		str = gets.chomp
	if str.length > 10
	len = str.length - 2
	len = len.to_s
	temp = str[0..0] + len + str[str.length-1..str.length-1]
		puts temp
	else
		puts str
	end
	end
end

n=gets.chomp.to_i.times{a=gets.chomp.to_s;o=a.length;if o>10 then printf("%c%d%c\n",a[0],o-2,a[o-1]);else puts(a)end}

a = gets.to_i

for arr in (1..a)
  arr = gets.to_s
  if arr.length > 11
    startLetter = arr[0]
    lastLetter = arr[arr.length - 2]
    puts arr = startLetter + (arr.length.to_i - 3).to_s + lastLetter.to_s
  else
    puts arr.to_s
  end
end

n = gets.to_i

words = []

n.times do
	curr = gets

	if curr.length > 11
		last = curr[curr.length - 2, 1]
		curr = curr[0] + (curr.length - 3).to_s
		curr = curr + last
	end

	words << curr
end

puts words

n = gets.to_i
n.times do
  s = gets.chomp
  if s.size <= 10
    puts s
  else
    puts "#{s[0]}#{s.size - 2}#{s[-1]}"
  end
end

len = 10
n = gets.to_i
while n > 0 do
    word = gets.chomp
    if word.size > len
        puts [word.chars.first, word.size-2, word.chars.last].join
    else
        puts word
    end
    n -= 1
end

def too_long_word (word)
    x = 0
    n = gets
    num = n.to_i

    while x < num
      word = gets
      char = word.chomp.split('')
      sum_char = char.size
      char_min = ((sum_char) - 2).to_s
        if sum_char <= 10
          puts word
        else
          puts char.first + char_min + char.last
        end
    x+=1
    end
end

too_long_word ()

n = readline.to_i

i = 0
a = Array.new()

while i < n do
  begin
    a[i] = readline
    i += 1
  end
end
a.each do
  |i|
  if (i.size > 11)
    puts i[0] + (i.size - 3).to_s + i[i.size - 2]
  else
    puts i
  end
end

gets.chomp.to_i.times {
	s=gets.chomp
	if(s.length<=10)
		puts s
	elsif
		puts "#{s[0]}#{s.length-2.to_i}#{s[-1]}"
	end
}

gets.chomp.to_i.times do
  str = gets.chomp
  puts str.length > 10 ? "#{str[0]}#{str.length - 2}#{str[-1]}" : str
end

x = gets.to_i

def check(j)
	if j.length <= 10
		puts j
	else
		puts j[0] + (j.length - 2).to_s + j[-1]
	end
end

for i in 1..x do
	y = gets.chomp
	check(y)
end

m=gets.to_i
m.times do
  s = gets.chomp
  if s.size <= 10
    puts s
  else
    puts "#{s[0]}#{s.size - 2}#{s[-1]}"
  end
end

a = gets.to_i
for i in 1..a
    b = gets
    c = b.length
    c = c - 1
    if c <= 10
        puts b
    else
        d = c - 2
        print b[0]
        print d
        print b[c-1]
        puts
    end
end

1.upto(gets.to_i) do
  a = gets.chomp
  a = "#{a[0, 1]}#{a.length - 2}#{a[-1, 1]}" if a.length > 10

  puts a
end

a = gets.split(" ")
n = a[0].to_i
for i in 1..n
  s = gets.chomp
  if(s.size > 10)
    s1 = s[0]+(s.size-2).to_s+s[s.size - 1]
    puts(s1)
  else puts(s)
  end
end

x=gets.to_i
x.times do
n=gets.chomp
z=n.length
if z > 10
print n[0]
print z-2
print n[z-1]
print "\n"
else
print n
print "\n"
end
end

a=Array.new;
n=gets;
n.to_i.times{|i|a[i]=gets.chop}
a=a.map{|i|if i.size>10 then i=i[0..0]+(i.size-2).to_s+i[-1..-1] else i=i end}
a.each{|i|puts i}

n = gets.chomp.to_i

n.times do
  word = gets.chomp
  if word.size > 10
    n = word.size
    puts "#{word[0]}#{n - 2}#{word[n-1]}"
  else
    puts word
  end
end

a = Array.new
n = gets.to_i
n.times do
 a << gets.to_s.chop
end
a.each do |i|
 if i.size <= 10
  p i
 else
  p "#{i[0]}#{i.size-2}#{i[(i.size-1)]}"
  end
end

n = gets.chomp.to_i
(0...n).each do |i|
	word = gets.chomp
	if word.length > 4
		print word[0], (word.length - 2), word[(word.length - 1)], "\n"
	else puts word
	end
end

(gets.to_i).times do
  str=gets
   if str.length > 10 then
     str[1,str.length - 2] = (str.length - 2).to_s
   end
   puts str
 end

a = gets.to_s
d = []
b = a[0]
c = a[-1, 1]
x = a[1..-2]
s = x.size.to_i
y = s.to_s
 d << b << y << c
 if s > 10
 puts d.join
 else
 puts a
 end

n = gets.to_i

$i = 0

while $i < n
    s = gets
    if s.size < 11
        puts s
    elsif
        puts "#{s[0]}#{s.size - 3}#{s[s.size - 2]}"
    end

    $i += 1
end

n = gets.chomp.to_i
for i in(0...n)
    s = gets.chomp
    if s.length() < 10
        puts s
    else
        print s[0],s.length()-2,s[s.length()-1]
        puts
    end
end

a = gets.to_s
b = a[0]
c = a[-1]
s = a.size
x = s - 2
z = x.to_s
 if s > 10
 puts b + z + c
 else
 puts a
 end

a = gets.to_i

for arr in (1..a)
  arr = gets.to_s
  if arr.length > 10
    startLetter = arr[0]
    lastLetter = arr[arr.length - 2]
    puts arr = startLetter + (arr.length.to_i - 3).to_s + lastLetter.to_s
  else
    puts arr.to_s
  end
end

def abb ()
    n = gets.to_i
    for i in 0...n
    word = gets.to_s
    word.chomp!
        if word.length < 10
            puts word
        else
            puts "#{word[0]}#{word.length-2}#{word[-1]}"
end
end
end

abb

#!/usr/bin/env ruby
class Test
	kol = gets.chomp
	ik = kol.to_i
	for num in 1..ik
		str = gets.chomp
	if str.length > 10
	len = str.length.to_s
	temp = str[0..0] + len + str[str.length-1..str.length-1]
		puts temp
	else
		puts str
	end
	end
end

n = gets.chomp.to_i

n.times do
    s = gets.chomp
    if s.length >= 10
        p "#{s[0]}#{s.length-2}#{s[s.length-1]}"
    else
        p s
    end
end

n = gets.chomp.to_i
for i in(0...n)
    s = gets.chomp
    if s.length() < 11
        puts s
    else
        print s[0],s.length()-2,s[s.length()-1]
    end
end

n = gets.to_i
n.times do |i|
	temp = gets
	if (temp.size < 11)
		puts temp
	else
		k = temp.size - 2
		curr = temp[0] + k.to_s + temp[k]
		puts curr
	end
end

a = gets.to_s
b = a[0]
c = a[-1]
d = a[1...-2]
 if a.length > 10
 puts b + d + c
 else
 puts a
 end

array = STDIN
array.each { |x| if x.size > 10 then puts "#{x[0]}#{x.size - 2}#{x[-1]}" elsif x =~ /[0-9]/ then nil else puts x end }

counter = gets.chomp.to_i

counter.times do
  word = gets.chomp.to_s

  if word.length > 10
    word = word[0,1] + ( word.length - 2 ).to_s + word[word.length-1, 1]
  end

  p word
end

n = gets.chomp.to_i
for i in(0...n)
    s = gets.chomp
    if s.length() < 10
        puts s
    else
        puts s[0],s.length(),s[s.length()-1]
    end
end

x = gets.to_i

def check(j)
	if j.length <= 10
		puts j
	else
		puts j[0] + j.length.to_s + j[-1]
	end
end

for i in 1..x do
	y = gets.chomp
	check(y)
end

n = gets.to_i

$i = 0

while $i < n
    s = gets
    puts s.length
    if s.length < 12
        puts s
    elsif
        puts "#{s[0]}#{s.length - 3}#{s[s.length - 2]}"
    end

    $i += 1
end

#!/usr/bin/env ruby
str = ARGF.read

if str.scan(/\D/).empty?
    exit
elsif str.size <= 10
    puts str
else
    puts str[0] + (str.length - 2).to_s + str[str.length - 1]
end

n = gets.to_i
n.times do
a = gets.chomp
d = Array.new
b = a[0]
c = a[-1, 1]
x = a[1..-2]
s = x.size.to_i
 if s >= 10
 d << b << s << c
 d.map { |sammy| sammy}
 puts d.join
 else
 puts a
 end
 end

a = gets.to_i
for i in 1..a
    b = gets
    c = b.length
    c = c - 1
    if c <=4
        puts b
    else
        d = c - 2
        print b[0]
        print d
        print b[c-1]
    end
end

n = gets.split.map &:to_i
n.each do |i|
    word = gets.split.map
    if word.count > 10
        p w[0] + w.count-2 + w[-1]
    else
        p word
    end
end

string = gets.chomp
puts (string[0] + (string.length-2).to_s + string[-1])

n = gets.to_i
n.times do
a = gets.chomp
d = Array.new
b = a[0]
c = a[-1, 1]
x = a[1..-2]
s = x.size.to_i
 if s > 10
 d << b << s << c
 d.map { |sammy| sammy}
 puts d.join
 else
 puts a
 end
 end

i=gets
a=i.length
if (a <= 11)
 puts i
else
 out= i[0] + (a-2).to_s + i[a-2]
 puts out
end

c, arr = gets.to_i, []
c.times { arr << gets }

arr.map! do |w|
  w.length > 10 ? "#{w[0]}#{w.length-3}#{w[-2]}" : w
end

puts arr

n = gets.to_i

a = Array.new(n)
for i in 0..(n - 1)
  a[i] = gets.to_s
end

a.each {|b|

if b.length >= 10
  f = b.split("")[0]
  l = b.split("")[(b.length-2)]
  c = b.split("")[1..(b.length-3)].join("")
  puts "#{f}#{c.length}#{l}"
else
  puts "#{b}"
end
}

a = gets.to_s
b = a[0]
c = a[-1]
s = a.size
z = s.to_s
 if s > 10
 puts b z c
 else
 puts a
 end

a = String.new
a = gets
b = a[0]
c = a[-1]
d = a[1..-2]
 s = a.size.to_i
 if s >= 10
 puts b + d + c
 else
 puts a
 end

n = gets.split.map &:to_i
n.each do |i|
    w = gets.strip
    if w.size > 10
        puts w[0] + w.size-2 + w[-1]
    else
        puts w
    end
end

n = gets.to_i
n.times do
  s = gets.chomp
  if s.size < 10
    puts s
  else
    puts "#{s[0]}#{s.size - 2}#{s[-1]}"
  end
end

n=gets.to_i
n.times do
str=gets.chomp.to_s
puts "#{str[0]}#{str.size-2}#{str[str.size-1]}"
end

x=gets.to_i
x.times do
n=gets.chomp
z=n.length
if z > 10
print n[0]
print z-2
print n[z-1]
else
print n
end
end

x=gets.to_i
x.times do
n=gets.chomp
z=n.length
if z > 10
print n[0]
print z-2
print n[z-1]
else
print n
print "\n"
end
end

n = Integer(gets)
a = Array.new
for i in 0...n
	a[i] = gets
end
		def word_to_long(b)
			l = b.length
			if l > 10
				return b[0] + "#{l - 3}"+ b[l-2]
			else
				return b
			end
		end

	for i in 0...n
		puts word_to_long(a[i])
	end

t = gets.chomp.to_i

for i in 1..t
  s = gets.chomp
  if s.length < 5
    puts s
    next
  end
  print s[0];print s.length-2; puts s[-1]
end

line_count = gets.to_i

for i in 1..line_count
    line = gets
    if line.length > 10
        p line[0] + (line.length-2).to_s + line[-1,1]
    else
        p line
    end
end

n = gets
n.to_i.times do
    word = gets.chomp
    l = word.size
    puts l
    if l > 10
        puts "#{word[0]}#{l-2}#{word[-1]}"
    else
        puts word
    end
end

a = gets.to_s
b = a[0]
c = a[-1]
s = a.size
x = s - 2
z = x.to_s
 if x >= 10
 puts b + z + c
 else
 puts a
 end

a = gets.to_s
b = a[0]
c = a[-1]
s = a.size
x = s - 2
z = x.to_s
 if s >= 10
 puts b + z + c
 else
 puts a
 end

line_count = gets.to_i

for i in 1..line_count
    line = gets.chomp
    if line.length > 10
        p line[0] + (line.length-2).to_s + line[-1,1]
    else
        p line
    end
end

n = gets.chomp.to_i
(0...n).each do |i|
	word = gets.chomp
	if word.length >= 4
		print word[0], (word.length - 2), word[(word.length - 1)], "\n"
	else puts i
	end
end

class LongWord
  def initialize(word)
    @word = word
  end

  def short_version
    return @word if @word.size <= 10

    first_char = @word[0]
    last_char = @word[-1]
    rest_word_count = @word[1..-2].size

    "#{first_char}#{rest_word_count}#{last_char}"
  end
end

# Main
word = gets.strip
short_version = LongWord.new(word).short_version
puts short_version

n = gets.to_i
while n > 0 do
    word = gets.chomp
    if (s = word.size - 2) >= 10
        puts [word[0], s, word[-1]].join
    else
        puts word
    end
    n -= 1
end

a = Array.new
n = gets.to_i
n.times do
 a << gets.to_s.chop
end
a.each do |i|
 if i.size < 10
  p i
 else
  p "#{i[0]}#{i.size-2}#{i[(i.size-1)]}"
  end
end

#!/usr/bin/env ruby
str = gets

if str.scan(/\D/).empty?
 return
end

if str.size <= 10
    puts str
    return
end

puts str[0] + (str.length - 2).to_s + str[str.length - 1]

puts "How many words would ou like to abreviate?"
words = gets.to_i
puts "Write down below #{words} words"

abreviadas = []
for number in 1..words
	palavra = gets.strip
	tamanho = (palavra.size) -2
	if palavra.size > 10
		palavras = palavra[0] + tamanho.to_s + palavra[(palavra.size)-1]
	else
		palavras = palavra
	end
		abreviadas<<palavras
end

puts "Your words are:"

puts abreviadas

STDIN.read.split("\n").drop(1).each do |w|
  puts res =  w.size < 10 ? w : w[0] + "#{(w.size - 2)}" + w[-1]
end

a = gets.to_s
b = a[0]
c = a[-1]
s = a[1...-2].to_i
 if s >= 10
 puts b s c
 else
 puts a
 end

a = gets.split(" ")
n = a[0].to_i
for i in 1..n
  s = gets.chomp
  if(s.size > 10)
    s1 = s[0]+(s.size-2).to_s+s[s.size - 1]
    p(s1)
  else p(s)
  end
end

lines = []
while line =(ARGV.shift or (!STDIN.tty? and STDIN.gets) )
  lines.push(line)
end

puts lines

num_line = gets.to_i()
num_line.times {
  str = gets()
  puts str.length()>10 ? str[0]+(str.length()-3).to_s+str[str.length()-2] : str
}

n=gets.to_i
a= []
for i in 0..n-1
	a[i] = gets
end
a.each do |val|
	len = val.length
	puts  len <= 10 ? val : "#{val[0]}#{len-3}#{val[len-2]}"
end

n=gets.to_i
a= []
for i in 0..n-1
	a[i] = gets
end
a.each do |val|
	len = val.length
	puts  len < 10 ? val : "#{val[0]}#{len-3}#{val[len-2]}"
end

a = gets.to_s
b = a[0]
c = a[-1]
s = a.size
x = s - 2
z = x.to_s
 if s > 10
 puts b + z + c
 else
 puts a
 end

x = gets.chomp.to_i

for i in 0...x do
   words = gets.chomp.to_s
   if words.length >= 10
    puts words[0].to_s + (words.length-2).to_s + words[-1]
   else
    puts words
   end
end

(gets.to_i).times do
  ss=gets
  ss[1,ss.length-3] = ss.length>10? (ss.length-3).to_s : ss[1,ss.length-3]
  puts (ss)
end

gets.chomp.to_i.times do
    a = gets.chomp
    if a.length<10
        puts a
    else
        print a[0],a.length-2,a[a.length-1],"\n"
    end
end

len = 10
n = gets.to_i
while n > 0 do
    word = gets.chomp
    if word.size > len
        p [word.chars.first, word.size-2, word.chars.last].join
    else
        p word
    end
    n -= 1
end

n = gets
n = n.to_i

for i in (1..n)
	string = gets
	if(string.size()<11)
		puts string
	else
		stringFinal = string[0]
		numero = string.size - 3
		stringFinal << numero.to_s
		stringFinal << string[string.size - 2]
		puts stringFinal
	end
end

n = STDIN.gets
while word = STDIN.gets
  word.strip!
  if word.length > 10
    puts "#{word[0,1]}#{word.length - 2}#{word[word.length-1,1]}"
  end
end

n = gets.to_i

$i = 0

while $i < n
    s = gets
    if s.size < 11
        puts s
    elsif
        puts "#{s[0]}#{s.size - 3}#{s[s.size - 2]}"
    end

    $i += 1
end

number_of_words = gets.to_i

words = []

number_of_words.times do |n|
    word = gets
    words.push(word)
end

words.each do |word|
    if word.length <= 10
        puts word
    else
        number_of_letters_between = word.length - 3
        fist_letter = word[0]
        last_letter = word[-2]
        puts "#{fist_letter}#{number_of_letters_between}#{last_letter}"
    end
end

n = gets.to_i
i = 0
y = []
while i < n
  x = gets
  if x.length > 10
    x[1...x.length-2] = (x.length-2).to_s
  end
  y << x
  i +=1
end

puts y

gets.chomp.to_i.times do
    word = gets.chomp
    if word.length >= 10
        print word[0], ((word.length)-2).to_s, word[-1], "\n"
    else
        print word, "\n"
    end
end

n = gets.to_i

words = []

n.times do
	curr = gets

	if curr.length > 10
		last = curr[curr.length - 2, 1]
		curr = curr[0] + (curr.length - 3).to_s
		curr = curr + last
	end

	words << curr
end

puts words

len = gets.to_i

while word = gets do
    word = word.chomp
    if word.size > len
        p [word.chars.first, word.size-2, word.chars.last].join
    else
        p word
    end
end

a = gets
b = []
c = a[0]
b << c
d = a[1..-2].length
b << d
e = a[-1]
b << e
f = b.join

if d > 10
puts f

else
puts a

end

(gets.to_i).times do
  str = gets
   if str.length > 10 then
     str= str[0..0] + (str.length - 2).to_s + str[-1..-1]
   end
   p str
end

number_of_words = gets.to_i

words = []

number_of_words.times do |n|
    word = gets
    words.push(word)
end

words.each do |word|
    if word.length < 10
        puts word
    else
        number_of_letters_between = word.length - 3
        fist_letter = word[0]
        last_letter = word[-2]
        puts "#{fist_letter}#{number_of_letters_between}#{last_letter}"
    end
end

n = gets.chomp.to_i
for i in(0...n)
    s = gets.chomp
    if s.length() < 10
        puts s
    else
        print s[0],s.length()-2,s[s.length()-1]
        puts
    end
end

n=gets.chomp.to_i.times{a=gets.chomp.to_s;o=a.length;if o>10 then printf("%c%d%c",a[0],o-2,a[o-1]);else puts(a)end}

n=gets.to_i
a= []
for i in 0..n-1
	a[i] = gets
end
a.each do |val|
	len = val.length
	puts  len <= 10 ? val : "#{val[0]}#{len-3}#{val[len-2]}"
end

array = STDIN
array.each { |x| if x.size > 10 then puts "#{x[0]}#{x.size - 2}#{x[-1]}" elsif x =~ /[0-9]/ then nil else puts x end }

n = gets.to_i
i = 0
y = []
while i < n
  x = gets
  if x.length > 10
    x[1...x.length-2] = (x.length-3).to_s
  end
  y << x
  i +=1
end

puts y

array = [4, "word", "localization", "internationalization", "pneumonoultramicroscopicsilicovolcanoconiosis"]
array.each { |x| if x.size > 10 then puts "#{x[0]}#{x.size - 2}#{x[-1]}" elsif x == x.to_s then puts x end }

n = gets.to_i
a =[]
for i in 0..n-1 do
  a = a + [gets]
  if a[i].size >= 10
    a[i] = (a[i][0] + (a[i].size - 3).to_s + a[i][a[i].size - 2])
  end
end
puts a

x = gets.to_i

def check(j)
	if j.length <= 10
		puts j
	else
		puts j[0] + j.length.to_s + j[-1]
	end
end

for i in 1..x do
	y = gets.chomp
	check(y)
end

x=gets.to_i
x.times do
n=gets.chomp
z=n.length
if z > 10
print n[0]
print z-2
print n[z-1]
else
print n
print "\n"
end
end

b = /[0-9]/
x = gets.chomp
if x.size > 10
  puts "#{x[0]}#{x.size - 2}#{x[-1]}"
elsif x =~ /[0-9]/
 nil
else
  puts x
end

a = gets.to_s
b = a[0]
c = a[-1]
s = a.size
 if s >= 12
 puts b
 puts s
 puts c
 else
 puts a
 end

n = gets.to_i
n.times do |i|
	temp = gets
	if (temp.size < 11)
		puts temp
	else
		k = temp.size - 2
		curr = temp[0] + k.to_s + temp[k]
		puts curr
	end
end

a = gets.to_s
b = a[0]
c = a[-1]
s = a.size
x = s - 2
z = x.to_s
 if x >= 10
 puts b + z + c
 else
 puts a
 end

n = gets.chomp.to_i

n.times do
    s = gets.chomp
    if s.length >= 10
        p "#{s[0]}#{s.length-2}#{s[s.length-1]}"
    else
        p s
    end
end

def abb ()
    n = gets.to_i
  words = Array.new(n)
    for i in 0...n
      word = gets.to_s
      words[i] = word.chomp!
    end
  words.each{ |word|
        if word.length < 10
            puts word
        else
            puts "#{word[0]}#{word.length-2}#{word[-1]}"
        end
  }
end

abb

gets.to_i.times do
  s=gets
  puts s.size>10 ? "#{s[0]}#{s.size-1}#{s[-1]}": s
end


gets.strip.to_i.times {
	n = gets.strip.to_i
	sq = Math.sqrt(n).to_i
	an = []
	sq.times { |i|
		an << i + 1
		an << n / (i + 1)
	}
	an << 0
	an = an.uniq.sort
	puts an.size
	puts an.join(' ')
}

#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

t = inp[0]
t.times do
  n = inp[0]
  ans = []
  (0...((n**0.5).ceil)).each do |d|
    ans.push(d)
  end
  mae = ans[-1]
  (1..((n**0.5).ceil)).reverse_each do |d|
    if n/d > mae
      mae = n/d
      ans.push(mae)
    end
  end
  p ans.size
  puts ans.join(" ")
end

#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

t = inp[0]
t.times do
  n = inp[0]
  mae = 0
  mae = 1
  ans = [0,1]
  (1..((n**0.5).ceil)).reverse_each do |d|
    if n/d > mae
      mae = n/d
      ans.push(mae)
    end
  end
  puts ans.size
  puts ans.join(" ")
end

gets.strip.to_i.times {
	n = gets.strip.to_i
	sq = Math.sqrt(n).to_i
	an = []
	sq.times { |i|
		next if i == 0
		an << i
		an << n / i
	}
	an << 0
	puts an.size
	print an.uniq.sort.join(' ')
}

gets.strip.to_i.times {
	n = gets.strip.to_i
	sq = Math.sqrt(n).to_i
	an = []
	sq.times { |i|
		next if i == 0
		an << i
		an << n / i
	}
	an << 0
	puts an.uniq.sort.join(' ')
}

gets.strip.to_i.times {
	n = gets.strip.to_i
	sq = Math.sqrt(n).to_i
	an = []
	sq.times { |i|
		an << i + 1
		an << n / (i + 1)
	}
	an << 0
	puts an.size
	puts an.uniq.sort.join(' ')
}


t = gets.chomp.to_i
t.times do
  a, b = gets.chomp.split(' ').map(&:to_i)
  s = gets.chomp.split('')
  del = []
  cur = 0
  s.each do |el|
    if el == '1'
      del << cur if cur > 0
      cur = 0
    else
      cur += 1
    end
  end
  del.shift if s[0] == '0'

  sum = a
  del.each do |el|
    sum += [a, b * el].min
  end
  if s.count('1') >= 1
    puts sum
  else
    puts 0
  end
end

t = gets.chomp.to_i
t.times do
    a, b = gets.chomp.split(" ").map(&:to_i)
    x = gets.chomp.split("")
    ookisa = x.size
    dp = Array.new(ookisa+1,Float::INFINITY)
    dp[0] = 0
    cost = 0
    i = 1
    renzoku = 0
    zero = 0
    first = 0
    until x == []
        me = x.shift
        #p me
        #p renzoku
        if me == "1"
           #p renzoku
            if renzoku >= 1
                dp[i] = dp[i-1]
            else
                #p dp
                #p zero
                if first >= 1
                    dp[i] = [zero*b+dp[i-1],dp[i-1]+a].min
                else
                    dp[i] = a
                    first += 1
                end
            end
            # p renzoku
            # p zero
            zero = 0
            renzoku += 1
        else
            zero += 1
            renzoku = 0
            dp[i] = dp[i-1]
        end
        i += 1
        #p zero
        #p dp
    end
    puts dp.pop
end

t = gets.chomp.to_i
t.times do
  a, b = gets.chomp.split(' ').map(&:to_i)
  s = gets.chomp.split('')
  del = []
  cur = 0
  s.each do |el|
    if el == '1'
      del << cur if cur > 0
      cur = 0
    else
      cur += 1
    end
  end
  del.shift if s[0] == '0'

  sum = a
  del.each do |el|
    sum += [a, b * el].min
  end
  if s.count('1') > 1
    puts sum
  else
    puts 0
  end
end

t = gets.chomp.to_i
t.times do
  a, b = gets.chomp.split(' ').map(&:to_i)
  s = gets.chomp.split('')
  del = []
  cur = 0
  s.each do |el|
    if el == '1'
      del << cur if cur > 0
      cur = 0
    else
      cur += 1
    end
  end
  puts "s = " + s.to_s
  del.shift if s[0] == '0'

  sum = a
  del.each do |el|
    sum += [a, b * el].min
  end
  if s.count('1') >= 1
    puts sum
  else
    puts 0
  end
end


gets.to_i.times{
  a=gets.split.map(&:to_i)-[-1]
  ans=a.inject(0,:|)
  print ans.to_s+' '
}

gets.to_i.times{
  a=gets.split.map(&:to_i)-[-1]
  p a.inject(0,:|)
}

gets.to_i.times{
  a=gets.split.map(&:to_i)-[-1]
  ans=a.inject(:|)
  print ans.to_s+' '
}


gets.to_i.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  vis = Array.new(n, false)

  l = 1
  cnt = 1
  max = 1

  num = a[0]
  a_l = 0
  a_r = 0

  n_l = nil
  n_r = 0

  while l < n
    next l += 1 if vis[l-1] && vis[l]
    if a[l-1] == a[l]
      n_l ||= l-1
      n_r = l
      cnt += 1
    else
      if cnt > 1
        r = l
        cnt1 = cnt
        while r < n
          if a[r] == a[n_l]
            vis[r] = true
            cnt1 += 1
          else
            cnt1 -= 1
          end
          if cnt1 > cnt
            cnt = cnt1
            n_r = r
          end
          break if cnt1 <= 0
          r += 1
        end
      end
      if cnt > max
        a_l = n_l
        a_r = n_r
        max = cnt
        num = a[a_l]
      end
      n_l = nil
      n_r = 0
      cnt = 1
    end
    l += 1
  end
  if cnt > max
    a_l = n_l
    a_r = n_r
    max = cnt
    num = a[n_l]
  end

  puts [num, a_l+1, a_r+1].join(" ")
end

main = -> {
    t = int
    t.times do
        n = int
        a = ints

        indices = {}
        a.each_with_index do |x, i|
            (indices[x] ||= []) << i
        end

        ans = 1
        ans_value = [a[0], 1, 1]
        indices.each do |x, row|
            sum = 1
            first = row[0]
            prev = row[0]
            row[1..].each do |i|
                sum = sum - (i - prev) + 2
                prev = i
                # p [x, first, i, sum]
                if sum < 1
                    sum = 1
                    first = i
                end
                if ans < sum
                    ans = sum
                    ans_value = [x, first + 1, i + 1]
                end
            end
        end

        puts ans_value * " "
    end
}

DEBUG = false
MOD = 10**9+7
INF = 10**18
$yesno = %w(No Yes)
$YesNo = %w(No Yes)
$YESNO = %w(NO YES)

require "set"
require "prime"

def int; gets.to_s.to_i end
def ints; gets.to_s.split.map { |s| s.to_i } end
def int1s; gets.to_s.split.map { |s| s.to_i - 1 } end
def float; gets.to_s.to_f end
def floats; gets.to_s.split.map { |s| s.to_f } end
def array_of(&convert); gets.to_s.split.map(&convert) end
def string; gets.to_s.chomp end
def strings; gets.to_s.split end
def rep(n, &b); Array.new(n, &b) end
def yes; puts $yesno[1] end
def no; puts $yesno[0] end
def yesno t; puts $yesno[t ? 1 : 0] end
def YesNo t; puts $YesNo[t ? 1 : 0] end
def YESNO t; puts $YESNO[t ? 1 : 0] end
def zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end
def max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end
def min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end
def minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end
def gcd(*xs); xs.inject(0, :gcd) end
def matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end
def debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end
def debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join("") } if DEBUG; grid end
def if_debug; yield if DEBUG end

module Boolean
  def coerce(other); [other, to_i] end
  def +@; to_i end
  def to_int; to_i end
  def *(other); to_i * other end
end

class TrueClass
  include Boolean
  def to_i; 1 end
end

class FalseClass
  include Boolean
  def to_i; 0 end
end

class Integer
  def div_ceil(y); (self + y - 1) / y end
  def mod_inv(mod = MOD); pow(mod-2, mod) end
  def mod_div(y, mod = MOD); self * y.mod_inv(mod) % mod end
  def mod_nCr(r, mod = MOD); x = y = 1; (1..r).each { |i| x = x * (self + 1 - i) % mod; y = y * i % mod }; x.mod_div(y, mod); end
  def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end
  def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster
  def bitbrute(&block); (1<<self).times(&block) end
  def nCr(r); x = 1; (1..r).each { |i| x *= self + 1 - i; x /= i }; x; end
  def each_divisor; return Enumerator.new { |y| each_divisor { |k| y << k } } unless block_given?; k = 1; while k * k < self; if self % k == 0; yield k; yield self / k end; k += 1; end; yield k if k * k == self end
  def divisors; each_divisor.to_a end
end

class Range
  def end_open; exclude_end? ? self.end : self.end + 1 end
  def end_close; exclude_end? ? self.end - 1 : self.end end
  def upper_bound; ac, wa = self.begin, self.end_open; while wa - ac > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end
  def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end
  def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end
  def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end
end

class Array
  def power(&block); (0 ... 1 << size).each(&block) end
  def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end
  def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end
  def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end
  def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end
  def cumdiff(range); self[range.end_open] - self[range.begin]; end
  def compress(kinds = uniq.sort!); map { |x| kinds.bsearch_index { _1 >= x } }; end
end

module Enumerable
  def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end
  def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end
end

main[]

gets.to_i.times do
  gets
  xs = gets.split.map(&:to_i)
  last = {}
  dp = [0] * xs.size
  xs.each.with_index do |x, i|
    if y = last[x]
      dp[i] = [dp[y] - (i - y) + 2, 1].max
    else
      dp[i] = 1
    end
    last[x] = i
  end
  max = dp.max
  l = r = dp.index(max)
  a = xs[l]
  count = 1
  until count == max
    l -= 1
    count += xs[l] == a ? 1 : -1
  end
  puts "#{a} #{l + 1} #{r + 1}"
end

t = gets.to_i
t.times do
  n = gets.to_i
  x = gets.split.map(&:to_i)
  indices = {}
  x.each_with_index do |a, i|
    (indices[a] ||= []) << i
  end

  ans = 1
  ans_value = [x[0], 1, 1]
  indices.each do |a, row|
    b = [1]
    row.each_cons(2) do |i, j|
      b << (i - j + 1) << 1
    end

    l = 0
    sum = 0
    b.each_with_index do |x, r|
      if sum < 0
        l = r
        sum = x
      else
        sum += x
      end
      if sum > ans
        ans = sum
        ans_value = [a, row[l / 2] + 1, row[r / 2] + 1]
      end
    end
  end

  puts ans_value.join(" ")
end

gets.to_i.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  index = {}

  a.each_with_index do |e, i|
    index[e] ||= []
    index[e] << i
  end

  cnt = 1

  ans = a[0]
  l = 1
  r = 1
  index.each do |k, v|
    sum = 1
    first = v[0]
    prev = v[0]

    v[1..].each do |i|
      sum = sum-(i-prev)+2
      prev = i
      if sum < 1
        sum = 1
        first = i
      end

      if cnt < sum
        cnt = sum
        ans = k
        l = first+1
        r = i+1
      end
    end
  end

  puts [ans, l, r].join(" ")
end

gets.to_i.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  vis = Array.new(n, false)

  l = 1
  cnt = 1
  max = 1

  num = a[0]
  a_l = 0
  a_r = 0

  n_l = nil
  n_r = 0

  while l < n
    next l += 1 if vis[l-1] && vis[l]
    if a[l-1] == a[l]
      n_l ||= l-1
      n_r = l
      cnt += 1
    else
      if cnt > 1
        r = l
        cnt1 = cnt
        while r < n
          if a[r] == a[n_l]
            vis[r] = true
            cnt1 += 1
          else
            cnt1 -= 1
          end
          if cnt1 > cnt
            cnt = cnt1
            n_r = r
          end
          break if cnt1 <= 0
          r += 1
        end
      end
      if cnt > max
        a_l = n_l
        a_r = n_r
        max = cnt
      end
      n_l = nil
      n_r = 0
      cnt = 1
    end
    l += 1
  end
  if cnt > max
    a_l = n_l
    a_r = n_r
    max = cnt
    num = a[n_l]
  end

  puts [num, a_l+1, a_r+1].join(" ")
end

gets.to_i.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  vis = Array.new(n, false)

  l = 1
  cnt = 1
  max = 1

  num = a[0]
  a_l = 0
  a_r = 0

  n_l = nil
  n_r = 0

  while l < n
    next l += 1 if vis[l]
    vis[l] = true

    if a[l-1] == a[l]
      n_l ||= l-1
      n_r = l
      cnt += 1
    else
      if cnt > 1
        r = l
        cnt1 = cnt
        while r < n
          if a[r] == a[l-1]
            vis[r] = true
            cnt1 += 1
          else
            cnt1 -= 1
          end
          if cnt1 > cnt
            cnt = cnt1
            n_r = r
          end
          break if cnt1 <= 0
          r += 1
        end
      end
      if cnt > max
        a_l = n_l
        a_r = n_r
        max = cnt
        num = a[l-1]
      end
      n_l = nil
      n_r = 0
      cnt = 1
    end
    l += 1
  end
  if cnt > max
    a_l = n_l
    a_r = n_r
    max = cnt
    num = a[n_l]
  end

  puts [num, a_l+1, a_r+1].join(" ")
end

gets.to_i.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  vis = Array.new(n, false)

  l = 1
  cnt = 1
  max = 1

  num = a[0]
  a_l = 0
  a_r = 0

  n_l = nil
  n_r = 0

  while l < n
    next l += 1 if vis[l]
    vis[l] = true

    if a[l-1] == a[l]
      n_l ||= l-1
      n_r = l
      cnt += 1
    else
      if cnt > 1
        r = l
        cnt1 = cnt
        while r < n
          if a[r] == a[l-1]
            vis[r] = true
            cnt1 += 1
          else
            cnt1 -= 1
          end
          if cnt1 > cnt
            cnt = cnt1
            n_r = r
          end
          break if cnt1 < 0
          r += 1
        end
      end
      if cnt > max
        a_l = n_l
        a_r = n_r
        max = cnt
        num = a[l-1]
      end
      n_l = nil
      n_r = 0
      cnt = 1
    end
    l += 1
  end
  if cnt > max
    a_l = n_l
    a_r = n_r
    max = cnt
    num = a[n_l]
  end

  puts [num, a_l+1, a_r+1].join(" ")
end

gets.to_i.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  vis = Array.new(n, false)

  l = 1
  cnt = 0
  max = 0
  num = -1

  n_l = nil
  n_r = 0

  a_l = -1
  a_r = -1

  while l < n
    next l += 1 if vis[l]
    vis[l] = true

    if a[l-1] == a[l]
      n_l ||= l-1
      n_r = l
      cnt += 1
    else
      if cnt > 0
        r = l
        cnt1 = cnt
        while r < n
          if a[r] == a[l-1]
            vis[r] = true
            cnt1 += 1
          else
            cnt1 -= 1
          end
          if cnt1 > cnt
            cnt = cnt1
            n_r = r
          end
          break if cnt1 < 0
          r += 1
        end
      end
      if cnt > max
        a_l = n_l
        a_r = n_r
        max = cnt
        num = a[l-1]
      end
      n_l = nil
      n_r = 0
      cnt = 0
    end
    l += 1
  end
  if cnt > max
    a_l = n_l
    a_r = n_r
    max = cnt
    num = a[n_l]
  end

  if n == 1 || num == -1
    num = a[0]
    a_l = 0
    a_r = 0
  end
  puts [num, a_l+1, a_r+1].join(" ")
end

gets.to_i.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  vis = Array.new(n, false)

  l = 1
  cnt = 0
  max = 0
  num = -1

  n_l = nil
  n_r = 0

  a_l = -1
  a_r = -1

  while l < n
    next l += 1 if vis[l]
    vis[l] = true

    if a[l-1] == a[l]
      n_l ||= l-1
      n_r = l
      cnt += 1
    else
      if cnt > 0
        r = l
        cnt1 = cnt
        while r < n
          if a[r] == a[l-1]
            vis[r] = true
            cnt1 += 1
          else
            cnt1 -= 1
          end
          if cnt1 > cnt
            cnt = cnt1
            n_r = r
          end
          break if cnt1 < 0
          r += 1
        end
      end
      if cnt > max
        a_l = n_l
        a_r = n_r
        max = cnt
        num = a[l-1]
      end
      n_l = nil
      n_r = 0
      cnt = 0
    end
    l += 1
  end
  if cnt > max
    a_l = n_l
    a_r = n_r
    max = cnt
    num = a[l-1]
  end
  if n == 1 || num == -1
    num = a[0]
    a_l = 0
    a_r = 0
  end
  puts [num, a_l+1, a_r+1].join(" ")
end

gets.to_i.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  vis = Array.new(n, false)

  l = 1
  cnt = 0
  max = 0
  num = 0

  n_l = nil
  n_r = 0

  a_l = -1
  a_r = -1

  while l < n
    next l += 1 if vis[l]
    vis[l] = true

    if a[l-1] == a[l]
      n_l ||= l-1
      cnt += 1
    else
      if cnt > 0
        r = l
        n_r = r-1
        cnt1 = cnt
        while r < n
          if a[r] == a[l-1]
            vis[r] = true
            cnt1 += 1
          else
            cnt1 -= 1
          end
          if cnt1 > cnt
            cnt = cnt1
            n_r = r
          end
          break if cnt1 < 0
          r += 1
        end
      end
      if cnt > max
        a_l = n_l
        a_r = n_r
        max = cnt
        num = a[l-1]
      end
      n_l = nil
      n_r = 0
      cnt = 0
    end
    l += 1
  end
  if n == 1 || a_l == -1
    num = a[0]
    a_l = 0
    a_r = 0
  end
  puts [num, a_l+1, a_r+1].join(" ")
end

t = gets.to_i
t.times do
  n = gets.to_i
  x = gets.split.map(&:to_i)
  indices = {}
  x.each_with_index do |a, i|
    (indices[a] ||= []) << i
  end

  ans = 1
  ans_value = [x[0], 1, 1]
  indices.each do |a, row|
    b = [1]
    row.each_cons(2) do |i, j|
      b << (i - j + 1) << 1
    end

    l = 0
    sum = 1
    b.each_with_index do |x, r|
      if sum < 0
        l = r
        sum = x
      else
        sum += x
      end
      if sum > ans
        ans = sum
        ans_value = [a, row[l / 2] + 1, row[r / 2] + 1]
      end
    end
  end

  p ans
  puts ans_value.join(" ")
end

t = gets.to_i
t.times do
  n = gets.to_i
  x = gets.split.map(&:to_i)
  indices = {}
  x.each_with_index do |a, i|
    (indices[a] ||= []) << i
  end

  ans = 1
  ans_value = [x[0], 1, 1]
  indices.each do |a, row|
    b = [1]
    row.each_cons(2) do |i, j|
      b << (i - j + 1) << 1
    end

    l = 0
    sum = 1
    b.each_with_index do |x, r|
      if sum < 0
        l = r
        sum = x
      else
        sum += x
      end
      if sum > ans
        ans = sum
        ans_value = [a, row[l / 2] + 1, row[r / 2] + 1]
      end
    end
  end

  puts ans_value.join(" ")
end

t = gets.to_i
t.times do
  n = gets.to_i
  x = gets.split.map(&:to_i)
  indices = {}
  x.each_with_index do |a, i|
    (indices[a] ||= []) << i
  end

  ans = 0
  ans_value = nil
  indices.each do |a, row|
    b = [1]
    row.each_cons(2) do |i, j|
      b << (i - j + 1) << 1
    end

    l = 0
    sum = 1
    b.each_with_index do |x, r|
      if sum < 0
        l = r
        sum = x
      else
        sum += x
      end
      if sum > ans
        ans = sum
        ans_value = [a, row[l / 2] + 1, row[r / 2] + 1]
      end
    end
  end

  puts ans_value.join(" ")
end

t = gets.to_i
t.times do
  n = gets.to_i
  x = gets.split.map(&:to_i)
  indices = {}
  x.each_with_index do |a, i|
    (indices[a] ||= []) << i
  end

  ans = 0
  ans_value = nil
  indices.each do |a, row|
    b = [1]
    row.each_cons(2) do |i, j|
      b << (j - i + 1) << 1
    end

    l = 0
    sum = 1
    b.each_with_index do |x, r|
      if sum < 0
        l = r
	sum = x
      else
        sum += x
      end
      if sum > ans
        ans = sum
	ans_value = [a, row[l / 2] + 1, row[r / 2] + 1]
      end
    end
  end

  puts ans_value.join(" ")
end


# coding: utf-8

# if __FILE__ == $0
# end
C = Struct.new(:x, :y)
t = gets.to_i
t.times {
    n = gets.to_i
    ar = []
    n.times {
        ar << C.new(*gets.split.map(&:to_i))
    }
    ar.sort! { |a, b|
        if a.x != b.x
            a.x - b.x
        else
            a.y - b.y
        end
    }
    possible = true
    commands = []
    cx, cy = 0, 0
    ar.each { |c|
        # p ar
        if cx <= c.x && cy <= c.y
            # lexicographical move
            # ABCDEFG.....OPQ'R'ST'U'
            # R first, U last
            commands << 'R'*(c.x-cx)
            commands << 'U'*(c.y-cy)
            cx = c.x
            cy = c.y
        else
            possible = false
            break
        end
    }

    if possible
        puts "YES"
        puts commands.join('')
    else
        puts "NO"
    end
}

#!usr/bin/env ruby

# https://codeforces.com/contest/1294/problem/B

require 'set'

n = gets.to_i

n.times do
 size = gets.to_i
 pkgs = {}
 size.times do
  cords = gets.split(' ').map(&:to_i)

  pkgs[cords[0]] ||= []
  pkgs[cords[0]] << cords[1]
 end

 x = y = 0
 answer = ""
 failed = false

 while !pkgs.empty? do
  if pkgs[x].nil?
   x += 1
   answer += "R"
  else
   mini = pkgs[x].min
   maxi = pkgs[x].max

   if mini < y
    failed = true
    break
   else
    answer += "U" * (maxi - y)
    y = maxi
    pkgs.delete x
   end
  end
 end

 if failed
  puts "NO"
 else
  puts "YES"
  puts answer
 end
end

#!usr/bin/env ruby

# https://codeforces.com/contest/1294/problem/B

n = gets.to_i

n.times do
 size = gets.to_i
 pkgs = {}
 size.times do
  cords = gets.split(' ').map(&:to_i)

  pkgs[cords[0]] ||= []
  pkgs[cords[0]] << cords[1]
 end

 x = y = 0
 answer = ""
 failed = false

 while !pkgs.empty? do
  if pkgs[x].nil?
   x += 1
   answer += "R"
  else
   mini = maxi = y

   pkgs[x].each do |val|
    mini = val if val < mini
    maxi = val if val > maxi
   end

   if mini < y
    failed = true
    break
   else
    answer += "U" * (maxi - y)
    y = maxi
    pkgs.delete x
   end
  end
 end

 if failed
  puts "NO"
 else
  puts "YES"
  puts answer
 end
end

#!usr/bin/env ruby

# https://codeforces.com/contest/1294/problem/B

n = gets.to_i

n.times do
 size = gets.to_i
 pkgs = []
 size.times do
  pkgs << gets.split(' ').map(&:to_i)
 end

 pkgs.sort!

 x = y = 0
 failed = false
 answer = ""

 pkgs.each do |p|
  dx = p[0] - x
  dy = p[1] - y

  if dx < 0 || dy < 0
   failed = true
   break
  else
   answer += "R" * dx + "U" * dy
   x = p[0]
   y = p[1]
  end
 end

 if failed
  puts "NO"
 else
  puts "YES"
  puts answer
 end
end

T = gets.to_i

T.times do
  n = gets.to_i

  packages = n.times.map { gets.split.map(&:to_i) }

  packages.sort_by! { |x, y| [x, y] }

  ans = ''
  cx = 0
  cy = 0
  success = true

  packages.each do |x, y|
    dx = x - cx
    dy = y - cy

    if dx < 0 || dy < 0
      success = false
      break
    end

    ans += 'R' * dx + 'U' * dy
    cx = x
    cy = y
  end

  if success
    puts 'YES'
    puts ans
  else
    puts 'NO'
  end
end

# coding: utf-8

# if __FILE__ == $0
# end
C = Struct.new(:x, :y)
t = gets.to_i
t.times {
    n = gets.to_i
    ar = []
    n.times {
        ar << gets.chomp
    }
    ar.sort!
    possible = true
    commands = []
    cx, cy = 0, 0
    ar.each { |c|
        x, y = c.split.map(&:to_i)
        if cx <= x && cy <= y
            commands << 'R'*(x-cx)
            commands << 'U'*(y-cy)
            cx = x
            cy = y
        else
            possible = false
            break
        end
    }

    if possible
        puts "YES"
        puts commands.join('')
    else
        puts "NO"
    end
}


def solve
  n, m, x, y = gets.strip.split(' ').map(&:to_i)
  an = 0
  n.times {
    str = gets.strip.split('')
    count = 0
    str.each_with_index { |e, i|
      if e == '.' && i < str.size - 1
        count += 1
      else
        count += 1 if e == '.'
        two = (count / 2).floor
        if two * y < two * 2 * x && !two.zero?
          an += (two * y)
        else
          an += (two * 2 * x)
        end
        an += x if count.odd?
        count = 0
      end
    }
  }
  puts an
end

gets.strip.to_i.times { solve }

  q = gets.chomp.to_i

  q.times {

    n, m, x, y = gets.split.map(&:to_i)

    table = []
    n.times {
      row = gets.chomp
      table << row
    }

    d = []
    n.times { |i|
      d << []
      m.times {
        d[i] << 0
      }
    }

    n.times { |i|
      m.times { |j|

        if j == 0

          if table[i][j] == '.'
            d[i][j] = x
          end

          next
        end

        d[i][j] = d[i][j - 1]

        if table[i][j] == '*'
          next
        end

        d[i][j] = d[i][j - 1] + x

        if table[i][j - 1] == '.'
          curVal = 0
          if j == 1
            curVal = y
          else
            curVal = d[i][j - 2] + y
          end

          d[i][j] = [d[i][j], curVal].min
        end
      }
    }

    sum = 0
    d.each { |row|
      sum += row.last
    }

    puts sum
  }

def solve
  n, m, x, y = gets.strip.split(' ').map(&:to_i)
  an = 0
  n.times {
    str = gets.strip.split('')
    count = 0
    str.each_with_index { |e, i|
      if e == '.' && i < str.size - 1
        count += 1
      else
        count += 1 if e == '.'
        two = (count / 2).floor
        if two * y < two * 2 * x && !two.zero?
          an += (two * y)
        else
          an += (two * 2 * x)
          an += x if count.odd?
        end
        count = 0
      end
    }
  }
    puts an
end

gets.strip.to_i.times { solve }

def solve
  n, m, x, y = gets.strip.split(' ').map(&:to_i)
  an = 0
  n.times {
    str = gets.strip.split('')
    count = 0
    str.each_with_index { |e, i|
      if e == '.' && i < str.size - 1
        count += 1
      else
        count += 1 if e == '.'
        two = (count / 2).to_i
        if two * y < count * x && !two.zero?
          an += (two * y)
        else
          an += (count * x)
        end
        count = 0
      end
    }
  }
    puts an
end

gets.strip.to_i.times { solve }

def solve
  n, m, x, y = gets.strip.split(' ').map(&:to_i)
  an = 0
  n.times {
    str = gets.strip.split('')
    count = 0
    str.each_with_index { |e, i|
      if e == '.' && i < str.size - 1
        count += 1
      else
        count += 1 if e == '.'
        two = (count / 2).to_i
        if two * y < two * 2 * x && !two.zero?
          an += (two * y)
        else
          an += (two * 2 * x)
          an += x if count.odd?
        end
        count = 0
      end
    }
  }
    puts an
end

gets.strip.to_i.times { solve }

def solve
  n, m, x, y = gets.strip.split(' ').map(&:to_i)
  an = 0
  n.times {
    str = gets.strip.split('')
    count = 0
    p str
    str.each_with_index { |e, i|
      if e == '.' && i < str.size - 1
        count += 1
      else
        count += 1 if e == '.'
        two = (count / 2).to_i
        if two * y < count * x && !two.zero?
          an += (two * y)
        else
          an += (count * x)
        end
        count = 0
      end
    }
  }
    puts an
end

gets.strip.to_i.times { solve }


n, m=gets.split.map &:to_i
a=gets.split.map &:to_i
b=gets.split.map &:to_i
p (0...n).map{|i|b.map{|x| (0...n).select{|j|i!=j}.map{|j|a[j]*x}.max}.max}.min

n,m=gets.split.map &:to_i
a=gets.split.map &:to_i
b=gets.split.map &:to_i
tat=1
res=-1e18
for i in 0..n-1
  for j in 0..m-1
    if a[i]*b[j]>res
      res=a[i]*b[j]
      tat=i
    end
  end
end
res=-1e18.to_i
a[tat]=a[n-1]
for i in 0..n-2
  for j in b
    res=[res,a[i]*j].max
  end
end
p res

n, m=gets.split.map &:to_i
a=gets.split.map &:to_i
b=gets.split.map &:to_i
p (0...n).map{ |i|
b.map{|x|
(0...n).select{ |j| i!=j }.map{|j|a[j]*x}.max}.max}.min

n,m=gets.split.map &:to_i
a=gets.split.map &:to_i
b=gets.split.map &:to_i
if a[0]==-1000000000
  p b[0]
end
tat=1
res=-1e18
for i in 0..n-1
  for j in 0..m-1
    if a[i]*b[j]>res
      res=a[i]*b[j]
      tat=i
    end
  end
end
res=-1e18
a[tat]=0
for i in a
  for j in b
    res=[res,i*j].max
  end
end
p res

n,m=gets.split.map &:to_i
a=gets.split.map &:to_i
b=gets.split.map &:to_i
tat=1
res=-1e18
for i in 0..n-1
  for j in 0..m-1
    if a[i]*b[j]>res
      res=a[i]*b[j]
      tat=i
    end
  end
end
res=-1e18
a[tat]=0
for i in a
  for j in b
    res=[res,i*j].max
  end
end
p res

n,m=gets.split.map &:to_i
a=gets.split.map &:to_i
b=gets.split.map &:to_i
tat=1
res=-1e9
for i in 0..n-1
  for j in 0..m-1
    if a[i]*b[j]>res
      res=a[i]*b[j]
      tat=i
    end
  end
end
res=-1e9
a[tat]=0
for i in a
  for j in b
    res=[res,i*j].max
  end
end
p res

n,m=gets.split.map &:to_i
a=gets.split.map &:to_i
b=gets.split.map &:to_i
if a[0]==-1000000000
  p b[0]
end
tat=1
res=-1e18
for i in 0..n-1
  for j in 0..m-1
    if a[i]*b[j]>res
      res=a[i]*b[j]
      tat=i
    end
  end
end
res=-1e18
a[tat]=a[n-1]
for i in 0..n-2
  for j in b
    res=[res,a[i]*j].max
  end
end
p res

n,m=gets.split.map &:to_i
a=gets.split.map &:to_i
b=gets.split.map &:to_i
tat=1
res=-1e18
for i in 0..n-1
  for j in 0..m-1
    if a[i]*b[j]>res
      res=a[i]*b[j]
      tat=i
    end
  end
end
res=-1e18
a[tat]=a[n-1]
for i in 0..n-2
  for j in b
    res=[res,a[i]*j].max
  end
end
p res

n,m=gets.split.map &:to_i
a=gets.split.map &:to_i
b=gets.split.map &:to_i
tat=1
res=-1e18
for i in 0..n-1
  for j in 0..m-1
    if a[i]*b[j]>res
      res=a[i]*b[j]
      tat=i
    end
  end
end
res=-1e18
a[tat]=0
for i in a
  for j in b
    if i!=tat
    res=[res,i*j].max
    end
  end
end
p res

n,m=gets.split.map &:to_i
a=gets.split.map &:to_i
b=gets.split.map &:to_i
if a[0]==-1000000000
  p b[0]
end
tat=1
res=-1e18
for i in 0..n-1
  for j in 0..m-1
    if a[i]*b[j]>res
      res=a[i]*b[j]
      tat=i
    end
  end
end
res=-1e18.to_i
a[tat]=a[n-1]
for i in 0..n-2
  for j in b
    res=[res,a[i]*j].max
  end
end
p res

n, m=gets.split.map &:to_i
a=gets.split.map &:to_i
b=gets.split.map &:to_i
a.delete a.max
puts a.max * b.max

n, m=gets.split.map &:to_i
a=gets.split.map &:to_i
b=gets.split.map &:to_i
a.sort!
puts a[n-2] * b.max