#!/usr/bin/ruby
r=m=1
gets
gets.split.map(&:to_i).each_cons(2){|x,y|
	m=x>y ? 1 : m+1
	r=[r,m].max
}
p r

gets
count=1
mx = 0
gets.split(' ').map(&:to_i).each_cons(2){|x,y|
    if x>y
        mx = [mx,count].max
        count =1
    else
        count+=1
    end
}
p [count,mx].max

n = gets
li = gets.split(' ').map(&:to_i)
count=1
mx = 0
for i in 1...li.length
    if li[i]>=li[i-1]
        count+=1
    else
        mx = [count,mx].max
        count=1
    end
end
puts [count,mx].max

n = gets.to_i
numbers = gets.split(' ').map!(&:to_i)
arr = Array.new(numbers.size, 1)
(numbers.size-1).times do |i|
    number = numbers[i+1]
    if number >= numbers[i]
        arr[i]+=arr[i-1]
    end
end
puts arr.max

n = gets.chomp.to_i
arr = gets.chomp.split(" ").map{|val| val = val.to_i}
curmax = 1
cur = 1
arr.each_with_index do |val,i|
	if i != 0 && val >= arr[i-1]
		cur += 1
	elsif cur > curmax
		curmax = cur
		cur = 1
	else
		cur = 1
	end
end
if cur > curmax
	curmax = cur
end
puts curmax

n = gets.chomp.to_i() - 1;
a = gets.chomp.split.map(&:to_i);
ans = 1;
max = 1;
(1..n).each do |x|
  if (a[x] >= a[x - 1])
      ans += 1;
      max = [max, ans].max;
  else
    ans = 1;
  end
end
p max;

def solution(earnings)

  front = 0
  tail = 0
  max_days = 0
  last_earning = earnings[0]

  for i in 0...earnings.size do
    front += 1
    tail = i if last_earning > earnings[i]
    max_days = [max_days, front - tail].max
    last_earning = earnings[i]
  end

  max_days
end

n = gets()
earnings = gets.strip.split.map { |i| i.to_i }
puts solution(earnings)

n = gets.strip.to_i
arr = gets.strip.split(" ").map(&:to_i)
i = 1
max_length = 1
count = 1
while (i < n) do
  if arr[i] >= arr[i-1] then
    count += 1
  else
    count = 1
  end
  max_length = [count, max_length].max
  i += 1
end
puts max_length

arrSize = gets.chomp.to_i
arr = gets.chomp.split

cnt = 1
i = 0
res =0

while i < (arr.length - 1)
  if arr[i].to_i <= arr[i+1].to_i
    cnt = cnt + 1
  else
    cnt = 1
  end
  if res < cnt
    res = cnt
  end
  i = i +1
end

if  arrSize.to_i == 1
  print arrSize.to_i
else
  print res
end

n = $stdin.gets.to_i
a = $stdin.gets.split.map(&:to_i)

prev = a.first
l = 1
maxl = 1
for i in 1...n do
    cur = a[i]
    if cur >= prev then
        l += 1
    else
        if l >= maxl then
            maxl = l
        end
        l = 1
    end
    prev = cur
end

if l >= maxl then
    maxl = l
end

puts maxl

n = gets.to_i
a = gets.split(" ")
cur = 0
best = 1
(1..n-1).each { |i|
  if a[i-1].to_i<=a[i].to_i
    if best<i-cur+1
      best=i-cur+1
    end
  else
    cur = i
  end
}
puts best

=begin
string = "foobar"
puts "The string '#{string}' is nonempty." unless string.empty?

puts "foo bar     baz".split
a = [42, 8, 17]
puts '['+a.join(', ')+']'
b = []
(1..5).each do |i|
  b[i] = 2*i
end
puts b

c = %w[a b c]
puts '["'+c.join('", "')+'"]'

user = { :name => "Michael Hartl", :email => "michael@example.com" }
puts user[:name]
puts user[:password]

def pow(x, y)
  p = 1
  y.times{p *= x}
  return p
end
z = pow(3,4)
puts z
=end

n = gets.to_i
a = gets.split.map(&:to_i)
mx, j = 1, 1
(n - 1).times do |i|
  if a[i] <= a[i + 1]
    j += 1
  else
    mx = [mx, j].max
    j = 1
  end
end
p [mx, j].max

a=gets.chomp.to_i
b=gets.chomp.split(" ")
max=1
temp=b[0].to_i
maray=[]
1.upto(a-1) do |i|
if b[i].to_i<temp
maray << max
max=0
end
temp=b[i].to_i
max+=1
end
maray<<max
maray.sort!
puts "#{maray[maray.length-1]}"

gets
x=gets.split.map{|e| e.to_i}
o=x[0]
c=1
ans=1
1.upto(x.size-1){|i|
	if o<=x[i] then
		c=c+1
	else
		c=1
	end
	ans=[ans,c].max
	o=x[i]
}
puts ans

# https://codeforces.com/problemset/problem/580/A
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)

max = 1
i = 1
last = a[0]
sum = 1
while(i < a.length)
    if a[i] >= last
        sum += 1
        max = sum if sum > max
    else
        sum = 1
    end
    last = a[i]
    i += 1
end

puts max

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

result = a.each_with_object({prev: 0, max: 0, step: 0}) do |i, o|
  if i >= o[:prev]
    o[:step] += 1
    o[:max] = [o[:max], o[:step]].max
  else
    o[:step] = 1
  end
  o[:prev] = i
end

p result[:max]

number = STDIN.gets.to_i
numbers = STDIN.gets

numbers = numbers.split(' ').map{|x| x.to_i}

unoozable = 1;
maxunoozable = 1;

0.upto(number-1) do |i|
  if i>0
    if numbers[i] >= numbers[i-1]

    unoozable+=1;
    else

      if unoozable > maxunoozable
        maxunoozable = unoozable;

      end
      unoozable = 1;

    end
  else
    unoozable = 1

  end
end
if unoozable > maxunoozable
  maxunoozable = unoozable;

end
puts maxunoozable

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

arr = []
i = 0
if n == 1
	print 1
else
while i < n-1
	count = 1
	x = i
	while a[x] <= a[x+1]
		count += 1
		x += 1
		if x == n-1
			break
		end
	end
	arr << count
	if count == 1
		i += 1
	elsif x <= n-2
		i = x
	else
		break
	end
end
print arr.max
end

n = gets.to_i
arr = gets.split.map(&:to_i)
ans = 1
l = 1

for i in 1..n-1
  if arr[i] >= arr[i-1]
    l += 1
  else
    l = 1
  end
  ans = [l,ans].max
end

puts ans

n = gets.to_i
a = gets.split.map(&:to_i)
dp = [1]
(1...n).each do |i|
  dp[i] = a[i] >= a[i-1] ? dp[i-1]+1 : 1
end
puts dp.max

def read_int
	c = 0
	while c < 48 || c > 57 do
		c = $stdin.readbyte
	end
	ret = 0
	while c >= 48 && c <= 57 do
		ret = (ret << 3) + (ret << 1) + c - 48
		c = $stdin.readbyte
	end

	ret
end

n = gets.to_i
# a = gets.split.map { |s| s.to_i }
a = []
n.times do
	a << read_int
end

tmp = 1
ans = 1
(1...n).each do |i|
	if a[i] < a[i - 1]
		tmp = 1
	else
		tmp = tmp + 1
		ans = [ans, tmp].max
	end
end

puts ans

def read_int
	c = 0
	while c < 48 || c > 57 do
		c = $stdin.readbyte
	end
	ret = 0
	while c >= 48 && c <= 57 do
		ret = ret * 10 + c - 48
		c = $stdin.readbyte
	end

	ret
end

n = gets.to_i
# a = gets.split.map { |s| s.to_i }
a = []
n.times do
	a << read_int
end

tmp = 1
ans = 1
(1...n).each do |i|
	if a[i] < a[i - 1]
		tmp = 1
	else
		tmp = tmp + 1
		ans = [ans, tmp].max
	end
end

puts ans

n = gets.to_i
a = gets.split.map { |s| s.to_i }

tmp = 1
ans = 1
(1...n).each do |i|
	if a[i] < a[i - 1]
		tmp = 1
	else
		tmp = tmp + 1
		ans = [ans, tmp].max
	end
end

puts ans

def read_int
	c = ?\0
	while c < '0' || c > '9' do
		c = $stdin.readchar
	end
	ret = 0
	while c >= '0' && c <= '9' do
		ret = ret * 10 + (c.ord - '0'.ord)
		c = $stdin.readchar
	end

	ret
end

n = gets.to_i
# a = gets.split.map { |s| s.to_i }
a = []
n.times do
	a << read_int
end

tmp = 1
ans = 1
(1...n).each do |i|
	if a[i] < a[i - 1]
		tmp = 1
	else
		tmp = tmp + 1
		ans = [ans, tmp].max
	end
end

puts ans

dayNumber = gets.chomp.to_i
input = gets.chomp.split(' ').map {|item| item.to_i}
ans = 1
best = 1
for i in (0...(input.length - 1))
	#puts "ans : #{ans}"
	ans += 1 if input[i] <= input[i + 1]
	ans = 1 if input[i] > input[i + 1]
	best = ans if best <= ans
end

puts best

n = gets.to_i
m = gets.split.map(&:to_i)
j=0;max=0
if n == 1
    p 1
else
for i in(1..(n-1))
    if(m[i]<m[i-1])
        if(i-j>max)
            max=i-j
        end
        j=i
    end
end
if i+1-j>max
    max = i+1-j
end
p max
end

n = gets.chomp.to_i
str_arr = gets.chomp.split
int_arr = str_arr.map(&:to_i)

prev = -1
max = 1
streak = 0
int_arr.each do |val|
    if val >= prev
        streak += 1
    else
        streak = 1
    end

    prev = val
    max = [max, streak].max
end

puts max

n = gets.chomp.to_i() - 1;
a = gets.chomp.split.map(&:to_i);
ans = 1;
max = -1;
(1..n).each do |x|
  if (a[x] >= a[x - 1])
      ans += 1;
      max = [max, ans].max;
  else
    ans = 1;
  end
end
p max;

n = gets.strip.to_i
arr = gets.strip.split(" ").map(&:to_i)
i = 1
max_length = 0
count = 1
while (i < n) do
  if arr[i] >= arr[i-1] then
    count += 1
  else
    count = 1
  end
  max_length = [count, max_length].max
  i += 1
end
puts max_length

n = gets.strip.to_i
arr = gets.strip.split(" ").map(&:to_i)
i = 1
max_length = 0
count = 1
while (i < n) do
  if count == 0 then
    count += 1
  elsif arr[i] >= arr[i-1] then
    count += 1
  else
    count = 0
  end
  max_length = [count, max_length].max
  i += 1
end
puts max_length

n = gets.to_i
a = gets.split(" ")
cur = 0
best = 1
(1..n-1).each { |i|
  if a[i-1].to_i<a[i].to_i
    if best<i-cur+1
      best=i-cur+1
    end
  else
    cur = i
  end
}
puts best

=begin
string = "foobar"
puts "The string '#{string}' is nonempty." unless string.empty?

puts "foo bar     baz".split
a = [42, 8, 17]
puts '['+a.join(', ')+']'
b = []
(1..5).each do |i|
  b[i] = 2*i
end
puts b

c = %w[a b c]
puts '["'+c.join('", "')+'"]'

user = { :name => "Michael Hartl", :email => "michael@example.com" }
puts user[:name]
puts user[:password]

def pow(x, y)
  p = 1
  y.times{p *= x}
  return p
end
z = pow(3,4)
puts z
=end

gets
x=gets.split.map{|e| e.to_i}
o=x[0]
c=1
ans=0
1.upto(x.size-1){|i|
	if o<=x[i] then
		c=c+1
	else
		c=1
	end
	ans=[ans,c].max
	o=x[i]
}
puts ans

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

arr = []
i = 0
while i < n-1
	count = 1
	x = i
	while a[x] <= a[x+1]
		count += 1
		x += 1
		if x == n-1
			break
		end
	end
	arr << count
	if count == 1
		i += 1
	elsif x <= n-2
		i = x
	else
		break
	end
end
print arr.max

def solution(earnings)

  front = 0
  tail = 0
  max_days = 0
  last_earning = earnings[0]

  for i in 1...earnings.size do
    front = i + 1
    tail = i if last_earning > earnings[i]
    max_days = [max_days, front - tail].max
    last_earning = earnings[i]
  end

  max_days
end

n = gets()

earnings = gets.strip.split.map { |i| i.to_i }
puts solution(earnings)

arrSize = gets.chomp.to_i
arr = gets.chomp.split

cnt = 1
i = 0
cntArr = []

while i < (arr.length - 1)
  if arr[i].to_i <= arr[i+1].to_i
    cnt = cnt + 1
  else
    cntArr.push cnt
    cnt = 1
  end
  i = i +1
end

if cntArr.empty?()
  print cnt
else
  print cntArr.max
end

arrSize = gets.chomp.to_i
arr = gets.chomp.split

cnt = 1
i = 0
res =0

while i < (arr.length - 1)
  if arr[i].to_i <= arr[i+1].to_i
    cnt = cnt + 1
  else
    cnt = 1
  end
  if res < cnt
    res = cnt
  end
  i = i +1
end

print res

n = gets.to_i
m = gets.split.map(&:to_i)
j=0;max=0
for i in(1..(n-1))
    if(m[i]<m[i-1] && i-j>max)
        max=i-j
        j=i
    end
end
if i-j+1>max
    max = i-j+1
end
p max

n = gets.to_i
ans = 1
l = 1
num = gets.to_i

for i in 2..n
  x = gets.to_i

  if x >= num
    l += 1
  else
    l = 1
  end
  ans = [l,ans].max
  num = x
end

puts ans

dayNumber = gets.chomp.to_i
input = gets.chomp.split(' ').map {|item| item.to_i}
index = 0
ans = 1
best = 0
for i in (0...(input.length - 1))
	#puts "ans : #{ans}"
	ans += 1 if input[i] <= input[i + 1]
	ans = 1 if input[1] > input[i + 1]
	best = ans if best <= ans
end

puts best

dayNumber = gets.chomp.to_i
input = gets.chomp.split(' ').map {|item| item.to_i}
index = 0
ans = 0
best = 0
for i in (0...(input.length - 1))
	#puts "ans : #{ans}"
	ans += 1 if input[i] <= input[i + 1]
	ans = 0 if input[1] > input[i + 1]
	best = ans if best < ans
end

puts best + 1

dayNumber = gets.chomp.to_i
input = gets.chomp.split(' ').map {|item| item.to_i}
ans = 1
best = 0
for i in (0...(input.length - 1))
	#puts "ans : #{ans}"
	ans += 1 if input[i] <= input[i + 1]
	ans = 1 if input[i] > input[i + 1]
	best = ans if best <= ans
end

puts best


#!/usr/bin/ruby
count = gets.chop.to_i
laptops = Array.new(count){Array.new(5)}
i = 0
while line = gets
	line.chomp!
	laptop = line.split(' ')
	laptops[i][0] = laptop[0].to_i
        laptops[i][1] = laptop[1].to_i
        laptops[i][2] = laptop[2].to_i
        laptops[i][3] = laptop[3].to_i
	laptops[i][4] = 1;
	i = i+1
end
for i in 0..laptops.count-1
	for i2 in 0..laptops.count-1
		trues = 0
		for i3 in 0..2
			if laptops[i][i3] < laptops[i2][i3]
				trues = trues+1
			end
		end
		if trues == 3
			laptops[i][4] = 0
			#puts "vyhozen " + i.to_s
			break
		end
	end
end
for a in  0..laptops.count-1
        if laptops[a][4] == 1
                min = a;
		break
        end
end
#puts min.to_s
for a in 0..laptops.count-1
	if laptops[a][3] < laptops[min][3]
		if laptops[a][4] == 1
			min = a;
		end
	end
	#puts min.to_s
end
puts (min+1).to_s

#$stdin = File.open("./input", "r")

Notebook = Struct.new(:id, :speed, :ram, :hdd, :cost)

n=gets.to_i

data=[]
n.times{|i|
	speed, ram, hdd, cost=gets.split.map(&:to_i)
	id=i+1
	data << Notebook.new(id, speed, ram , hdd, cost)
}

n.times{|i|
	n.times{|j|
		next if i==j || data[i].nil? || data[j].nil?

		a, b = data[i], data[j]

		if a.speed<b.speed && a.ram<b.ram && a.hdd<b.hdd
			data[i]=nil
		end
	}
}

puts data.keep_if{|v| !v.nil?}.sort!{|a,b| (a.cost<b.cost)?-1:1}[0].id

class Comp
  attr_accessor :hdd, :ram, :cpu, :cost, :id

  def greater_than(other)
    if (@hdd > other.hdd and @ram > other.ram and @cpu > other.cpu)
      return true
    end
    return false
  end
end

comps = Hash.new
count = gets.to_i
count.times { |i|
  cpus, rams, hdds, costs = gets.chop.split(/\s+/)
  comp = Comp.new
  comp.hdd = hdds.to_i
  comp.cpu = cpus.to_i
  comp.ram = rams.to_i
  comp.cost = costs.to_i
  comp.id = i+1
  comps[comp.id] = comp
}
lastCount = 0
currCount = count
while (lastCount != currCount) do
  lastCount = comps.length

  comps.each { |id1, comp1|
    comps.each { |id2, comp2|
      if (id1 != id2 and comp1 != nil and comp2 != nil)
        if (comp1.greater_than(comp2))
          comps[id2] = nil
        elsif (comp2.greater_than(comp1))
          comps[id1] = nil
        end
      end
    }
  }
  currCount = comps.length
 # p comps
end

mincomp = nil
comps.each { |id, comp|
  if comp != nil
    if (mincomp == nil)
      mincomp = comp
    end
    if (comp.cost < mincomp.cost)
      mincomp = comp
    end
  end
}

puts mincomp.id

def choosing_laptop
  specs = []
  gets.to_i.times do
    specs << gets.split(' ').map{|i| i.to_i}
  end

  (0...specs.size).each do |i|
    (0...specs.size).each do |j|
      next if specs[j].nil? or specs[i].nil?

      if specs[i][0] > specs[j][0] and specs[i][1] > specs[j][1] and specs[i][2] > specs[j][2]
        specs[j] = nil
      end
    end
  end

  min = min_ind = nil
  (0...specs.size).each do |i|
    next if specs[i].nil?

    if min.nil? or specs[i][3] < min
      min, min_ind = specs[i][3], i
    end
  end

  puts min_ind+1
end

choosing_laptop

#!/usr/bin/env ruby

n = gets.chomp.to_i
arr = []
n.times do |i|
    arr.push gets.chomp.split(/ /).map{|n| n.to_i} + [i+1]
end

n.times do |i|
    n.times do |j|
        if arr[i][0] < arr[j][0] and arr[i][1] < arr[j][1] and arr[i][2] < arr[j][2]
            arr[i][4] = 0
        end
    end
end

puts arr.select{|a| a[4] != 0}.min{|a,b| a[3] <=> b[3]}[4]

#!/usr/bin/env ruby

n = gets.chomp.to_i
arr = []
n.times do |i|
    arr.push gets.chomp.split(/ /).map{|n| n.to_i} + [i+1]
end

n.times do |i|
    n.times do |j|
        if arr[i][0] < arr[j][0] and arr[i][1] < arr[j][1] and arr[i][2] < arr[j][2]
            arr[i][4] = 0
        end
    end
end

id = 0
minv = 10000
arr.select{|a| a[4] != 0}.each do |a|
    if a[3] < minv
        minv = a[3]
        id = a[4]
    end
end
puts id

laptops=[]
gets.to_i.times{laptops<<gets.split.map(&:to_i)}
l=laptops.each_with_index.to_a.map.sort_by{|(a,b,c,d),i|d}
l.each_with_index{|((a,b,c,d),i),j|
	if l[j+1..-1].any?{|(aa,bb,cc,dd),ii|aa>a&&bb>b&&cc>c&&dd>d}
		next
	else
		puts i+1
		break
	end
}

#!/usr/bin/env ruby

n = STDIN.gets.to_i
laptops=[]
n.times do
  laptops << STDIN.gets.split(" ").map {|i| i.to_i}
end

flag = (0..n-1).map {|i| true}
(laptops.length-1).times do |i|
  (i+1..laptops.length-1).each do |j|
    flag[i] = nil if laptops[i][0] < laptops[j][0] and laptops[i][1] < laptops[j][1] and laptops[i][2] < laptops[j][2]
    flag[j] = nil if laptops[j][0] < laptops[i][0] and laptops[j][1] < laptops[i][1] and laptops[j][2] < laptops[i][2]
  end
end

min = 10000
id = 0
flag.length.times do |i|
  #p [i,flag[i]]
  if flag[i] and laptops[i][3] < min
    #p [i,flag[i]]
      id = i
      min = laptops[i][3]
  end
end
puts id+1

gets; laptops, old = STDIN.read.split("\n").map {|l| l.split.map! &:to_i }, []

laptops.each do |l|
  laptops.each do |a|
    (old.push l; break) if l[0] < a[0] && l[1] < a[1] && l[2] < a[2]
  end
end

min = 1001
(laptops - old).each { |l| min = l[3] if l[3] < min }

laptops.each.with_index { |l, i| (print i + 1 ;break) if l[3] == min }

n=gets.to_i
computer=Struct.new("Computer",:cpu,:ram,:hdd,:cost)
c=[]
for i in 1..n
    input=gets.split.map(&:to_i)
    c.push(computer.new(input[0],input[1],input[2],input[3]))
end
u=Array.new(n,0)
for i in 0..n-1
    for j in 0..n-1
        if c[i].cpu<c[j].cpu && c[i].ram < c[j].ram && c[i].hdd < c[j].hdd then
            u[i]=1
        end
    end
end
mincost = 999999999
for i in 0..n-1
    if u[i]==0 then
        if mincost>c[i].cost then
            mincost=c[i].cost
            res=i+1
        end
    end
end
puts res

n = STDIN.readline.to_i
laptops = []
n.times {|i| laptops.push(STDIN.readline.split.map {|s| s.to_i } + [i] ) }
consider = []
n.times do |i|
  a = laptops[i]
  okay = true
  n.times do |j|
    b = laptops[j]
    if a[0] < b[0] and a[1] < b[1] and a[2] < b[2]
      okay = false
      break
    end
  end
  consider.push(a) if okay
end
consider.sort_by! {|a| a[3] }
puts consider[0][4] + 1

#!/usr/bin/ruby
count = gets.chop.to_i
laptops = Array.new(count){Array.new(5)}
i = 0
while line = gets
        line.chomp!
        laptop = line.split(' ')
        laptops[i][0] = laptop[0].to_i
        laptops[i][1] = laptop[1].to_i
        laptops[i][2] = laptop[2].to_i
        laptops[i][3] = laptop[3].to_i
        laptops[i][4] = 1;
        i = i+1
end
for i in 0..laptops.count-1
        for i2 in 0..laptops.count-1
                trues = 0
                for i3 in 0..2
                        if laptops[i][i3] < laptops[i2][i3]
                                trues = trues+1
                        end
                end
                if trues == 3
                        laptops[i][4] = 0
                        #puts "vyhozen " + i.to_s
                        break
                end
        end
end
minprice = -1
minindex = -1
for a in 0..laptops.count-1
        if laptops[a][3] < minprice || minprice == -1
                if laptops[a][4] == 1
                        minprice = laptops[a][3];
                        minindex = a;
                end
        end
        #puts min.to_s
end
puts (minindex+1).to_s

n = gets.to_i
a = readlines.map(&:chomp).map(&:split).each {|x| x.map!(&:to_i)}
ok = a.find_all { |i| !a.any? { |x| i[0]<x[0] and i[1]<x[1] and i[2]<x[2] and i[3]<x[3] } }
puts a.index(ok.min_by {|x| x[3]})+1

n = gets.to_i
a = readlines.map(&:chomp).map(&:split).each {|x| x.map!(&:to_i)}
puts a.find_all { |i| !a.any? { |x| i[0]<x[0] and i[1]<x[1] and i[2]<x[2] and i[3]<x[3] } }.min_by {|x| x[3]}[3]

#$stdin = File.open("./input", "r")

Notebook=Struct.new(:id, :speed, :ram, :hdd, :cost)

data=[]

n=gets.to_i
n.times{|i|
	speed, ram, hdd, cost=gets.split.map(&:to_i)
	id=i+1
	data << Notebook.new(id, speed, ram, hdd, cost)
}

data.sort!{|a, b|
	(a.speed<b.speed && a.ram<b.ram && a.hdd<b.hdd)? -1 : 1
}

for i in 0..data.size-2
	a,b=data[i], data[i+1]

	if a.speed<b.speed && a.ram<b.ram && a.hdd<b.hdd
		tmp=data[(i+1)..data.size-1].sort!{|a,b| (a.cost<b.cost)? -1 : 1}
		puts tmp[0].id
		exit
	end
end

tmp=data.sort!{|a,b| (a.cost<b.cost)? -1 : 1}
puts tmp[0].id

#$stdin = File.open("./input", "r")

Notebook=Struct.new(:id, :speed, :ram, :hdd, :cost)

data=[]

n=gets.to_i
n.times{|i|
	speed, ram, hdd, cost=gets.split.map(&:to_i)
	id=i+1
	data << Notebook.new(id, speed, ram, hdd, cost)
}

data.sort!{|a, b|
	(a.speed<b.speed && a.ram<b.ram && a.hdd<b.hdd)? -1 : 1
}

puts data

for i in 0..data.size-1
	a,b=data[i], data[i+1]

	if a.speed<b.speed && a.ram<b.ram && a.hdd<b.hdd
		tmp=data[(i+1)..data.size-1].sort!{|a,b| (a.cost<b.cost)? -1 : 1}
		puts tmp[0].id
		break
	end
end

#$stdin = File.open("./input", "r")

Notebook=Struct.new(:speed, :ram, :hdd, :cost)

data=[]

n=gets.to_i
n.times{
	speed, ram, hdd, cost=gets.split.map(&:to_i)
	data << Notebook.new(speed, ram, hdd, cost)
}

data.sort!{|a, b|
	(a.speed<b.speed && a.ram<b.ram && a.hdd<b.hdd)? -1 : 1
}

fin_index=-1
min_cost=999999

for i in 0..data.size-2
	a,b=data[i], data[i+1]

	if a.speed<b.speed && a.ram<b.ram && a.hdd<b.hdd
		[*(i+1)..data.size-1].each{|index|
			notebook=data[index]

			if notebook.cost<min_cost
				min_cost=notebook.cost
				fin_index=index
			end
		}
		break
	end
end

puts "#{fin_index+1}"

#!/usr/bin/env ruby

n = gets.chomp.to_i
arr = []
n.times do
    arr.push gets.chomp.split(/ /).map{|n| n.to_i}
end

speed = arr.map{|a| a[0]}.max
ram = arr.map{|a| a[1]}.max
hdd = arr.map{|a| a[2]}.max

n.times do |i|
    unless arr[i][0] == speed or arr[i][1] == ram or arr[i][2] == hdd
        3.times do |j|
            arr[i][j] = 0
        end
    end
end

id = 0
minv = 10000
n.times do |i|
    if arr[i][0] != 0 and arr[i][1] != 0 and arr[i][2] != 0
        if arr[i][3] < minv
            minv = arr[i][3]
            id = i
        end
    end
end

puts id + 1

#!/usr/bin/env ruby

n = gets.chomp.to_i
arr = []
n.times do
    arr.push gets.chomp.split(/ /).map{|n| n.to_i}
end

speed = arr.map{|a| a[0]}.max
ram = arr.map{|a| a[1]}.max
hdd = arr.map{|a| a[2]}.max

n.times do |i|
    if arr[i][0] < speed and arr[i][1] < ram and arr[i][2] < hdd
        3.times do |j|
            arr[i][j] = 0
        end
    end
end

id = 0
minv = 10000
n.times do |i|
    if arr[i][0] != 0 and arr[i][1] != 0 and arr[i][2] != 0
        if arr[i][3] < minv
            minv = arr[i][3]
            id = i
        end
    end
end

puts id + 1

#!/usr/bin/env ruby

n = gets.chomp.to_i
arr = []
n.times do
    arr.push gets.chomp.split(/ /).map{|n| n.to_i}
end

speed = arr.map{|a| a[0]}.max
ram = arr.map{|a| a[1]}.max
hdd = arr.map{|a| a[2]}.max

n.times do |i|
    if arr[i][0] < speed and arr[i][1] < ram and arr[i][2] < hdd
        3.times do |j|
            arr[i][j] = 0
        end
    end
end

id = 0
minv = 10000
n.times do |i|
    if arr[i][0] != 0 and arr[i][1] != 0 and arr[i][2] != 0
        if arr[i][3] <= minv
            minv = arr[i][3]
            id = i
        end
    end
end

puts id + 1

#!/usr/bin/env ruby

n = STDIN.gets.to_i
laptops=[]
n.times do
  laptops << STDIN.gets.split(" ").map {|i| i.to_i}
end

flag = (0..n-1).map {|i| true}
(laptops.length-1).times do |i|
  (i+1..laptops.length-1).each do |j|
    flag[i] = false if laptops[i][0] < laptops[j][0] and laptops[i][1] < laptops[j][1] and laptops[i][2] < laptops[j][2]
    flag[j] = false if laptops[j][0] < laptops[i][0] and laptops[j][1] < laptops[i][1] and laptops[j][2] < laptops[i][2]
  end
end

min = 10000
id = 0
flag.length.times do |i|
  if flag and laptops[i][3] < min
    id = i
    min = laptops[i][3]
  end
end
puts id

gets; laptops = STDIN.read.split("\n").map {|l| l.split.map! &:to_i }
d = laptops.dup

laptops.each.with_index do |l, i|
  laptops.each do |a|
    next if l == a
    laptops.delete_at(i) if l[0] < a[0] && l[1] < a[1] && l[2] < a[2]
  end
end

min = 1001
laptops.each { |i| min = i[3] if i[3] < min }

d.each.with_index do |l, i|
  if l[3] == min
    print i + 1
    break
  end
end


n,h,a,b,k = gets.strip.split.map(&:to_i)

k.times do
  ta,fa,tb,fb = gets.strip.split.map(&:to_i)
  # ta,fa,tb,fb=[tb,fb,ta,fa] if ta>tb
  if(ta==tb)
    puts (fa-fb).abs
  else
    tt = (ta-tb).abs
    if fa>b && fb>b
      tt += ( (fa-b).abs + (fb-b).abs )
    elsif fa<a && fb<a
      tt += ( (fa-a).abs + (fb-a).abs )
    else
      tt += ( (fa-fb).abs )
    end
    puts tt
  end
end

nhabk = gets.chomp.split(" ").map(&:to_i)
n = nhabk[0]
h = nhabk[1]
a = nhabk[2]
b = nhabk[3]
k = nhabk[4]

arr = []
k.times {arr.push gets.chomp.split(" ").map(&:to_i)}

arr.each do |z|
  ta = z[0]
  fa = z[1]
  tb = z[2]
  fb = z[3]

  if ta == tb
    puts (fa-fb).abs
    next
  end

  ans = 0
  floor = fa

  if fa<a
    floor = a
    ans += a-fa
  elsif fa>b
    floor = b
    ans += fa-b
  end

  ans += (tb-ta).abs
  ans += (floor-fb).abs

  puts ans
end

N, H, A, B, K = gets.split.map(&:to_i)
K.times do
    ta, fa, tb, fb = gets.split.map(&:to_i)
    if ta == tb
        dh = (fa-fb).abs
    elsif fa<A && fb<A
        dh = 2*A - fa - fb
    elsif fa>B && fb>B
        dh = fa+fb - 2*B
    else
        dh = (fa-fb).abs
    end
    puts dh + (ta-tb).abs
end

n,h,a,b,k = gets.chomp.split(" ").map(&:to_i)
k.times do
  o,p,q,r = gets.chomp.split(" ").map(&:to_i)
  ans = 0
  ans += (o-q).abs
  if ((p < a && r < a) || (p > b && r > b)) && o != q
    ans += [(p-a).abs,(p-b).abs].min
    ans += [(r-a).abs,(r-b).abs].min
  else
    ans += (p-r).abs
  end
  puts ans
end

n, h, a, b, k = gets.split.map(&:to_i)
k.times do
    ta, fa, tb, fb = gets.split.map(&:to_i)
    if ta == tb
        puts (fa - fb).abs
        next
    end
    ans = (ta - tb).abs
    if fa > fb
        fa, fb = fb, fa
    end
    if fa <= b && fb >= a
        ans += fb - fa
    elsif fa > b
        ans += (fa - b) + (fb - b)
    elsif fb < a
        ans += (a - fb) + (a - fa)
    end
    puts ans
end

N, H, A, B, K = gets.split.map(&:to_i)
K.times do
    ta, fa, tb, fb = gets.split.map(&:to_i)
    if fa<A && fb<A
        dh = 2*A - fa - fb
    elsif fa>B && fb>B
        dh = fa+fb - 2*B
    else
        dh = (fa-fb).abs
    end
    puts dh + (ta-tb).abs
end

n,h,a,b,k = gets.chomp.split(" ").map(&:to_i)
k.times do
  o,p,q,r = gets.chomp.split(" ").map(&:to_i)
  ans = 0
  ans += (o-q).abs
  if (p < a && r < a) || (p > b && r > b)
    ans += [(p-a).abs,(p-b).abs].min
    ans += [(r-a).abs,(r-b).abs].min
  else
    ans += (p-r).abs
  end
  puts ans
end

nhabk = gets.chomp.split(" ").map(&:to_i)
n = nhabk[0]
h = nhabk[1]
a = nhabk[2]
b = nhabk[3]
k = nhabk[4]

arr = []
k.times {arr.push gets.chomp.split(" ").map(&:to_i)}

arr.each do |z|
  ta = z[0]
  fa = z[1]
  tb = z[2]
  fb = z[3]

  ans = 0
  floor = fa

  if fa<a
    floor = a
    ans += a-fa
  elsif fa>b
    floor = b
    ans += fa-b
  end

  ans += tb-ta
  ans += (floor-fb).abs

  puts ans
end

nhabk = gets.chomp.split(" ").map(&:to_i)
n = nhabk[0]
h = nhabk[1]
a = nhabk[2]
b = nhabk[3]
k = nhabk[4]

arr = []
k.times {arr.push gets.chomp.split(" ").map(&:to_i)}

arr.each do |z|
  ta = z[0]
  fa = z[1]
  tb = z[2]
  fb = z[3]

  ans = 0
  floor = fa

  if fa<a
    floor = a
    ans += a-fa
  elsif fa>b
    floor = b
    ans += fa-b
  end

  ans += (tb-ta).abs
  ans += (floor-fb).abs

  puts ans
end


#$stdin.reopen('/cygdrive/d/input.txt', 'r')

class Friend
	def initialize(cost, monitor, nsolve, array)
		@cost,@monitor, @nsolve, @array = cost,
			monitor, nsolve, array
	end
	attr_accessor :cost, :monitor, :nsolve, :array
end

class Min
	def initialize(cost,monitor,ruble)
		@cost,@monitor,@ruble=cost,monitor,ruble

	end
	attr_accessor :cost, :monitor, :ruble
end

def init

	friend_list = []
	n,m,b = gets.split.map(&:to_i)

	(1..n).each do |ind|
		cost,monitor,nsolve=gets.split.map(&:to_i)
		array = gets.split.map(&:to_i)
		friend_list.push(Friend.new(cost,monitor,nsolve,array))
	end

	array = [0]*(m+1)

	(0..m).each do |ind|
		array[ind] = []
	end

	(0...friend_list.size).each do |ind|
		friend_list[ind].array.each do |e|
			array[e].push(friend_list[ind])
		end
	end

	#each element in array should be sorted.
=begin
	array.each do |e|
		e.sort! do |a,c|
			if (a.cost+a.monitor*b)/a.nsolve.to_f > (c.cost+c.monitor*b)/c.nsolve.to_f
				1
			else
				-1
			end
		end
	end
=end
	return n,m,b,array
end

def index(problem)

	i,s=1,0
	size = problem.size
	while i<size
		s=s<<1
		s+=1 if problem[i]>=1
		i+=1
	end
	s
end

def solve(array,ind,problem,t,current,min)

	if ind==array.size
		#puts current.cost
		if min.cost == -1 or current.cost<min.cost
			min.cost = current.cost
			min.monitor = current.monitor
		end
		return
	end

	if problem[ind] >= 1
		solve(array, ind+1,  problem, t, current, min)
	else

		if array[ind].empty?
			puts -1
			exit 0
		end

		array[ind].each do |e|

			i=e.monitor>current.monitor ? e.monitor-current.monitor : 0
			cost = current.cost+i*min.ruble+e.cost
			next if (min.cost!=-1 and cost >= min.cost)
			current.cost, current.monitor = cost, current.monitor+i
			e.array.each do |ind|
				problem[ind]+=1
			end
			#print problem; puts
=begin
			m= index(problem)
			if t[m] == -1 or current.cost< t[m]
				t[m] = current.cost
				solve(array, ind+1, problem,t, current,min)
			end
=end

			m =problem.to_s+current.monitor.to_s
			if !t.has_key?(m) or current.cost < t[m]
				t[m] = current.cost
				solve(array,ind+1,problem, t, current, min)
			end

			current.cost-= (e.cost+i*min.ruble)
			current.monitor -= i
			e.array.each do |ind|
				problem[ind]-=1
			end

		end
	end
end

def main
	n,m,b,array = init
=begin
	array[1].each do |e|
		puts (e.cost+e.monitor*b)/e.nsolve.to_f
	end
=end
	current, min, problem  = Min.new(0,0,b), Min.new(-1,0,b), [0]*(m+1)

	#t = [-1]*(1<<22)
	t=Hash.new

	solve(array, 1, problem, t,current, min)
	puts min.cost

end

main

#$stdin.reopen('/cygdrive/d/input.txt', 'r')

class Friend
	def initialize(cost, monitor, nsolve, array)
		@cost,@monitor, @nsolve, @array = cost,
			monitor, nsolve, array
	end
	attr_accessor :cost, :monitor, :nsolve, :array
end

class Min
	def initialize(cost,monitor,ruble)
		@cost,@monitor,@ruble=cost,monitor,ruble

	end
	attr_accessor :cost, :monitor, :ruble
end

def init

	friend_list = []
	n,m,b = gets.split.map(&:to_i)

	(1..n).each do |ind|
		cost,monitor,nsolve=gets.split.map(&:to_i)
		array = gets.split.map(&:to_i)
		friend_list.push(Friend.new(cost,monitor,nsolve,array))
	end

	array = [0]*(m+1)

	(0..m).each do |ind|
		array[ind] = []
	end

	(0...friend_list.size).each do |ind|
		friend_list[ind].array.each do |e|
			array[e].push(friend_list[ind])
		end
	end

	#each element in array should be sorted.

	array.each do |e|
		e.sort! do |a,c|
			if (a.cost+a.monitor*b)/a.nsolve.to_f > (c.cost+c.monitor*b)/c.nsolve.to_f
				1
			else
				-1
			end
		end
	end

=begin
	array.each do |e|
		e.sort! do |a,c|
			if a.monitor< c.monitor
				1
			else
				-1
			end
		end
	end
=end
	return n,m,b,array
end

def index(problem)

	i,s=1,0
	size = problem.size
	while i<size
		s=s<<1
		s+=1 if problem[i]>=1
		i+=1
	end
	s
end

def solve(array,ind,problem,t,current,min)

	if ind==array.size
		#puts current.cost
		if min.cost == -1 or current.cost<min.cost
			min.cost = current.cost
			min.monitor = current.monitor
		end
		return
	end

	if problem[ind] >= 1
		solve(array, ind+1,  problem, t, current, min)
	else

		if array[ind].empty?
			puts -1
			exit 0
		end

		array[ind].each do |e|

			i=e.monitor>current.monitor ? e.monitor-current.monitor : 0
			cost = current.cost+i*min.ruble+e.cost
			next if (min.cost!=-1 and cost >= min.cost)
			current.cost, current.monitor = cost, current.monitor+i
			e.array.each do |ind|
				problem[ind]+=1
			end
			#print problem; puts
=begin
			m= index(problem)
			if t[m] == -1 or current.cost< t[m]
				t[m] = current.cost
				solve(array, ind+1, problem,t, current,min)
			end
=end

			m =problem.to_s+current.monitor.to_s
			if !t.has_key?(m) or current.cost < t[m]
				t[m] = current.cost
				solve(array,ind+1,problem, t, current, min)
			end

			current.cost-= (e.cost+i*min.ruble)
			current.monitor -= i
			e.array.each do |ind|
				problem[ind]-=1
			end

		end
	end
end

def main
	n,m,b,array = init
=begin
	array[1].each do |e|
		puts (e.cost+e.monitor*b)/e.nsolve.to_f
	end
=end
	current, min, problem  = Min.new(0,0,b), Min.new(-1,0,b), [0]*(m+1)

	#t = [-1]*(1<<22)
	t=Hash.new

	solve(array, 1, problem, t,current, min)
	puts min.cost

end

main

#$stdin.reopen('/cygdrive/d/input.txt', 'r')

class Friend
	def initialize(cost, monitor, nsolve, array)
		@cost,@monitor, @nsolve, @array = cost,
			monitor, nsolve, array
	end
	attr_accessor :cost, :monitor, :nsolve, :array
end

class Min
	def initialize(cost,monitor,ruble)
		@cost,@monitor,@ruble=cost,monitor,ruble

	end
	attr_accessor :cost, :monitor, :ruble
end

def init

	friend_list = []
	n,m,b = gets.split.map(&:to_i)

	(1..n).each do |ind|
		cost,monitor,nsolve=gets.split.map(&:to_i)
		array = gets.split.map(&:to_i)
		friend_list.push(Friend.new(cost,monitor,nsolve,array))
	end

	array = [0]*(m+1)

	(0..m).each do |ind|
		array[ind] = []
	end

	(0...friend_list.size).each do |ind|
		friend_list[ind].array.each do |e|
			array[e].push(friend_list[ind])
		end
	end

	#each element in array should be sorted.
=begin
	array.each do |e|
		e.sort! do |a,c|
			if (a.cost+a.monitor*b)/a.nsolve.to_f > (c.cost+c.monitor*b)/c.nsolve.to_f
				1
			else
				-1
			end
		end
	end
=end

	array.each do |e|
		e.sort! do |a,c|
			if a.monitor> c.monitor
				1
			else
				-1
			end
		end
	end
	return n,m,b,array
end

def index(problem)

	i,s=1,0
	size = problem.size
	while i<size
		s=s<<1
		s+=1 if problem[i]>=1
		i+=1
	end
	s
end

def solve(array,ind,problem,t,current,min)

	if ind==array.size
		#puts current.cost
		if min.cost == -1 or current.cost<min.cost
			min.cost = current.cost
			min.monitor = current.monitor
		end
		return
	end

	if problem[ind] >= 1
		solve(array, ind+1,  problem, t, current, min)
	else

		if array[ind].empty?
			puts -1
			exit 0
		end

		array[ind].each do |e|

			i=e.monitor>current.monitor ? e.monitor-current.monitor : 0
			cost = current.cost+i*min.ruble+e.cost
			next if (min.cost!=-1 and cost >= min.cost)
			current.cost, current.monitor = cost, current.monitor+i
			e.array.each do |ind|
				problem[ind]+=1
			end
			#print problem; puts
=begin
			m= index(problem)
			if t[m] == -1 or current.cost< t[m]
				t[m] = current.cost
				solve(array, ind+1, problem,t, current,min)
			end
=end

			m =problem.to_s+current.monitor.to_s
			if !t.has_key?(m) or current.cost < t[m]
				t[m] = current.cost
				solve(array,ind+1,problem, t, current, min)
			end

			current.cost-= (e.cost+i*min.ruble)
			current.monitor -= i
			e.array.each do |ind|
				problem[ind]-=1
			end

		end
	end
end

def main
	n,m,b,array = init
=begin
	array[1].each do |e|
		puts (e.cost+e.monitor*b)/e.nsolve.to_f
	end
=end
	current, min, problem  = Min.new(0,0,b), Min.new(-1,0,b), [0]*(m+1)

	#t = [-1]*(1<<22)
	t=Hash.new

	solve(array, 1, problem, t,current, min)
	puts min.cost

end

main

#$stdin.reopen('/cygdrive/d/input.txt', 'r')

class Friend
	def initialize(cost, monitor, nsolve, array)
		@cost,@monitor, @nsolve, @array = cost,
			monitor, nsolve, array
	end
	attr_accessor :cost, :monitor, :nsolve, :array
end

class Min
	def initialize(cost,monitor,ruble)
		@cost,@monitor,@ruble=cost,monitor,ruble

	end
	attr_accessor :cost, :monitor, :ruble
end

def init

	friend_list = []
	n,m,b = gets.split.map(&:to_i)

	(1..n).each do |ind|
		cost,monitor,nsolve=gets.split.map(&:to_i)
		array = gets.split.map(&:to_i)
		friend_list.push(Friend.new(cost,monitor,nsolve,array))
	end

	array = [0]*(m+1)

	(0..m).each do |ind|
		array[ind] = []
	end

	(0...friend_list.size).each do |ind|
		friend_list[ind].array.each do |e|
			array[e].push(friend_list[ind])
		end
	end

	#each element in array should be sorted.
=begin
	array.each do |e|
		e.sort! do |a,c|
			if (a.cost+a.monitor*b)/a.nsolve.to_f > (c.cost+c.monitor*b)/c.nsolve.to_f
				1
			else
				-1
			end
		end
	end
=end

	array.each do |e|
		e.sort! do |a,c|
			if a.monitor< c.monitor
				1
			else
				-1
			end
		end
	end
	return n,m,b,array
end

def index(problem)

	i,s=1,0
	size = problem.size
	while i<size
		s=s<<1
		s+=1 if problem[i]>=1
		i+=1
	end
	s
end

def solve(array,ind,problem,t,current,min)

	if ind==array.size
		#puts current.cost
		if min.cost == -1 or current.cost<min.cost
			min.cost = current.cost
			min.monitor = current.monitor
		end
		return
	end

	if problem[ind] >= 1
		solve(array, ind+1,  problem, t, current, min)
	else

		if array[ind].empty?
			puts -1
			exit 0
		end

		array[ind].each do |e|

			i=e.monitor>current.monitor ? e.monitor-current.monitor : 0
			cost = current.cost+i*min.ruble+e.cost
			next if (min.cost!=-1 and cost >= min.cost)
			current.cost, current.monitor = cost, current.monitor+i
			e.array.each do |ind|
				problem[ind]+=1
			end
			#print problem; puts
=begin
			m= index(problem)
			if t[m] == -1 or current.cost< t[m]
				t[m] = current.cost
				solve(array, ind+1, problem,t, current,min)
			end
=end

			m =problem.to_s+current.monitor.to_s
			if !t.has_key?(m) or current.cost < t[m]
				t[m] = current.cost
				solve(array,ind+1,problem, t, current, min)
			end

			current.cost-= (e.cost+i*min.ruble)
			current.monitor -= i
			e.array.each do |ind|
				problem[ind]-=1
			end

		end
	end
end

def main
	n,m,b,array = init
=begin
	array[1].each do |e|
		puts (e.cost+e.monitor*b)/e.nsolve.to_f
	end
=end
	current, min, problem  = Min.new(0,0,b), Min.new(-1,0,b), [0]*(m+1)

	#t = [-1]*(1<<22)
	t=Hash.new

	solve(array, 1, problem, t,current, min)
	puts min.cost

end

main

#$stdin.reopen('/cygdrive/d/input.txt', 'r')

class Friend
	def initialize(cost, monitor, nsolve, array)
		@cost,@monitor, @nsolve, @array = cost,
			monitor, nsolve, array
	end
	attr_accessor :cost, :monitor, :nsolve, :array
end

class Min
	def initialize(cost,monitor,ruble)
		@cost,@monitor,@ruble=cost,monitor,ruble

	end
	attr_accessor :cost, :monitor, :ruble
end

def init

	friend_list = []
	n,m,b = gets.split.map(&:to_i)

	(1..n).each do |ind|
		cost,monitor,nsolve=gets.split.map(&:to_i)
		array = gets.split.map(&:to_i)
		friend_list.push(Friend.new(cost,monitor,nsolve,array))
	end

	array = [0]*(m+1)

	(0..m).each do |ind|
		array[ind] = []
	end

	(0...friend_list.size).each do |ind|
		friend_list[ind].array.each do |e|
			array[e].push(friend_list[ind])
		end
	end

	#each element in array should be sorted.

	array.each do |e|
		e.sort! do |a,c|
			if (a.cost+a.monitor*b)/a.nsolve.to_f > (c.cost+c.monitor*b)/c.nsolve.to_f
				1
			else
				-1
			end
		end
	end

	return n,m,b,array
end

def index(problem)

	i,s=1,0
	size = problem.size
	while i<size
		s=s<<1
		s+=1 if problem[i]>=1
		i+=1
	end
	s
end

def solve(array,ind,problem,t,current,min)

	if ind==array.size
		#puts current.cost
		if min.cost == -1 or current.cost<min.cost
			min.cost = current.cost
			min.monitor = current.monitor
		end
		return
	end

	if problem[ind] >= 1
		solve(array, ind+1,  problem, t, current, min)
	else

		if array[ind].empty?
			puts -1
			exit 0
		end

		array[ind].each do |e|

			i=e.monitor>current.monitor ? e.monitor-current.monitor : 0
			cost = current.cost+i*min.ruble+e.cost
			next if (min.cost!=-1 and cost >= min.cost)
			current.cost, current.monitor = cost, current.monitor+i
			e.array.each do |ind|
				problem[ind]+=1
			end
			#print problem; puts
=begin
			m= index(problem)
			if t[m] == -1 or current.cost< t[m]
				t[m] = current.cost
				solve(array, ind+1, problem,t, current,min)
			end
=end

			m =problem.to_s+current.monitor.to_s
			if !t.has_key?(m) or current.cost < t[m]
				t[m] = current.cost
				solve(array,ind+1,problem, t, current, min)
			end

			current.cost-= (e.cost+i*min.ruble)
			current.monitor -= i
			e.array.each do |ind|
				problem[ind]-=1
			end

		end
	end
end

def main
	n,m,b,array = init
=begin
	array[1].each do |e|
		puts (e.cost+e.monitor*b)/e.nsolve.to_f
	end
=end
	current, min, problem  = Min.new(0,0,b), Min.new(-1,0,b), [0]*(m+1)

	#t = [-1]*(1<<22)
	t=Hash.new

	solve(array, 1, problem, t,current, min)
	puts min.cost

end

main

#$stdin.reopen('/home/chen/Desktop/input.txt', 'r')

class Friend
	def initialize(cost, monitor, nsolve, array)
		@cost,@monitor, @nsolve, @array = cost,
			monitor, nsolve, array
	end
	attr_accessor :cost, :monitor, :nsolve, :array
end

class Min
	def initialize(cost,monitor,ruble)
		@cost,@monitor,@ruble=cost,monitor,ruble

	end
	attr_accessor :cost, :monitor, :ruble
end

def init

	friend_list = []
	n,m,b = gets.split.map(&:to_i)

	(1..n).each do |ind|
		cost,monitor,nsolve=gets.split.map(&:to_i)
		array = gets.split.map(&:to_i)
		friend_list.push(Friend.new(cost,monitor,nsolve,array))
	end

	array = [0]*(m+1)

	(0..m).each do |ind|
		array[ind] = []
	end

	(0...friend_list.size).each do |ind|
		friend_list[ind].array.each do |e|
			array[e].push(friend_list[ind])
		end
	end

	#each element in array should be sorted.
	array.each do |e|
		e.sort! do |a,c|
			if (a.cost+a.monitor*b)/a.nsolve.to_f > (c.cost+c.monitor*b)/c.nsolve.to_f
				1
			else
				-1
			end
		end
	end

	return n,m,b,array
end

def solve(array,ind,problem,current,min)

	if ind==array.size
		if current.cost<min.cost
			min.cost = current.cost
			min.monitor = current.monitor
		end
		return
	end

	if problem[ind] >= 1
		solve(array, ind+1,  problem, current, min)
	else

		if array[ind].empty?
			puts -1
			exit 0
		end

		array[ind].each do |e|

			i=e.monitor>current.monitor ? e.monitor-current.monitor : 0
			cost = current.cost+i*min.ruble+e.cost
			next if cost > min.cost
			current.cost, current.monitor = cost, current.monitor+i
			e.array.each do |m|
				problem[m]+=1
			end
			print problem
			solve(array, ind+1, problem, current,min)
			current.cost-= (e.cost+i*min.ruble)
			current.monitor -= i
			e.array.each do |m|
				problem[m]-=1
			end

		end
	end
end

def main
	n,m,b,array = init

	array[1].each do |e|
		puts (e.cost+e.monitor*b)/e.nsolve.to_f
	end
	current, min, problem  = Min.new(0,0,b), Min.new(1<<32,0,b), [0]*(m+1)
	solve(array, 1, problem, current, min)
	puts min.cost

end

main

#$stdin.reopen('/home/chen/Desktop/input.txt', 'r')

class Friend
	def initialize(cost, monitor, nsolve, array)
		@cost,@monitor, @nsolve, @array = cost,
			monitor, nsolve, array
	end
	attr_accessor :cost, :monitor, :nsolve, :array
end

class Min
	def initialize(cost,monitor,ruble)
		@cost,@monitor,@ruble=cost,monitor,ruble

	end
	attr_accessor :cost, :monitor, :ruble
end

def init

	friend_list = []
	n,m,b = gets.split.map(&:to_i)

	(1..n).each do |ind|
		cost,monitor,nsolve=gets.split.map(&:to_i)
		array = gets.split.map(&:to_i)
		friend_list.push(Friend.new(cost,monitor,nsolve,array))
	end

	array = [0]*(m+1)

	(0..m).each do |ind|
		array[ind] = []
	end

	(0...friend_list.size).each do |ind|
		friend_list[ind].array.each do |e|
			array[e].push(friend_list[ind])
		end
	end

	#each element in array should be sorted.
	array.each do |e|
		e.sort! do |a,c|
			if (a.cost+a.monitor*b)/a.nsolve.to_f > (c.cost+c.monitor*b)/c.nsolve.to_f
				1
			else
				-1
			end
		end
	end

	return n,m,b,array
end
def index(problem)

	i,s=1,0
	size = problem.size
	while i<size
		if problem[i]!=0
			s= (s<<1)+1
		end
		i+=1
	end
	s
end

def solve(array,ind,problem,t,current,min)

	if ind==array.size

		if min.cost == -1 or current.cost<min.cost
			min.cost = current.cost
			min.monitor = current.monitor
		end
		return
	end

	if problem[ind] >= 1
		solve(array, ind+1,  problem, t, current, min)
	else

		if array[ind].empty?
			puts -1
			exit 0
		end

		array[ind].each do |e|

			i=e.monitor>current.monitor ? e.monitor-current.monitor : 0
			cost = current.cost+i*min.ruble+e.cost
			next if min.cost!=-1 and cost >= min.cost
			current.cost, current.monitor = cost, current.monitor+i
			e.array.each do |m|
				problem[m]+=1
			end

			#print problem; puts
			x= index(problem)
			if t[x] == -1 or current.cost< t[x]
				t[x] = current.cost
				solve(array, ind+1, problem,t, current,min)
			end
			current.cost-= (e.cost+i*min.ruble)
			current.monitor -= i
			e.array.each do |m|
				problem[m]-=1
			end

		end
	end
end

def main
	n,m,b,array = init

=begin
	array[1].each do |e|
		puts (e.cost+e.monitor*b)/e.nsolve.to_f
	end
=end
	current, min, problem  = Min.new(0,0,b), Min.new(-1,0,b), [0]*(m+1)
	t = [-1]*(1<<22)
	solve(array, 1, problem, t,current, min)
	puts min.cost

end

main

#$stdin.reopen('/cygdrive/d/input.txt', 'r')

class Friend
	def initialize(cost, monitor, nsolve, array)
		@cost,@monitor, @nsolve, @array = cost,
			monitor, nsolve, array
	end
	attr_accessor :cost, :monitor, :nsolve, :array
end

class Min
	def initialize(cost,monitor,ruble)
		@cost,@monitor,@ruble=cost,monitor,ruble

	end
	attr_accessor :cost, :monitor, :ruble
end

def init

	friend_list = []
	n,m,b = gets.split.map(&:to_i)

	(1..n).each do |ind|
		cost,monitor,nsolve=gets.split.map(&:to_i)
		array = gets.split.map(&:to_i)
		friend_list.push(Friend.new(cost,monitor,nsolve,array))
	end

	array = [0]*(m+1)

	(0..m).each do |ind|
		array[ind] = []
	end

	(0...friend_list.size).each do |ind|
		friend_list[ind].array.each do |e|
			array[e].push(friend_list[ind])
		end
	end

	#each element in array should be sorted.
	array.each do |e|
		e.sort! do |a,c|
			if (a.cost+a.monitor*b)/a.nsolve.to_f > (c.cost+c.monitor*b)/c.nsolve.to_f
				1
			else
				-1
			end
		end
	end

	return n,m,b,array
end

def index(problem)

	i,s=1,0
	size = problem.size
	while i<size
		if problem[i]>=1
			s= (s<<1)+1
		end
		i+=1
	end
	s
end

def solve(array,ind,problem,t,current,min)

	if ind==array.size

		if min.cost == -1 or current.cost<min.cost
			min.cost = current.cost
			min.monitor = current.monitor
		end
		return
	end

	if problem[ind] >= 1
		solve(array, ind+1,  problem, t, current, min)
	else

		if array[ind].empty?
			puts -1
			exit 0
		end

		array[ind].each do |e|

			i=e.monitor>current.monitor ? e.monitor-current.monitor : 0
			cost = current.cost+i*min.ruble+e.cost
			next if (min.cost!=-1 and cost >= min.cost)
			current.cost, current.monitor = cost, current.monitor+i
			e.array.each do |m|
				problem[m]+=1
			end
			#print problem; puts
			x= index(problem)
			if t[x] == -1 or current.cost< t[x]
				t[x] = current.cost
				solve(array, ind+1, problem,t, current,min)
			end
			current.cost-= (e.cost+i*min.ruble)
			current.monitor -= i
			e.array.each do |m|
				problem[m]-=1
			end

		end
	end
end

def main
	n,m,b,array = init

=begin
	array[1].each do |e|
		puts (e.cost+e.monitor*b)/e.nsolve.to_f
	end
=end
	current, min, problem  = Min.new(0,0,b), Min.new(-1,0,b), [0]*(m+1)
	t = [-1]*(1<<22)
	solve(array, 1, problem, t,current, min)
	puts min.cost

end

main

#$stdin.reopen('/home/chen/Desktop/input.txt', 'r')

class Friend
	def initialize(cost, monitor, nsolve, array)
		@cost,@monitor, @nsolve, @array = cost,
			monitor, nsolve, array
	end
	attr_accessor :cost, :monitor, :nsolve, :array
end

class Min
	def initialize(cost,monitor,ruble)
		@cost,@monitor,@ruble=cost,monitor,ruble

	end
	attr_accessor :cost, :monitor, :ruble
end

def init

	friend_list = []
	n,m,b = gets.split.map(&:to_i)

	(1..n).each do |ind|
		cost,monitor,nsolve=gets.split.map(&:to_i)
		array = gets.split.map(&:to_i)
		friend_list.push(Friend.new(cost,monitor,nsolve,array))
	end

	array = [0]*(m+1)

	(0..m).each do |ind|
		array[ind] = []
	end

	(0...friend_list.size).each do |ind|
		friend_list[ind].array.each do |e|
			array[e].push(friend_list[ind])
		end
	end

	#each element in array should be sorted.
	array.each do |e|
		e.sort! do |a,c|
			if (a.cost+a.monitor*b)/a.nsolve.to_f > (c.cost+c.monitor*b)/c.nsolve.to_f
				1
			else
				-1
			end
		end
	end

	return n,m,b,array
end
def index(problem)

	i,s=1,0
	size = problem.size
	while i<size
		if problem[i]!=0
			s= (s<<1)+1
		end
		i+=1
	end
	s
end

def solve(array,ind,problem,t,current,min)

	if ind==array.size

		if min.cost == -1 or current.cost<min.cost
			min.cost = current.cost
			min.monitor = current.monitor
		end
		return
	end

	if problem[ind] >= 1
		solve(array, ind+1,  problem, t, current, min)
	else

		if array[ind].empty?
			puts -1
			exit 0
		end

		array[ind].each do |e|

			i=e.monitor>current.monitor ? e.monitor-current.monitor : 0
			cost = current.cost+i*min.ruble+e.cost
			next if min.cost!=-1 and cost >= min.cost
			current.cost, current.monitor = cost, current.monitor+i
			e.array.each do |m|
				problem[m]+=1
			end

			#print problem; puts
			i= index(problem)
			if t[i] == -1 or current.cost< t[i]
				t[i] = current.cost
				solve(array, ind+1, problem,t, current,min)
			end
			current.cost-= (e.cost+i*min.ruble)
			current.monitor -= i
			e.array.each do |m|
				problem[m]-=1
			end

		end
	end
end

def main
	n,m,b,array = init

=begin
	array[1].each do |e|
		puts (e.cost+e.monitor*b)/e.nsolve.to_f
	end
=end
	current, min, problem  = Min.new(0,0,b), Min.new(-1,0,b), [0]*(m+1)
	t = [-1]*(1<<22)
	solve(array, 1, problem, t,current, min)
	puts min.cost

end

main

#$stdin.reopen('/home/chen/Desktop/input.txt', 'r')

class Friend
	def initialize(cost, monitor, nsolve, array)
		@cost,@monitor, @nsolve, @array = cost,
			monitor, nsolve, array
	end
	attr_accessor :cost, :monitor, :nsolve, :array
end

class Min
	def initialize(cost,monitor,ruble)
		@cost,@monitor,@ruble=cost,monitor,ruble

	end
	attr_accessor :cost, :monitor, :ruble
end

def init

	friend_list = []
	n,m,b = gets.split.map(&:to_i)

	(1..n).each do |ind|
		cost,monitor,nsolve=gets.split.map(&:to_i)
		array = gets.split.map(&:to_i)
		friend_list.push(Friend.new(cost,monitor,nsolve,array))
	end

	array = [0]*(m+1)

	(0..m).each do |ind|
		array[ind] = []
	end

	(0...friend_list.size).each do |ind|
		friend_list[ind].array.each do |e|
			array[e].push(friend_list[ind])
		end
	end

	#each element in array should be sorted.
	array.each do |e|
		e.sort! do |a,c|
			if (a.cost+a.monitor*b)/a.nsolve.to_f > (c.cost+c.monitor*b)/c.nsolve.to_f
				1
			else
				-1
			end
		end
	end

	return n,m,b,array
end

def solve(array,ind,problem,current,min)

	if ind==array.size
		if current.cost<min.cost
			min.cost = current.cost
			min.monitor = current.monitor
		end
		return
	end

	if problem[ind] >= 1
		solve(array, ind+1,  problem, current, min)
	else

		if array[ind].empty?
			puts -1
			exit 0
		end

		array[ind].each do |e|

			i=e.monitor>current.monitor ? e.monitor-current.monitor : 0
			cost = current.cost+i*min.ruble+e.cost
			next if cost > min.cost
			current.cost, current.monitor = cost, current.monitor+i
			e.array.each do |m|
				problem[m]+=1
			end
			#print problem
			solve(array, ind+1, problem, current,min)
			current.cost-= (e.cost+i*min.ruble)
			current.monitor -= i
			e.array.each do |m|
				problem[m]-=1
			end

		end
	end
end

def main
	n,m,b,array = init

=begin
	array[1].each do |e|
		puts (e.cost+e.monitor*b)/e.nsolve.to_f
	end
=end
	current, min, problem  = Min.new(0,0,b), Min.new(1<<32,0,b), [0]*(m+1)
	solve(array, 1, problem, current, min)
	puts min.cost

end

main

#$stdin.reopen('/cygdrive/d/input.txt', 'r')

class Friend
	def initialize(cost, monitor, nsolve, array)
		@cost,@monitor, @nsolve, @array = cost,
			monitor, nsolve, array
	end
	attr_accessor :cost, :monitor, :nsolve, :array
end

class Min
	def initialize(cost,monitor,ruble)
		@cost,@monitor,@ruble=cost,monitor,ruble

	end
	attr_accessor :cost, :monitor, :ruble
end

def init

	friend_list = []
	n,m,b = gets.split.map(&:to_i)

	(1..n).each do |ind|
		cost,monitor,nsolve=gets.split.map(&:to_i)
		array = gets.split.map(&:to_i)
		friend_list.push(Friend.new(cost,monitor,nsolve,array))
	end

	array = [0]*(m+1)

	(0..m).each do |ind|
		array[ind] = []
	end

	(0...friend_list.size).each do |ind|
		friend_list[ind].array.each do |e|
			array[e].push(friend_list[ind])
		end
	end

	#each element in array should be sorted.

	array.each do |e|
		e.sort! do |a,c|
			if (a.cost+a.monitor*b)/a.nsolve.to_f > (c.cost+c.monitor*b)/c.nsolve.to_f
				1
			else
				-1
			end
		end
	end

	return n,m,b,array
end

def index(problem)

	i,s=1,0
	size = problem.size
	while i<size
		s=s<<1
		s+=1 if problem[i]>=1
		i+=1
	end
	s
end

def solve(array,ind,problem,t,current,min)

	if ind==array.size

		if min.cost == -1 or current.cost<min.cost
			min.cost = current.cost
			min.monitor = current.monitor
		end
		return
	end

	if problem[ind] >= 1
		solve(array, ind+1,  problem, t, current, min)
	else

		if array[ind].empty?
			puts -1
			exit 0
		end

		array[ind].each do |e|

			i=e.monitor>current.monitor ? e.monitor-current.monitor : 0
			cost = current.cost+i*min.ruble+e.cost
			next if (min.cost!=-1 and cost >= min.cost)
			current.cost, current.monitor = cost, current.monitor+i
			e.array.each do |ind|
				problem[ind]+=1
			end
			#print problem; puts

			m= index(problem)
			if t[m] == -1 or current.cost< t[m]
				t[m] = current.cost
				solve(array, ind+1, problem,t, current,min)
			end
			current.cost-= (e.cost+i*min.ruble)
			current.monitor -= i
			e.array.each do |ind|
				problem[ind]-=1
			end

		end
	end
end

def main
	n,m,b,array = init
=begin
	array[1].each do |e|
		puts (e.cost+e.monitor*b)/e.nsolve.to_f
	end
=end
	current, min, problem  = Min.new(0,0,b), Min.new(-1,0,b), [0]*(m+1)
	t = [-1]*(1<<22)
	solve(array, 1, problem, t,current, min)
	puts min.cost

end

main


buf = STDIN.gets.chomp.split
n = buf[0].to_i
m = buf[1].to_i
prices = STDIN.gets.chomp.split
for i in 0 .. prices.size-1
  prices[i] = prices[i].to_i
end
prices.sort!

hash = Hash.new
m.times { |i|
  name = STDIN.gets.chomp
  if (name == nil)
    puts "ERROR"
  end
  if (hash[name] == nil)
    hash[name] = 1
  else
    hash[name] += 1
  end
}

nums = []
hash.each_value { |i|
  nums.push(i)
}

nums.sort!

minT = 0
maxT = 0
for i in 0..nums.size-1
  minT += nums[nums.size-1-i]*prices[i]
  maxT += nums[nums.size-1-i]*prices[prices.size-1-i]
end
puts minT.to_s + " " + maxT.to_s

n,m = gets.chomp.split(/ /).map!{|x| x.to_i}
prices = gets.chomp.split(/ /).map!{|x| x.to_i}
h = Hash.new
for i in 0..m-1
	s = gets.chomp
	if h.key?(s)
		wk = h[s]
		h[s] = wk+1
	else
		h[s] = 1
	end
end

sum1 = 0
sum2 = 0
ha = h.to_a.sort!{ |a,b| b[1] <=> a[1] }
prices.sort!
for i in 0..ha.length-1
	sum1 += ha[i][1]*prices[i]
	sum2 += ha[i][1]*prices[(prices.length-1)-i]
end
puts sum1.to_s + " " + sum2.to_s

#!/usr/bin/ruby
n=gets.chomp.split(" ").map!{|i|i=i.to_i}
a=gets.chomp.split(" ").map!{|i|i=i.to_i}.sort
b=a.reverse
h=Hash.new
h.default=0
n[1].times{|i|
  h[gets.chomp]+=1;
}
g=h.values.sort.reverse
m=M=0
g.length.times{|i|
  m+=g[i]*a[i]
  M+=g[i]*b[i]
}
puts "#{m} #{M}"

n,m=gets.split.map(&:to_i)
costs=[gets.split.map(&:to_i).sort]
costs.push(costs[0].reverse)
fruit=Hash.new
fruit.default=0
m.times{ fruit[gets.split[0]]+=1 }
ans=[0,0]
fruit.size.times{|i|
    found=false
    m.downto(1){|j|
        fruit.each{|a,b|
            if b==j then
                2.times{|k| ans[k]+=j*costs[k][i] }
                found=a
                break
            end
        }
        fruit[found]=0
        break if found!=false
    }
}
printf "%d %d\n",ans[0],ans[1]

fruits = {}

n,m = gets.split.map(&:to_i)
prices = gets.split.map(&:to_i)
m.times do
	fruit = gets.chomp
	if !fruits[fruit]
		fruits[fruit] = 1
	else
		fruits[fruit] += 1
	end
end

numbers = fruits.values.sort!.reverse!

prices.sort!
min_cost = 0
for i in 0...numbers.size
	min_cost += prices[i] * numbers[i]
end
print "#{min_cost} "

prices.reverse!
max_cost = 0
for i in 0...numbers.size
	max_cost += prices[i] * numbers[i]
end
puts max_cost

str=gets
str.chomp!
tmp=str.split()
num=tmp[1].to_i
str2=gets
str2.chomp!
memo=[]
str2.split().each do |s|
  memo << s.to_i
end
memo.sort!
max=0
min=0
hash=Hash.new
while name=gets
  name.chomp!
  if(hash.key?(name)==false)
    hash.store(name,1)
  else
    hash.store(name,hash[name]+1)
  end
end
number=hash.values
number=number.sort_by{|i| -i}
hash.length.times do |i|
  min+=number[i]*memo[i]
  max+=number[i]*memo[memo.length-1-i]
end
printf("%d %d\n",min,max)

n,m=gets.split.map(&:to_i)
prices = gets.split.map(&:to_i)
prices.sort!
#p prices
fruits = Hash.new
m.times do
  f = gets.chomp
  if fruits[f] == nil then
    fruits[f] = 1
  else
    fruits[f] += 1
  end
end
#p fruits
fvalues = fruits.values
fvalues.sort!
fvalues.reverse!
len = n < fvalues.length() ? n : fvalues.length()

sum = 0
len.times do |i|
  sum += fvalues[i] *  prices[i]
end
print sum, " "

prices.reverse!
sum = 0
len.times do |i|
  sum += fvalues[i] *  prices[i]
end
print sum
puts

a=gets().chomp().split(' ').map(&:to_i)
b = gets().chomp().split(' ').map(&:to_i).sort!{|x,y| x<=>y}
h=Hash.new
a[1].times { temp=gets().chomp; (h.has_key?(temp)) ? h[temp]+=1 : h[temp]=1 }
h= (h.sort_by{|_key, value| value}).reverse
s=0;e=b.length()-1;max=0;min=0
h.each(){|key,value| min+=value.to_i*b[s];max+=value.to_i*b[e];s+=1;e-=1; }
print min,' ', max

fruits = Hash.new { |hash, key| hash[key] = 0 }
n, m = STDIN.readline.chomp.split.map { |c| Integer(c) }
prices = STDIN.readline.chomp.split.map { |c| Integer(c) }
m.times do
  fruits[STDIN.readline.chomp] += 1
end

prices.sort!
fruits_sorted_d = fruits.sort { |a, b| b[1] <=> a[1] }

min_value, max_value = 0, 0
fruits_sorted_d.each_with_index do |value, index|
  min_value += (prices[index] * value[1])
  max_value += (prices[prices.size - 1 - index] * value[1])
end

puts "#{min_value} #{max_value}"

n, m = gets.split.map(&:to_i)
price = gets.split.map(&:to_i).sort
fruits = {}
m.times do
	fruit = gets.chomp
	fruits.has_key?(fruit) ? fruits[fruit] += 1 : fruits[fruit] = 1
end
count = fruits.values.sort.reverse
mn, mx = 0, 0
count.each_index{|i| mn, mx = mn + price[i] * count[i], mx + price[n-1-i] * count[i]}
puts "#{mn} #{mx}"


n = gets.to_i
a = gets.strip.split(' ').map {|x| x.to_i}
h = Hash.new 0
a.each do |e|
  if e > 0
    h[1] += 1
  elsif e < 0
    h[-1] += 1
  else
    h[0] += 1
  end
end
m = h[-1]%2
k = (n%2 == 1) ? 0 : m
aa = a.map {|e| e.abs}.sort
a1 = aa[0,k]
a2 = aa[k..-1]
puts( a2.inject(0, :+) - a1.inject(0, :+) )

n = gets.to_i
a = gets.split.map(&:to_i)
m = a.count{|i| i < 0}
a = a.map(&:abs)
s = a.inject(&:+)
s -= 2 * a.min if n.even? && m.odd?
p s

def run
  n = $stdin.gets.to_i
  a = $stdin.gets.split.map(&:to_i)
  m = a.count {|x| x < 0}
  a.map!(&:abs)
  s = a.reduce(&:+)
  s -= 2 * a.min if n.even? && m.odd?
  p s
end

run if $0 == __FILE__

n = gets.to_i
a = gets.split(" ").map{|s| s.to_i}
a = a.sort
ans = 0
if n%2==1
    a.each {|x| ans+=x.abs}
else
	dlt=0
	a.each_with_index {|x,i| ans+=x;dlt=[-ans,dlt].max if i%2==1}
	ans+=dlt+dlt
end
p ans

n = gets.to_i
a = gets.split.map(&:to_i)
m = a.count{|i| i < 0}
a = a.map(&:abs)
s = a.inject(&:+)
s -= 2 * a.min if m.odd?
p s

def convert(a, n)
  a[0, n].map {|x| x *= -1} + a[n, n - 1]
end

def run
  n = $stdin.gets.to_i
  a = $stdin.gets.split.map(&:to_i).sort
  s = a.reduce(:+)

  2.times do
    a1 = convert(a, n)
    s1 = a1.reduce(:+)
    a = a1.sort if s1 > s
  end

  puts a.reduce(:+)
end

run if $0 == __FILE__


class DisjointSet
	def initialize(n)
		@p = [*0..n]
	end

	def root(i)
		i == @p[i] ? i : @p[i] = root(@p[i])
	end

	def setp(i, j)
		i = root(i)
		j = root(j)
		return if i == j
		@p[i] = j
	end
end

n = gets.to_i
e = n.times.map{[]}
d = DisjointSet.new(n + 1)
x = []
(2..n).each{
	a, b = gets.split.map(&:to_i)
	x << [a, b] unless d.setp(a, b)
}
p x.size
(2..n).each{|i|
	next unless d.setp(i - 1, i)
	puts "#{x[0][0]} #{x[0][1]} #{i - 1} #{i}"
	x.shift
}

$n = gets.chomp.to_i

$p = Array.new($n+1) {|i| i}
$rank = Array.new($n+1, 0)

def find(x)
  while ($p[x]!=x)
    x=$p[x]
  end
  x
end

def union(x, y)
  px = find(x)
  py = find(y)
  return if px==py
  if $rank[px]<$rank[py]
    $p[px]=py
  else
    $p[py]=px
    $rank[px]=$rank[px]+1 if $rank[px]==$rank[py]
  end
end

def find_need_road()
  1.upto($n-1){|i|
    (i+1).upto($n){|j|
      return i, j if find(i)!=find(j)
    }
  }
end

bad_roads = []
($n-1).times{
  x, y = gets.chomp.split(' ').map{|i| i.to_i}
  x, y = y, x if x > y
  if find(x)!=find(y)
    union(x, y)
  else
    bad_roads << [x, y]
  end
}

puts bad_roads.size
bad_roads.size.times{|t|
  a, b = find_need_road()
  union(a, b)
  puts "#{bad_roads[t][0]} #{bad_roads[t][1]} #{a} #{b}"
}


# Try Codeforces
# author: Leonardone @ NEETSDKASU
############################################################
def gs() gets.chomp end
def gi() gets.to_i end
def gss() gs.split end
def gis() gss.map(&:to_i) end
def nmapf(n,f) n.times.map{ __send__ f } end
def ngs(n) nmapf n,:gs end
def ngi(n) nmapf n,:gi end
def ngss(n) nmapf n,:gss end
def ngis(n) nmapf n,:gis end
def arr2d(h,w,v=0) h.times.map{[v] * w} end
def for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end
def nsum(n) n * (n + 1) / 2 end
def vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end
############################################################

n = gi

# x ** 2 == z ** 2 - y ** 2 = (z + y) * (z - y)

m = (n ** 2) / 2
k = m + 1
if n.even?
    m /= 2
    k = m + 1
    m -= 1
end

if m > 0 && k > 0 && n ** 2 + m ** 2 == k ** 2
    puts "%d %d" % [m, k]
else
    puts -1
end

n = gets.to_i
if n == 1 || n == 2
  puts -1
else
  n2 = n
  n2 /= 2 while n2 % 2 == 0
  if n2 == 1
    time = n / 4
    puts "#{3 * time} #{5 * time}"
  else
    time = n / n2
    a = n2 * n2 / 2
    m, k = a * time, (a + 1) * time
    puts "#{m} #{k}"
  end
end

require 'prime'
n = gets.to_i
factors = n.prime_division
if n == 1 || n == 2
  puts -1
elsif factors.size == 1 && factors[0][0] == 2
  time = n / 4
  puts "#{3 * time} #{5 * time}"
else
  n2 = n
  n2 /= 2 while n2 % 2 == 0
  time = n / n2
  a = ((n2 ** 2) - 1) / 2
  m, k = a * time, (a + 1) * time
  puts "#{m} #{k}"
end


(1..(n=gets.to_i)).to_a.each_slice((n**0.5).to_i).to_a.reverse.flatten.each {|x| print "#{x} "}

N = gets.to_i
M = Math.sqrt(N).floor
ans = []
(N/M).downto(0) do |i|
    ((i*M+1)..(i*M+M)).each do |j|
        ans.push(j) if j <= N
    end
end
puts ans.join(' ')

n = gets.chomp.to_i

st = Math.sqrt(n).to_i

(1..n).step(st) do |i|
  [i+st-1,n].min.downto(i) { |j| print "#{j} " }
end

puts ""


gets.to_i.times {
  puts gets.to_i / 2
}

t = gets.chomp.to_i
t.times do
   n = gets.chomp.to_i
   if n % 2 == 0
        aa = n
        puts aa / 2
   elsif n % 2 == 1
    a = n - 1
    puts a / 2
   end
end

gets.to_i.times do
  puts gets.to_i.div(2)
end


#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'