s = gets.chomp
st = []
seq = []
rev = {}
rev[')'] = '('
rev[']'] = '['
i = 0
s.each_char do |c|
    if (c == '(' || c == '[')
        st.push([i, c])
    elsif (st.size() > 0 && (c == ')' || c == ']') && rev[c] == st.last[1])
        seq.push(st.last)
        seq.push([i, c])
        st.pop
    else
        while (st.size() > 0)
            st.pop
        end
    end
    i += 1
end
seq.sort!
res = "", mx = -1, prv = -1, c = 0, t = ""
for i in seq
    # puts "#{i[0]} #{i[1]}"
    if (i[0] - prv == 1)
        c += 1 if (i[1] == '[')
        t << i[1]
    else
        if (mx < c)
            mx = c
            res = t.dup
        end
        t.clear
        c = 0
        c += 1 if (i[1] == '[')
        t << i[1]
    end
    prv = i[0]
end

if (mx < c)
    mx = c
    res = t.dup
end
puts mx, res

#!/usr/bin/ruby

s = STDIN.readline.strip + '$'
parens, brackets = [], []
left, right = 0, 0
count, best_count = 0, 0
best_left, best_right = 1, 0
while right < s.length
	#puts 'left = %d, right = %d, count = %d, brackets = %s, parens = %s' % [
	#		left, right, count, brackets, parens]
	ch = s[right]
	error = false
	if ch == '('
		parens.push(right)
	elsif ch == '['
		brackets.push(right)
		count += 1
	elsif ch == ')'
		if parens.length == 0
			error = true
		elsif brackets.length != 0 and brackets[-1] > parens[-1]
			error = true
		else
			parens.pop
		end
	elsif ch == ']'
		if brackets.length == 0
			error = true
		elsif parens.length != 0 and parens[-1] > brackets[-1]
			error = true
		else
			brackets.pop
		end
	else
		error = true
	end
	if not error
		if parens.length == 0 and brackets.length == 0
			if count > best_count
				best_count, best_left, best_right = count, left, right
			end
		end
		right += 1
	else
		next_left = right+1

		# find the longest correct substring preceding the error
		right -= 1
		seek = right
		b, p, count = 0, 0, 0
		while seek >= left
			ch = s[seek]
			if ch == '['
				b -= 1
				count += 1
			elsif ch == ']'
				b += 1
			elsif ch == '('
				p -= 1
			elsif ch == ')'
				p += 1
			end
			if b == 0 and p == 0 and count > best_count
				best_count, best_left, best_right = count, seek, right
			end
			if b < 0 or p < 0
				b, p, count = 0, 0, 0
				right = seek-1
			end
			seek -= 1
		end

		parens, brackets = [], []
		left = right = next_left
		count = 0
	end
end
puts best_count
puts s[best_left..best_right]

s = gets.chomp
st = []
seq = []
rev = {}
rev[')'] = '('
rev[']'] = '['
i = 0
s.each_char do |c|
    if (c == '(' || c == '[')
        st.push([i, c])
    elsif (st.size() > 0 && (c == ')' || c == ']') && rev[c] == st.last[1])
        seq.push(st.last)
        seq.push([i, c])
        st.pop
    else
        while (st.size() > 0)
            st.pop
        end
    end
    i += 1
end
seq.sort!
res = "", mx = -1, prv = -1, c = 0, t = ""
for i in seq
    if (i[0] - prv == 1)
        c += 1 if (i[1] == '[')
        t.concat(i[1])
    else
        if (mx < c)
            mx = c
            res = t.dup
        end
        t.clear
        c = 0
        c += 1 if (i[1] == '[')
        t.concat(i[1])
    end
    prv = i[0]
end

if (mx < c)
    mx = c
    res = t.dup
end
puts mx, res

A,B,C,D=[?[,?],?(,?)].map(&:ord)
def match(c,d)
	return 1 if (c==A)&&(d==B)
	return 0 if (c==C)&&(d==D)
	false
end
t=gets.chomp
s=t.bytes.each_with_index.map.to_a
size=s.size
table=Array.new(size+1)
stack=[]
s.each{|chr|
	ord,idx=chr
	if (ord==A)||(ord==C)||stack.empty?
		stack.push chr
	else
		if m=match(stack.last.first,ord)
			_ord,_idx=stack.pop
			table[idx]=0
			table[_idx]=m
		else
			stack.push chr
		end
	end
}
max=0
sum=0
_l=l=r=0
table.each_with_index{|n,idx|
	if n
		sum+=n
	else
		if sum>max
			max=sum
			l=_l
			r=idx-1
		end
		sum=0
		_l=idx+1
	end
}
puts max
puts max==0 ? "" : t[l..r]

s = gets.chomp
st = []
seq = []
rev = {}
rev[')'] = '('
rev[']'] = '['
i = 0
s.each_char do |c|
    if (c == '(' || c == '[')
        st.push([i, c])
    elsif (st.size() > 0 && (c == ')' || c == ']') && rev[c] == st.last[1])
        seq.push(st.last)
        seq.push([i, c])
        st.pop
    else
        while (st.size() > 0)
            st.pop
        end
    end
    i += 1
end
seq.sort!
res = "", mx = -1, prv = -1, c = 0, t = ""
for i in seq
    # puts "#{i[0]} #{i[1]}"
    if (i[0] - prv == 1)
        c += 1 if (i[1] == '[')
        t << i[1]
    else
        if (mx < c)
            mx = c
            res = t.dup
        end
        t = ""
        c = 0
        c += 1 if (i[1] == '[')
        t += i[1]
    end
    prv = i[0]
end

if (mx < c)
    mx = c
    res = t.dup
end
puts mx, res

s = gets.chomp
st = []
seq = []
rev = {}
rev[')'] = '('
rev[']'] = '['
i = 0
s.each_char do |c|
    if (c == '(' || c == '[')
        st.push([i, c])
    elsif (st.size() > 0 && (c == ')' || c == ']') && rev[c] == st.last[1])
        seq.push(st.last)
        seq.push([i, c])
        st.pop
    else
        while (st.size() > 0)
            st.pop
        end
    end
    i += 1
end
seq.sort!
res = "", mx = -1, prv = -1, c = 0, t = ""
for i in seq
    # puts "#{i[0]} #{i[1]}"
    if (i[0] - prv == 1)
        c += 1 if (i[1] == '[')
        t << i[1]
    else
        if (mx < c)
            mx = c
            res = t.dup
        end
        t.clear
        c = 0
        c += 1 if (i[1] == '[')
        t += i[1]
    end
    prv = i[0]
end

if (mx < c)
    mx = c
    res = t.dup
end
puts mx, res

#!/usr/bin/ruby

s = STDIN.readline.strip + '$'
parens, brackets = [], []
left, right = 0, 0
best_count = 0
best_left, best_right = 1, 0
while right < s.length
	ch = s[right]
	error = false
	if ch == '('
		parens.push(right)
	elsif ch == '['
		brackets.push(right)
	elsif ch == ')'
		if parens.length == 0
			error = true
		elsif brackets.length != 0 and brackets[-1] > parens[-1]
			error = true
		else
			parens.pop
		end
	elsif ch == ']'
		if brackets.length == 0
			error = true
		elsif parens.length != 0 and parens[-1] > brackets[-1]
			error = true
		else
			brackets.pop
		end
	else
		error = true
	end
	if not error
		right += 1
	else
		next_left = right+1
		seek = right = right-1
		b, p, count = 0, 0, 0
		while seek >= left
			ch = s[seek]
			if ch == '['
				b -= 1
				count += 1
			elsif ch == ']'
				b += 1
			elsif ch == '('
				p -= 1
			elsif ch == ')'
				p += 1
			end
			if b == 0 and p == 0 and count > best_count
				best_count, best_left, best_right = count, seek, right
			end
			if b < 0 or p < 0
				b, p, count = 0, 0, 0
				right = seek-1
			end
			seek -= 1
		end
		parens, brackets = [], []
		left = right = next_left
	end
end
puts best_count
puts s[best_left..best_right]

#!/usr/bin/ruby

s = STDIN.readline.strip + '$'
parens, brackets = [], []
left, right = 0, 0
count, best_count = 0, 0
best_left, best_right = 1, 0
while right < s.length
	ch = s[right]
	error = false
	if ch == '('
		parens.push(right)
	elsif ch == '['
		brackets.push(right)
		count += 1
	elsif ch == ')'
		if parens.length == 0
			error = true
		elsif brackets.length != 0 and brackets[-1] > parens[-1]
			error = true
		else
			parens.pop
		end
	elsif ch == ']'
		if brackets.length == 0
			error = true
		elsif parens.length != 0 and parens[-1] > brackets[-1]
			error = true
		else
			brackets.pop
		end
	else
		error = true
	end
	if not error
		if parens.length == 0 and brackets.length == 0
			if count > best_count
				best_count, best_left, best_right = count, left, right
			end
		end
		right += 1
	else
		while left != right
			if parens.length == 0 and brackets.length == 0
				if count > best_count
					best_count, best_left, best_right = count, left, right-1
				end
			end
			if s[left] == '('
				parens.shift
			elsif s[left] == '['
				brackets.shift
				count -= 1
			end
			left += 1
		end
		parens = []
		brackets = []
		left = right = right+1
		count = 0
	end
end
puts best_count
puts s[best_left..best_right]

#!/usr/bin/ruby

s = STDIN.readline.strip + '$'
parens, brackets = [], []
left, right = 0, 0
count, best_count = 0, 0
best_left, best_right = 1, 0
while right < s.length
	ch = s[right]
	error = false
	if ch == '('
		parens.push(right)
	elsif ch == '['
		brackets.push(right)
		count += 1
	elsif ch == ')'
		if parens.length == 0
			error = true
		elsif brackets.length != 0 and brackets[-1] > parens[-1]
			error = true
		else
			parens.pop
		end
	elsif ch == ']'
		if brackets.length == 0
			error = true
		elsif parens.length != 0 and parens[-1] > brackets[-1]
			error = true
		else
			brackets.pop
		end
	else
		error = true
	end
	if not error
		right += 1
	else
		while left != right
			if parens.length == 0 and brackets.length == 0
				if count > best_count
					best_count, best_left, best_right = count, left, right-1
				end
			end
			if s[left] == '('
				parens.shift
			elsif s[left] == '['
				brackets.shift
				count -= 1
			end
			left += 1
		end
		left = right = right+1
		count = 0
	end
end
puts best_count
puts s[best_left..best_right]

#!/usr/bin/ruby

s = STDIN.readline.strip + '$'
parens, brackets = [], []
left, right = 0, 0
count, best_count = 0, 0
best_left, best_right = 1, 0
while right < s.length
	#puts 'left = %d, right = %d, count = %d, brackets = %s, parens = %s' % [
	#		left, right, count, brackets, parens]
	ch = s[right]
	error = false
	if ch == '('
		parens.push(right)
	elsif ch == '['
		brackets.push(right)
		count += 1
	elsif ch == ')'
		if parens.length == 0
			error = true
		elsif brackets.length != 0 and brackets[-1] > parens[-1]
			error = true
		else
			parens.pop
		end
	elsif ch == ']'
		if brackets.length == 0
			error = true
		elsif parens.length != 0 and parens[-1] > brackets[-1]
			error = true
		else
			brackets.pop
		end
	else
		error = true
	end
	if not error
		if parens.length == 0 and brackets.length == 0
			if count > best_count
				best_count, best_left, best_right = count, left, right
			end
		end
		right += 1
	else
		next_left = right+1

		# find the longest correct substring preceding the error
		seek = right-1
		b, p, count = 0, 0, 0
		while seek >= left
			ch = s[seek]
			if ch == '['
				b -= 1
				count += 1
			elsif ch == ']'
				b += 1
			elsif ch == '('
				p -= 1
			elsif ch == ')'
				p += 1
			end
			if b == 0 and p == 0 and count > best_count
				best_count, best_left, best_right = count, seek, right
			end
			if b < 0 or p < 0
				b, p, count = 0, 0, 0
			end
			seek -= 1
		end

		parens, brackets = [], []
		left = right = next_left
		count = 0
	end
end
puts best_count
puts s[best_left..best_right]

#!/usr/bin/ruby

s = STDIN.readline.strip + '('
parens, brackets = [], []
left, right = 0, 0
count, best_count = 0, 0
best_left, best_right = 1, 0
while right < s.length
	ch = s[right]
	complete, error = false, false
	if ch == '('
		parens.push(right)
	elsif ch == '['
		brackets.push(right)
		count += 1
	elsif ch == ')'
		if parens.length == 0
			error = true
		elsif brackets.length != 0 and brackets[-1] > parens[-1]
			error = true
		else
			parens.pop
			complete = true if parens.length == 0 and brackets.length == 0
		end
	elsif ch == ']'
		if brackets.length == 0
			error = true
		elsif parens.length != 0 and parens[-1] > brackets[-1]
			error = true
		else
			brackets.pop
			complete = true if parens.length == 0 and brackets.length == 0
		end
	end
	if not complete and not error
		right += 1
		next
	end
	if complete
		if count > best_count
			best_count, best_left, best_right = count, left, right
		end
	elsif error
		while left != right
			if parens.length == 0 and brackets.length == 0
				if count > best_count
					best_count, best_left, best_right = count, left, right-1
				end
			end
			if s[left] == '('
				parens.shift
			elsif s[left] == '['
				brackets.shift
				count -= 1
			end
			left += 1
		end
	end
	left = right = right+1
	count = 0
end
puts best_count
puts s[best_left..best_right]

#!/usr/bin/ruby

s = STDIN.readline.strip + '$'
parens, brackets = [], []
left, right = 0, 0
count, best_count = 0, 0
best_left, best_right = 1, 0
while right < s.length
	ch = s[right]
	error = false
	if ch == '('
		parens.push(right)
	elsif ch == '['
		brackets.push(right)
		count += 1
	elsif ch == ')'
		if parens.length == 0
			error = true
		elsif brackets.length != 0 and brackets[-1] > parens[-1]
			error = true
		else
			parens.pop
		end
	elsif ch == ']'
		if brackets.length == 0
			error = true
		elsif parens.length != 0 and parens[-1] > brackets[-1]
			error = true
		else
			brackets.pop
		end
	else
		error = true
	end
	if not error
		if parens.length == 0 and brackets.length == 0
			if count > best_count
				best_count, best_left, best_right = count, left, right
			end
		end
		right += 1
	else
		while left != right
			if parens.length == 0 and brackets.length == 0
				if count > best_count
					best_count, best_left, best_right = count, left, right-1
				end
				break
			end
			if s[left] == '('
				parens.shift
			elsif s[left] == '['
				brackets.shift
				count -= 1
			end
			left += 1
		end
		parens = []
		brackets = []
		left = right+1
		right = right+1
		count = 0
	end
end
puts best_count
puts s[best_left..best_right]

#!/usr/bin/ruby

s = STDIN.readline.strip + '$'
parens, brackets = [], []
left, right = 0, 0
count, best_count = 0, 0
best_left, best_right = 1, 0
while right < s.length
	#puts 'left = %d, right = %d, count = %d, brackets = %s, parens = %s' % [
	#		left, right, count, brackets, parens]
	ch = s[right]
	error = false
	if ch == '('
		parens.push(right)
	elsif ch == '['
		brackets.push(right)
		count += 1
	elsif ch == ')'
		if parens.length == 0
			error = true
		elsif brackets.length != 0 and brackets[-1] > parens[-1]
			error = true
		else
			parens.pop
		end
	elsif ch == ']'
		if brackets.length == 0
			error = true
		elsif parens.length != 0 and parens[-1] > brackets[-1]
			error = true
		else
			brackets.pop
		end
	else
		error = true
	end
	if not error
		if parens.length == 0 and brackets.length == 0
			if count > best_count
				best_count, best_left, best_right = count, left, right
			end
		end
		right += 1
	else
		next_left = right+1

		# find the longest correct substring preceding the error
		right -= 1
		right -= 1 while right != left and s[right] != ']'
		if right != left
			b, p, count = 0, 0, 0
			seek = right
			while seek >= left
				ch = s[seek]
				if ch == '['
					b -= 1
					count += 1
				elsif ch == ']'
					b += 1
				elsif ch == '('
					p -= 1
				elsif ch == ')'
					p += 1
				end
				if b == 0 and p == 0 and count > best_count
					best_count, best_left, best_right = count, seek, right
				end
				break if b < 0 or p < 0
				seek -= 1
			end
		end

		parens, brackets = [], []
		left = right = next_left
		count = 0
	end
end
puts best_count
puts s[best_left..best_right]

#!/usr/bin/ruby

s = STDIN.readline.strip + '$'
parens, brackets = [], []
left, right = 0, 0
count, best_count = 0, 0
best_left, best_right = 1, 0
best_case = nil
while right < s.length
	ch = s[right]
	error = false
	if ch == '('
		parens.push(right)
	elsif ch == '['
		brackets.push(right)
		count += 1
	elsif ch == ')'
		if parens.length == 0
			error = true
		elsif brackets.length != 0 and brackets[-1] > parens[-1]
			error = true
		else
			parens.pop
		end
	elsif ch == ']'
		if brackets.length == 0
			error = true
		elsif parens.length != 0 and parens[-1] > brackets[-1]
			error = true
		else
			brackets.pop
		end
	else
		error = true
	end
	if not error
		if parens.length == 0 and brackets.length == 0
			if count > best_count
				best_count, best_left, best_right = count, left, right
				best_case = 0
			end
		end
		right += 1
	else
		while left != right
			if parens.length == 0 and brackets.length == 0
				if count > best_count
					best_count, best_left, best_right = count, left, right-1
					best_case = 1
				end
				break
			end
			if s[left] == '('
				parens.shift
			elsif s[left] == '['
				brackets.shift
				count -= 1
			end
			left += 1
		end
		parens = []
		brackets = []
		left = right+1
		right = right+1
		count = 0
	end
end
if s[best_left..best_right] == ']][[[[[]'
	puts 'best_case == %d' % best_case
end
puts best_count
puts s[best_left..best_right]

#!/usr/bin/ruby

s = STDIN.readline.strip + '$'
parens, brackets = [], []
left, right = 0, 0
count, best_count = 0, 0
best_left, best_right = 1, 0
while right < s.length
	ch = s[right]
	error = false
	if ch == '('
		parens.push(right)
	elsif ch == '['
		brackets.push(right)
		count += 1
	elsif ch == ')'
		if parens.length == 0
			error = true
		elsif brackets.length != 0 and brackets[-1] > parens[-1]
			error = true
		else
			parens.pop
		end
	elsif ch == ']'
		if brackets.length == 0
			error = true
		elsif parens.length != 0 and parens[-1] > brackets[-1]
			error = true
		else
			brackets.pop
		end
	else
		error = true
	end
	if not error
		if parens.length == 0 and brackets.length == 0
			if count > best_count
				best_count, best_left, best_right = count, left, right
			end
		end
		right += 1
	else
		while left != right
			if parens.length == 0 and brackets.length == 0
				if count > best_count
					best_count, best_left, best_right = count, left, right-1
				end
			end
			if s[left] == '('
				parens.shift
			elsif s[left] == '['
				brackets.shift
				count -= 1
			end
			left += 1
		end
		left = right = right+1
		count = 0
	end
end
puts best_count
puts s[best_left..best_right]

s = gets.chomp
st = []
seq = []
rev = {}
rev[')'] = '('
rev[']'] = '['
i = 0
s.each_char do |c|
    if (c == '(' || c == '[')
        st.push([i, c])
    elsif (st.size() > 0 && (c == ')' || c == ']') && rev[c] == st.last[1])
        seq.push(st.last)
        seq.push([i, c])
        st.pop
    else
        while (st.size() > 0)
            st.pop
        end
    end
    i += 1
end
seq.sort!
res = "", mx = -1, prv = -1, c = 0, t = ""
for i in seq
    # puts "#{i[0]} #{i[1]}"
    if (i[0] - prv == 1 || prv == -1)
        c += 1 if (i[1] == '[')
        t += i[1]
    else
        if (mx < c)
            mx = c
            res = t.dup
            t = ""
            c = 0
            c += 1 if (i[1] == '[')
            t += i[1]
        end
    end
    prv = i[0]
end

if (mx < c)
    mx = c
    res = t.dup
end
puts mx, res


n = gets.to_i
x = gets.split.map(&:to_i)
v = x[0]
c = [0,0,0,0,0]
n.times do |i|
  c[x[i]-v+2] += 1
end
maxidx = minidx = 2
5.times do |i|
  if c[i] != 0
    minidx = i if i < minidx
    maxidx = i if i > maxidx
  end
end
diff = maxidx - minidx
if diff != 2
  p n
  puts x.join(" ")
else
  num = []
  cnt = [c[minidx],c[minidx+1],c[minidx+2]]
  a = [cnt[0],cnt[2]].min * 4 #incrase cnt[1]
  b = cnt[1]/2 * 4 #decrease cnt[1]
  if a > b
    k = [cnt[0],cnt[2]].min
    num[0] = cnt[0]-k
    num[2] = cnt[2]-k
    num[1] = cnt[1] + k*2
    ans = num[0] + num[1] +num[2] - k*2
  else
    k = cnt[1]/2
    num[0] = cnt[0] + k
    num[1] = cnt[1] - k*2
    num[2] = cnt[2] + k
    ans = num[0] + num[1] +num[2] - k*2
  end
  p ans
  res = []
  3.times do |i|
    res += [v+minidx-2+i] * num[i] if num[i] > 0
  end
  puts res.join(" ")
end
#p c
#p cnt
#p num

n = gets.chomp.to_i
arr = gets.chomp.split(" ").map {|e| e.to_i}
mi = arr.min
ma = arr.max

out = n
mac = 0
mic = 0
if ma - mi > 1
	arr.each do |e|
		if e == mi
			mic +=1
		elsif e == ma
			mac +=1
		end
	end
end
mmc = (n - mic - mac)

if mic > mac
	mic = mac
else
	mac = mic
end
if mmc % 2 != 0
	mmc = mmc - 1
end
if mmc <= (2*mic)
	out -= mic*2
	arr = arr.map do |e|
		if e == mi && mic > 0
			mic -= 1
			e + 1
		elsif e == ma && mac > 0
			mac -= 1
			e-1
		else
			e
		end
	end
elsif (ma - mi) > 1
	out -= mmc
	mm = mi + 1
	i = 1
	arr = arr.map do |e|
		if e == mm && mmc > 0
			i = -i
			mmc -= 1
			e + i
		else
			e
		end
	end
end
puts out
puts arr.join(" ")

n = gets.to_i
x = gets.split.map(&:to_i)
v = x[0]
c = [0,0,0,0,0]
n.times do |i|
  c[x[i]-v+2] += 1
end
maxidx = minidx = 2
5.times do |i|
  if c[i] != 0
    minidx = i if i < minidx
    maxidx = i if i > maxidx
  end
end
diff = maxidx - minidx
if diff != 2
  p 0
  puts x.join(" ")
else
  num = []
  cnt = [c[minidx],c[minidx+1],c[minidx+2]]
  a = [cnt[0],cnt[2]].min * 4 #incrase cnt[1]
  b = cnt[1]/2 * 4 #decrease cnt[1]
  if a > b
    k = [cnt[0],cnt[2]].min
    num[0] = cnt[0]-k
    num[2] = cnt[2]-k
    num[1] = cnt[1] + k*2
    ans = num[0] + num[1] +num[2] - k*2
  else
    k = cnt[1]/2
    num[0] = cnt[0] + k
    num[1] = cnt[1] - k*2
    num[2] = cnt[2] + k
    ans = num[0] + num[1] +num[2] - k*2
  end
  p ans
  m = num[2] - 1 < 0 ? 0 : num[2] - 1
  print "#{v+minidx-2} " * num[0] +  "#{v+minidx-1} " * num[1] +  "#{v+minidx} " * m
  print "#{v+minidx}" if num[2] > 0
end
#p c
#p cnt
#p num

n = gets.to_i
x = gets.split.map(&:to_i)
v = x[0]
c = [0,0,0,0,0]
n.times do |i|
  c[x[i]-v+2] += 1
end
maxidx = minidx = 2
5.times do |i|
  if c[i] != 0
    minidx = i if i < minidx
    maxidx = i if i > maxidx
  end
end
diff = maxidx - minidx
if diff != 2
  p 0
  puts x.join(" ")
else
  num = []
  cnt = [c[minidx],c[minidx+1],c[minidx+2]]
  a = [cnt[0],cnt[2]].min * 4 #incrase cnt[1]
  b = cnt[1]/2 * 4 #decrease cnt[1]
  if a > b
    k = [cnt[0],cnt[2]].min
    num[0] = cnt[0]-k
    num[2] = cnt[2]-k
    num[1] = cnt[1] + k*2
    ans = num[0] + num[1] +num[2] - k*2
  else
    k = cnt[1]/2
    num[0] = cnt[0] + k
    num[1] = cnt[1] - k*2
    num[2] = cnt[2] + k
    ans = num[0] + num[1] +num[2] - k*2
  end
  p ans
  res = []
  3.times do |i|
    res += [v+minidx-2+i] * num[i] if num[i] > 0
  end
  puts res.join(" ")
end
#p c
#p cnt
#p num

n = gets.chomp.to_i
arr = gets.chomp.split(" ").map {|e| e.to_i}
mi = arr.min
ma = arr.max

out = n
mac = 0
mic = 0
if ma - mi > 1
	arr.each do |e|
		if e == mi
			mic +=1
		elsif e == ma
			mac +=1
		end
	end
end
if mic > mac
	mic = mac
else
	mac = mic
end
mic = mic
out -= mic*2
i = 0
arr = arr.map do |e|
	if e == mi && mic > 0
		mic -= 1
		e + 1
	elsif e == ma && mac > 0
		mac -= 1
		e-1
	else
		e
	end
end
puts out
puts arr.join(" ")


gets.to_i.times do
  n = gets.to_i.to_s(2).chars.select { |i| i == ?1 } .size
  puts 2**n
end

gets.to_i.times do
  p 2**gets.to_i.to_s(2).chars.select { |i| i == ?1 } .size
end

t = gets.to_i
t.times do
  a = gets.to_i
  puts 2**a.to_s(2).count('1')
end


n = gets.to_i
h = Hash.new(0)
gets.split.map(&:to_i).each_with_index do |i, j|
	k = i - [j, n - 1 - j].min
	h[k] += 1 if k > 0
end
p n - h.max{|a, b| a[1] <=> b[1]}[1]

N  = gets.to_i
a = gets.split(/\s+/).map {|i| i.to_i}
d = {}
d.default = 0
i, j = 0, N - 1
while i <= j
    if a[i] - i > 0
        d[a[i] - i] += 1
    end
    if i != j && a[j] - i > 0
        d[a[j] - i] += 1
    end
    i += 1
    j -= 1
end

puts N - [1, d.values.max].max

N  = gets.to_i
a = gets.split(/\s+/).map {|i| i.to_i}
d = Array.new(100001, 0)
i, j = 0, N - 1
while i <= j
    d[a[i] - i] += 1 if a[i] - i > 0
    d[a[j] - i] += 1 if i != j && a[j] - i > 0
    i += 1
    j -= 1
end
puts N - [1, d.max].max

N = gets.to_i
a = gets.split(/\s+/).map {|i| i.to_i}
d = Hash.new(0)
i, j = 0, N - 1
while i <= j
    d[a[i] - i] += 1 if a[i] - i > 0
    d[a[j] - i] += 1 if i != j && a[j] - i > 0
    i += 1
    j -= 1
end
puts N - [1, d.values.max].max

n = gets.to_i
h = Hash.new(0)
gets.split.map(&:to_i).each_with_index do |i, j|
	h[i - [j, n - 1 - j].min] += 1
end
p n - h.max{|a, b| a[1] <=> b[1]}[1]


info = gets.chomp.to_i
info.times do
  input  = gets.chomp.to_i
  if input.positive?
    print -(input-1), ' ', input
    puts
  elsif input.negative?
    print input, ' ', -(input)-1
    puts
  else
    print 0, ' ', 0
    puts
  end
end

def i(x)
	x.to_i
end

t = gets
for k in 1..i(t)
	n = gets
	puts "#{-i(n) + 1} #{n}"
end

def i(x)
	x.to_i
end

t = gets
for k in 1..i(t)
	n = gets
	if i(n) == 1
		puts "0 1"
		next
	end
	puts "-#{i(n) - 1} #{n}"
end

def i(x)
	x.to_i
end

t = gets
for k in 1..i(t)
	n = gets
	if n == 1
		puts "0 1"
		next
	end
	puts "-#{i(n) - 1} #{n}"
end


#I could just assign 0 to some graph[i][j] instead of using path
def DFS(v,p)
	#puts v+1
	p.push(v)
	$colour[v] = :grey
	$n.times do |i|
		if $graph[v][i] == 1
			if $colour[i] == :white
				DFS(i,p)
				#p = Array.new
			elsif $colour[i] == :grey
				unless p[p.length-2] == i
					if $cycle == :void
						$cycle = true
						if p.length % 2 == 1
							$students += 1 #p.length - 2
							#puts "ALALAH!: " + v.to_s + ", " + i.to_s
						end
					end
					break
				end
			end
		end
	end
	$colour[v] = :black
	if $cycle == :void
		$cycle = :false
	end
end

#input = File.open('input.txt','r')
$n, m = gets.split#input.
$n = $n.to_i
m = m.to_i
$graph = Array.new($n)#,Array.new(n,0))
$n.times do |i|
	$graph[i] = Array.new($n,0)
end
m.times do |i|
	a, b = gets.split#input.
	#print(a,' ',b,"\n")
	#puts graph[a.to_i-1][b.to_i-1]
	$graph[a.to_i-1][b.to_i-1] = $graph[b.to_i-1][a.to_i-1] = 1
	#puts graph[a.to_i-1][b.to_i-1]
end
# $graph.each do |i|
	# i.each do |j|
		# print j
		# print ' '
	# end
	# puts
# end
$colour = Array.new($n,:white)
$cycle = :void
$students = 0
$n.times do |i|
	if $colour[i] == :white
		path = Array.new
		DFS(i,path)
		$cycle = :void
	end
end
# if $cycle
	# puts "No"
# else
	# puts "Yes"
# end
if ($n - $students) % 2 == 1
	$students += 1
end
puts $students
#assign a value to a variable only if that variable isn't already set:
#@variable ||= "default value"

#x, y = y, x will interchange the values of x and y

#names2 = %w{  ann richard william susan pat }

#puts "Enrollments will now Stop" if participants > 2500

#Negative index values count from the end of the array

n, m = STDIN.readline.split.map {|s| s.to_i }
enemies = {}
(1..n).each {|i| enemies[i] = [] }
m.times do
	a, b = STDIN.readline.split.map {|s| s.to_i }
	enemies[a].push(b)
	enemies[b].push(a)
end
value_side = {}
sides = [[], [], []]
def add(i, target, value_side, sides, enemies)
	okay = true
	value_side[i] = target
	sides[target].push(i)
	next_target = (target == 0 ? 1 : 0)
	enemies[i].each do |j|
		if not value_side[j]
			add(j, next_target, value_side, sides, enemies)
		elsif value_side[j] == target
			sides[target].delete i
			value_side[i] = 2
			sides[2].push(i)
		end
	end
end
(1..n).each do |i|
	next if value_side[i]
	target = (sides[0].length <= sides[1].length ? 0 : 1)
	add(i, target, value_side, sides, enemies)
end
puts sides[2].length + (sides[0].length + sides[1].length)%2

#I could just assign 0 to some graph[i][j] instead of using path
def DFS(v,p)
	#puts v+1
	p.push(v)
	$colour[v] = :grey
	$n.times do |i|
		if $graph[v][i] == 1
			if $colour[i] == :white
				DFS(i,p)
				#p = Array.new
			elsif $colour[i] == :grey
				unless p[p.length-2] == i
					if $cycle == :void
						$cycle = true
						if p.length % 2 == 1
							$students += 1 #p.length - 2
							#puts "ALALAH!: " + v.to_s + ", " + i.to_s
						end
					end
					break
				end
			end
		end
	end
	$colour[v] = :black
	if $cycle == :void
		$cycle = :false
	end
end

#input = File.open('input.txt','r')
$n, m = gets.split#input.
$n = $n.to_i
m = m.to_i
$graph = Array.new($n)#,Array.new(n,0))
$n.times do |i|
	$graph[i] = Array.new($n,0)
end
m.times do |i|
	a, b = gets.split#input.
	#print(a,' ',b,"\n")
	#puts graph[a.to_i-1][b.to_i-1]
	$graph[a.to_i-1][b.to_i-1] = $graph[b.to_i-1][a.to_i-1] = 1
	#puts graph[a.to_i-1][b.to_i-1]
end
# $graph.each do |i|
	# i.each do |j|
		# print j
		# print ' '
	# end
	# puts
# end
$colour = Array.new($n,:white)
$cycle = :void
$students = 0
$n.times do |i|
	if $colour[i] == :white
		path = Array.new
		DFS(i,path)
	end
end
# if $cycle
	# puts "No"
# else
	# puts "Yes"
# end
if ($n - $students) % 2 == 1
	$students += 1
end
puts $students
#assign a value to a variable only if that variable isn't already set:
#@variable ||= "default value"

#x, y = y, x will interchange the values of x and y

#names2 = %w{  ann richard william susan pat }

#puts "Enrollments will now Stop" if participants > 2500

#Negative index values count from the end of the array

#I could just assign 0 to some graph[i][j] instead of using path
def DFS(v,p)
	#puts v+1
	p.push(v)
	$colour[v] = :grey
	$n.times do |i|
		if $graph[v][i] == 1
			if $colour[i] == :white
				DFS(i,p)
			elsif $colour[i] == :grey
				unless p[p.length-2] == i
					$cycle = true
					if p.length % 2 == 1
						$students += 1 #p.length - 2
					end
					break
				end
			end
		end
	end
	$colour[v] = :black
end

#input = File.open('input.txt','r')
$n, m = gets.split#input.
$n = $n.to_i
m = m.to_i
$graph = Array.new($n)#,Array.new(n,0))
$n.times do |i|
	$graph[i] = Array.new($n,0)
end
m.times do |i|
	a, b = gets.split#input.
	#print(a,' ',b,"\n")
	#puts graph[a.to_i-1][b.to_i-1]
	$graph[a.to_i-1][b.to_i-1] = $graph[b.to_i-1][a.to_i-1] = 1
	#puts graph[a.to_i-1][b.to_i-1]
end
# $graph.each do |i|
	# i.each do |j|
		# print j
		# print ' '
	# end
	# puts
# end
$colour = Array.new($n,:white)
$cycle = false
$students = 0
$n.times do |i|
	if $colour[i] == :white
		path = Array.new
		DFS(i,path)
	end
end
# if $cycle
	# puts "No"
# else
	# puts "Yes"
# end
if ($n - $students) % 2 == 1
	$students += 1
end
puts $students
#assign a value to a variable only if that variable isn't already set:
#@variable ||= "default value"

#x, y = y, x will interchange the values of x and y

#names2 = %w{  ann richard william susan pat }

#puts "Enrollments will now Stop" if participants > 2500

#Negative index values count from the end of the array

#I could just assign 0 to some graph[i][j] instead of using path
def DFS(v,p)
	#puts v+1
	p.push(v)
	$colour[v] = :grey
	$n.times do |i|
		if $graph[v][i] == 1
			if $colour[i] == :white
				DFS(i,p)
			elsif $colour[i] == :grey
				unless p[p.length-2] == i
					$cycle = true
					$students += p.length - 2
					break
				end
			end
		end
	end
	$colour[v] = :black
end

#input = File.open('input.txt','r')
$n, m = gets.split#input.
$n = $n.to_i
m = m.to_i
$graph = Array.new($n)#,Array.new(n,0))
$n.times do |i|
	$graph[i] = Array.new($n,0)
end
m.times do |i|
	a, b = gets.split#input.
	#print(a,' ',b,"\n")
	#puts graph[a.to_i-1][b.to_i-1]
	$graph[a.to_i-1][b.to_i-1] = $graph[b.to_i-1][a.to_i-1] = 1
	#puts graph[a.to_i-1][b.to_i-1]
end
# $graph.each do |i|
	# i.each do |j|
		# print j
		# print ' '
	# end
	# puts
# end
$colour = Array.new($n,:white)
$cycle = false
$students = 0
$n.times do |i|
	if $colour[i] == :white
		path = Array.new
		DFS(i,path)
	end
end
# if $cycle
	# puts "No"
# else
	# puts "Yes"
# end
if ($n - $students) % 2 == 1
	$students += 1
end
puts $students
#assign a value to a variable only if that variable isn't already set:
#@variable ||= "default value"

#x, y = y, x will interchange the values of x and y

#names2 = %w{  ann richard william susan pat }

#puts "Enrollments will now Stop" if participants > 2500

#Negative index values count from the end of the array

#I could just assign 0 to some graph[i][j] instead of using path
def DFS(v,p)
	#puts v+1
	p.push(v)
	$colour[v] = :grey
	$n.times do |i|
		if $graph[v][i] == 1
			if $colour[i] == :white
				DFS(i,p)
			elsif $colour[i] == :grey
				unless p[p.length-2] == i
					$cycle = true
					$students += p.length - 2
					break
				end
			end
		end
	end
	$colour[v] = :black
end

#input = File.open('input.txt','r')
$n, m = gets.split#input.
$n = $n.to_i
m = m.to_i
$graph = Array.new($n)#,Array.new(n,0))
$n.times do |i|
	$graph[i] = Array.new($n,0)
end
m.times do |i|
	a, b = gets.split#input.
	#print(a,' ',b,"\n")
	#puts graph[a.to_i-1][b.to_i-1]
	$graph[a.to_i-1][b.to_i-1] = $graph[b.to_i-1][a.to_i-1] = 1
	#puts graph[a.to_i-1][b.to_i-1]
end
# $graph.each do |i|
	# i.each do |j|
		# print j
		# print ' '
	# end
	# puts
# end
$colour = Array.new($n,:white)
$cycle = false
$students = 0
$n.times do |i|
	if $colour[i] == :white
		path = Array.new
		DFS(i,path)
	end
end
# if $cycle
	# puts "No"
# else
	# puts "Yes"
# end
puts $students
#assign a value to a variable only if that variable isn't already set:
#@variable ||= "default value"

#x, y = y, x will interchange the values of x and y

#names2 = %w{  ann richard william susan pat }

#puts "Enrollments will now Stop" if participants > 2500

#Negative index values count from the end of the array

#I could just assign 0 to some graph[i][j] instead of using path
def DFS(v,p)
	#puts v+1
	p.push(v)
	$colour[v] = :grey
	$n.times do |i|
		if $graph[v][i] == 1
			if $colour[i] == :white
				DFS(i,p)
			elsif $colour[i] == :grey
				unless p[p.length-2] == i
					$cycle = true
					$students += p.length - 2
					break
				end
			end
		end
	end
	$colour[v] = :black
end

#input = File.open('input.txt','r')
$n, m = gets.split#input.
$n = $n.to_i
m = m.to_i
$graph = Array.new($n)#,Array.new(n,0))
$n.times do |i|
	$graph[i] = Array.new($n,0)
end
m.times do |i|
	a, b = gets.split#input.
	#print(a,' ',b,"\n")
	#puts graph[a.to_i-1][b.to_i-1]
	$graph[a.to_i-1][b.to_i-1] = $graph[b.to_i-1][a.to_i-1] = 1
	#puts graph[a.to_i-1][b.to_i-1]
end
# $graph.each do |i|
	# i.each do |j|
		# print j
		# print ' '
	# end
	# puts
# end
$colour = Array.new($n,:white)
$cycle = false
$students = 0
$n.times do |i|
	if $colour[i] == :white
		path = Array.new
		DFS(i,path)
	end
end
# if $cycle
	# puts "No"
# else
	# puts "Yes"
# end
if $students % 2 == 1
	$students -= 1
end
puts $students
#assign a value to a variable only if that variable isn't already set:
#@variable ||= "default value"

#x, y = y, x will interchange the values of x and y

#names2 = %w{  ann richard william susan pat }

#puts "Enrollments will now Stop" if participants > 2500

#Negative index values count from the end of the array


N = gets.to_i
A = gets.chomp
B = gets.chomp

n00, n01, n10, n11 = 0, 0, 0, 0

N.times do |i|
    if A[i] == '0'
        if B[i] == '0'
            n00 += 1
        else
            n01 += 1
        end
    else
        if B[i] == '0'
            n10 += 1
        else
            n11 += 1
        end
    end
end

puts (n00+n01) * (n10+n11) - n01*n11

n = gets.to_i
a = gets.chomp
b = gets.chomp

azerocount = 0
bzerocount = 0

b.each_char.with_index do |c,i|
  if c=="0"
    if a[i] == "0"
      azerocount+=1
    end
    bzerocount += 1
  end
end

aone = a.count('1')

#p azerocount
#p bzerocount
#p aone
puts azerocount*aone+(bzerocount-azerocount)*(n-aone-azerocount)


MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end
#def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
q = gi
ans = []
base = ["0","1","2"]
q.times do |i|
  n, k = gsmi
  # RGBは012に変換
  s = gs.gsub(/R/,"0").gsub(/G/,"1").gsub(/B/,"2")
  last =
    if s.length%3==1
      "0"
    elsif s.length%3==2
      "01"
    else
      ""
    end
  ex = base.join * (s.length/3) + last

  #RGBRGB...との差分(距離)をとる
  diff = []
  ex.chars.each.with_index do |str,j|
    d = str.to_i - s[j].to_i
    d = d+3 if d<0
    diff << d
  end
  #debug 'diff', diff.to_s
  # 0,1,2のうちいずれかがk回続けばいい
  a0 = diff[0..(k-1)]
  h=Hash.new(0)
  a0.each{|j|h[j]+=1}
  ar = h.to_a
  #puts ar.to_s
  max = ar.each.map{|j|j[1]}.max
  prev = h
  1.upto(n-k) do |idx|
    prev_i = idx-1
    en = idx+k-1
    h[diff[prev_i]]-=1
    h[diff[en]]+=1
    ar = h.to_a
    #puts ar.to_s
    cnt = ar.each.map{|j|j[1]}.max
    max = cnt if cnt>max
    prev = h
  end

  ans << k-max
end
puts ans

S = "RGB"
gets.to_i.times do
  n, k = gets.split.map(&:to_i)
  s = gets
  a = []
  (0...n - k + 1).each do |i|
    (0...3).each do |j|
      cur = 0
      (0...k).each do |shift|
        cur += 1 if s[i+shift] != S[(j + shift) % 3]
      end
      a << cur
    end
  end
  puts a.min
end

S = "RGB"
gets.to_i.times do
  n, k = gets.split.map(&:to_i)
  s = gets
  a = []
  (0...3).each do |shift|
    d = [0] * n
    cur = 0
    (0...n).each do |i|
      d[i] = (s[i] != S[(i + shift) % 3]) ? 1 : 0
      cur += d[i]
      cur -= d[i - k] if i >= k
      a << cur if i >= k - 1
    end
  end
  puts a.min
end


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

if k == 1
    p 0
    exit
end

k.times {
    a = gets.split(" ")[1..-1].map(&:to_i)
    if a[0] == 1
        i = 0
        i += 1 while i < a.size && a[i] == i + 1
        puts 2 * (n - i) - k + 1
        exit
    end
}

n,m = gets.split.map{ |x| x.to_i }

v = Array.new(n) { [0,0] }
cost,merge = 0,0
real_start = 0
m.times do |i|
  a = gets.split.map{ |x| x.to_i }
  start = 1
  while (a[start] == start)
    start += 1
  end
  if start == 1
    cost += a.size - 1 - start
  else
    cost += a.size - start
    real_start = start
  end
end

merge = n-real_start+1;
#puts "split = #{cost}"
#puts "merge = #{merge}"
puts "#{cost + merge}"

n, k = gets.split.map(&:to_i)
a = k.times.map{gets.split.map(&:to_i)}
a = a.sort_by{|x| x[1]}
accumulate, c = 1, 0
a[0][1..-1].each do |x|
  if x == accumulate
    c += 1
    accumulate += 1
  else
    break
  end
end
ans = (a[0].size - 1 - c) * 2
a[1..-1].each{|x| ans += 2 * x.size - 3}
puts ans

n, k = gets.split.map(&:to_i)
a = k.times.map{gets.split.map(&:to_i)}.sort_by{|x| x[1]}
i = 1
i += 1 while a[0][i + 1] == i + 1
ans = (a[0][1..-1].size - i) * 2
a[1..-1].each{|x| ans += 2 * x[1..-1].size - 1}
puts ans

n, k = gets.split.map(&:to_i)
a = k.times.map{gets.split.map(&:to_i)}.sort_by{|x| x[1]}
accumulate, c = 1, 0
a[0][1..-1].each do |x|
  break if x != accumulate
  c += 1
  accumulate += 1
end
ans = (a[0][1..-1].size - c) * 2
a[1..-1].each{|x| ans += 2 * x[1..-1].size - 1}
puts ans

n, k = gets.split.map(&:to_i)
a = k.times.map{gets.split.map(&:to_i).drop(1)}.find{|x| x[0] == 1}
puts n + n - k + 1 - 2 * a.map.with_index(1).take_while{|x, i| x == i}.size

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

if m == 1
  puts 0
  exit
end

m.times do
  a = gets.split.map(&:to_i)
  a = a[1..-1]

  if a[0] == 1
    i = 0
    i += 1 while i < a.size && a[i] == i + 1

    puts((n - i) + (n - i - (m - 1)))
    exit
  end
end

n, k = gets.split.map(&:to_i)
a = k.times.map{gets.split.map(&:to_i)}
accumulate, c = 1, 0
a[0][1..-1].each do |x|
  if x == accumulate
    c += 1
    accumulate += 1
  else
    break
  end
end
ans = (a[0].size - 1 - c) * 2
a[1..-1].each{|x| ans += 2 * x.size - 3}
puts ans


#!/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