n = gets.to_i
a = gets.chomp.split.map(&:to_i)
c = Array.new(101) { [] }

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

total = c.map(&:length).map { |e| [e, 2].min }.inject(:+)
half = total/2
puts half * (total-half)

b = Array.new(2*n)
cnt = 0

c.each do |e|
  if e.length >= 2
    b[e[0]] = 1
    b[e[1]] = 2
    cnt += 1
  end
end

c.each do |e|
  if e.length == 1
    if cnt < half
      b[e[0]] = 1
      cnt += 1
    else
      b[e[0]] = 2
    end
  end
end

a.each_with_index do |e, i|
  if b[i] == nil
    if cnt < n
      b[i] = 1
      cnt += 1
    else
      b[i] = 2
    end
  end
end

b.each do |e|
  print e , ' '
end
puts

#!/usr/bin/ruby

n = $stdin.readline.to_i
cubes = $stdin.readline.split.map(&:to_i)

cubes_count = Hash.new

cubes.each{|x| cubes_count[x] = (cubes_count[x] == nil ? 1 : cubes_count[x] + 1 )}

a1 = []
a2 = []

cubes_count.each_pair {|key, value|
  if value == 1
    if a1.length < a2.length
      a1.push key
    else
      a2.push key
    end
  else
    a1.push key
    a2.push key
  end
}

a1.sort!
a2.sort!

b1 = a1.length
b2 = a2.length

cubes_count.each_pair {|key, value|
  v = value - 2
  while v > 1
    a1.push key
    a2.push key
    v -= 2
  end
  if v == 1
    if a1.length < a2.length
      a1.push key
    else
      a2.push key
    end
  end
}

# puts "#{cubes_count} #{a1.length} #{a2.length}"
# puts "#{a1}"
# puts "#{a2}"

ans = []

cubes.each_index { |i|
  if a1.include? cubes[i]
    ans[i] = 1
    a1.delete_at(a1.index(cubes[i]))
  else
    ans[i] = 2
    a2.delete_at(a2.index(cubes[i]))
  end
}

# puts ans.inject{|sum,x| sum + x }

puts "#{b1*b2}"
puts ans.join(' ')

n = gets.to_i
given = gets.split.map{|s| s.to_i}
numbers = Array::new(100, 0)
given.each { |cg| numbers[cg] += 1 }
flag0 = 0
flag1 = 0
sum = 0
numbers.map! {|n|
	if n > 0
		if n == 1
			sum += 1
			flag0 = (flag0+1)%2
			n = flag0
		elsif n%2 == 1
			sum += 2
			flag1 = (flag1+1)%2
			n += flag1
		else
			sum += 2
			n
		end
	end
}
if sum%2 == 0
	puts sum*sum/4
else
	puts sum/2*(sum/2 + 1)
end
given.each {|cg|
	print (numbers[cg]%2 + 1).to_s + " "
	numbers[cg] -= 1
}

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

a.each_with_index do |e, i|
  (h[e] ||= []) << i
end

total = h.values.map(&:length).map { |e| [e, 2].min }.inject(:+)
half = total/2
puts half * (total-half)

b = Array.new(2*n)
cnt = 0

h.each do |k, v|
  if v.length >= 2
    b[v[0]] = 1
    b[v[1]] = 2
    cnt += 1
  end
end

h.each do |k, v|
  if v.length == 1
    if cnt < half
      b[v[0]] = 1
      cnt += 1
    else
      b[v[0]] = 2
    end
  end
end

a.each_with_index do |e, i|
  if b[i] == nil
    if cnt < n
      b[i] = 1
      cnt += 1
    else
      b[i] = 2
    end
  end
end

b.each do |e|
  print e , ' '
end
puts

n = gets.to_i
a = gets.chomp.split.map(&:to_i)
h = Hash.new { |h, k| h[k] = [] }

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

tmp = h.values.map(&:length).map { |e| [e, 2].min }.inject(:+)
puts tmp/2*(tmp-tmp/2)

b = Array.new(2*n)
cnt = 0
a.each_with_index do |e, i|
  if b[i] == nil
	b[i] = 1
	h[e].shift
	if !h[e].empty?
	  b[h[e].pop] = 2
	end
	cnt += 1
	if cnt == n
	  break
	end
  end
end

b.each do |e|
  print e ||= 2, ' '
end
puts

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

a.each_with_index do |e, i|
  (h[e] ||= []) << i
end

total = h.values.map(&:length).map { |e| [e, 2].min }.inject(:+)
half = total/2
puts half * (total-half)

b = Array.new(2*n)
cnt = 0
h.each do |k, v|
  if v.length >= 2
	b[v[0]] = 1
	b[v[1]] = 2
	cnt += 1
  end
end

a.each_with_index do |e, i|
  if b[i] != nil
	next
  else
	if cnt < n
	  b[i] = 1
	  cnt += 1
	else
	  b[i] = 2
	end
  end
end

b.each do |e|
  print e , ' '
end
puts

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

a.each_with_index do |e, i|
  (h[e] ||= []) << i
end

total = h.values.map(&:length).map { |e| [e, 2].min }.inject(:+)
half = total/2
puts half * (total-half)

b = Array.new(2*n)
cnt = 0
h.each do |k, v|
  if v.length >= 2
	b[v[0]] = 1
	b[v[1]] = 2
	cnt += 1
  end
end

a.each_with_index do |e, i|
  if b[i] != nil
	next
  else
	if cnt < half
	  b[i] = 1
	  cnt += 1
	else
	  b[i] = 2
	end
  end
end

b.each do |e|
  print e ||= 2, '  '
end
puts

#!/usr/bin/ruby

n = $stdin.readline.to_i
cubes = $stdin.readline.split.map(&:to_i)

cubes_count = Hash.new

cubes.each{|x| cubes_count[x] = (cubes_count[x] == nil ? 1 : cubes_count[x] + 1 )}

a1 = []
a2 = []

cubes_count.each_pair {|key, value|
  v = value
  while v > 1
    a1.push key
    a2.push key
    v -= 2
  end
  if v == 1
    if a1.length < a2.length
      a1.push key
    else
      a2.push key
    end
  end
}

a1.sort!
a2.sort!

b1 = 1
b2 = 1

a1.each_index {|index|
  if index > 0
    if a1[index - 1] != a1[index]
      b1 += 1
    end
  end
}

a2.each_index {|index|
  if index > 0
    if a2[index - 1] != a2[index]
      b2 += 1
    end
  end
}

ans = []

cubes.each_index { |i|
  if a1.include? cubes[i]
    ans[i] = 1
    a1.delete_at(a1.index(cubes[i]) || a1.length)
  else
    ans[i] = 2
    a2.delete_at(a2.index(cubes[i]) || a2.length)
  end
}

puts "#{cubes_count}"
puts "#{a1}"
puts "#{a2}"
puts "#{b1*b2}"
puts ans.join(' ')

#!/usr/bin/ruby

n = $stdin.readline.to_i
cubes = $stdin.readline.split.map(&:to_i)

cubes_count = Hash.new

cubes.each{|x| cubes_count[x] = (cubes_count[x] == nil ? 1 : cubes_count[x] + 1 )}

a1 = []
a2 = []

cubes_count.each_pair {|key, value|
  v = value
  while v > 1
    a1.push key
    a2.push key
    v -= 2
  end
  if value == 1
    if a1.length < a2.length
      a1.push key
    else
      a2.push key
    end
  end
}

a1.sort!
a2.sort!

b1 = 1
b2 = 1

a1.each_index {|index|
  if index > 0
    if a1[index - 1] != a1[index]
      b1 += 1
    end
  end
}

a2.each_index {|index|
  if index > 0
    if a2[index - 1] != a2[index]
      b2 += 1
    end
  end
}

ans = []

cubes.each_index { |i|
  if a1.include? cubes[i]
    ans[i] = 1
    a1.delete_at(a1.index(cubes[i]) || a1.length)
  else
    ans[i] = 2
    a2.delete_at(a2.index(cubes[i]) || a2.length)
  end
}

# puts "#{cubes_count}"
# puts "#{a1}"
# puts "#{a2}"
puts "#{b1*b2}"
puts ans.join(' ')

#!/usr/bin/ruby

n = $stdin.readline.to_i
cubes = $stdin.readline.split.map(&:to_i)

cubes_count = Hash.new

cubes.each{|x| cubes_count[x] = (cubes_count[x] == nil ? 1 : cubes_count[x] + 1 )}

a1 = []
a2 = []

cubes_count.each_pair {|key, value|
  v = value
  while v > 1
    a1.push key
    a2.push key
    v -= 2
  end
  if v == 1
    if a1.length < a2.length
      a1.push key
    else
      a2.push key
    end
  end
}

a1.sort!
a2.sort!

b1 = 1
b2 = 1

a1.each_index {|index|
  if index > 0
    if a1[index - 1] != a1[index]
      b1 += 1
    end
  end
}

a2.each_index {|index|
  if index > 0
    if a2[index - 1] != a2[index]
      b2 += 1
    end
  end
}

ans = []

cubes.each_index { |i|
  if a1.include? cubes[i]
    ans[i] = 1
    a1.delete_at(a1.index(cubes[i]) || a1.length)
  else
    ans[i] = 2
    a2.delete_at(a2.index(cubes[i]) || a2.length)
  end
}

# puts "#{cubes_count}"
# puts "#{a1}"
# puts "#{a2}"
puts "#{b1*b2}"
puts ans.join(' ')


n, l, r, ql, qr = gets.split.map(&:to_i)
w = gets.split.map(&:to_i)

left = Array.new(n+2, 0)
right = Array.new(n+2, 0)

for i in 0...n
  left[i+1] = left[i]+w[i]
  right[n-i] = right[n-i+1]+w[n-i-1]
end

min = 2**30
for i in 0..n
  energy = l*left[i]+r*right[i+1]
  same = n - 2*i
  if same > 1
    energy += (same-1)*qr
  elsif same < -1
    energy -= (same+1)*ql
  end
  if energy < min
    min = energy
  end
end

print min

#f = File.open('test1.txt', 'r')
f = STDIN
n, l, r, Ql, Qr = f.gets.chomp.split.map &:to_i
w = f.gets.chomp.split.map &:to_i
sum = Array.new(w.size)
sum[0] = w[0]
(1...n).each do |i|
  sum[i] = sum[i-1] + w[i]
end

total = -1
(0..n).each do |k|
  tmp_total = 0
  tmp_sum = k == 0 ? 0 : sum[k-1]
  tmp_total += tmp_sum * l + (sum[n-1] - tmp_sum) * r
  if k > n - k
    tmp_total += (2 * k - n - 1) * Ql
  end
  if k < n - k
    tmp_total += (n - 2 * k - 1) * Qr
  end
  if total == -1
    total = tmp_total
  else
    total = [total, tmp_total].min
  end
end
puts total

n, l, r, ql, qr = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

ans = 2**30
sl = 0
sr = a.inject(:+)

for i in (0..n)
  trial = 0
  if 2*i < n
    trial += (n-2*i-1)*qr
  elsif 2*i > n
    trial += (2*i-n-1)*ql
  end
  trial += sl*l + sr*r
  ans = [ans, trial].min
  if i < n
    sl += a[i]
    sr -= a[i]
  end
end

puts ans

n, l, r, ql, qr = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

ans = 1e9
sl = 0
sr = a.inject(:+)

for i in (0..n)
  trial = 0
  if 2*i < n
    trial += (n-2*i-1)*qr
  elsif 2*i > n
    trial += (2*i-n-1)*ql
  end
  trial += sl*l + sr*r
  ans = [ans, trial].min
  if i < n
    sl += a[i]
    sr -= a[i]
  end
end

puts ans

line = gets.split(' ').map(&:to_i)
n = line[0]
l = line[1]
r = line[2]
ql = line[3]
qr = line[4]
a = gets.split(' ').map(&:to_i)
if l < r
  l, r = r, l
  ql, qr = qr, ql
end

a.sort!
ans = 2**32
sl = 0
sr = a.inject(:+)
for i in (0...a.size)
  trial = 0
  if 2*i > a.size
    break
  elsif 2*i < a.size
    trial += (a.size-2*i-1)*qr
  end
  trial += sl*l+sr*r
  ans = [ans, trial].min
  sl += a[i]
  sr -= a[i]
end

puts ans

n, l, r, ql, qr = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

if l < r
  l, r = r, l
  ql, qr = qr, ql
end
a.sort!
ans = 2**32
sl = 0
sr = a.inject(:+)

for i in (0...a.size)
  trial = 0
  if 2*i > a.size
    break
  elsif 2*i < a.size
    trial += (a.size-2*i-1)*qr
  end
  trial += sl*l+sr*r
  ans = [ans, trial].min
  sl += a[i]
  sr -= a[i]
end

puts ans

n, l, r, ql, qr = gets.split.map(&:to_i)
w = gets.split.map(&:to_i)

left = Array.new(n+2, 0)
right = Array.new(n+2, 0)

for i in 0...n
  left[i+1] = left[i]+w[i]
  right[n-i] = right[n-i+1]+w[n-i-1]
end

min = 2**30
for i in 0..n
  energy = l*left[i]+r*right[i+1]
  same = n - 2*i
  if same > 0
    energy += same*qr
  else
    energy -= same*ql
  end
  if energy < min
    min = energy
  end
end

print min


t = gets.to_i
t.times do
    d=gets.split.map &:to_i
    puts d.count{|i|i>d[0]}
end

gets.to_i.times do
  a, b, c, d = gets.split.map(&:to_i)
  ans = 0
  ans += 1 if a < b
  ans += 1 if a < c
  ans += 1 if a < d
  puts ans
end

main = -> {
  t = int
  t.times do
      a, *x = ints

      puts x.count { _1 > a }
  end
}

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

require "set"
require "prime"

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

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

class TrueClass
  include Boolean
  def to_i; 1 end
end

class FalseClass
  include Boolean
  def to_i; 0 end
end

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

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

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

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

main[]

gets.to_i.times do
  a, b, c, d = gets.split.map(&:to_i)
  p [b, c, d].count { |x| x > a }
end

 gets.to_i.times {
 	a,*b = gets.split.map {|x| x.to_i }
 	puts  (b.count{|x| x > a})
 }

t = gets.to_i

inputs = []
(0...t).each do
  arr = gets.chomp
  arr = arr.split(" ").map(&:to_i)
  inputs << arr

end

inputs.each do |arr|
  ans = 0
  # array.each do |arr|
    a = arr[0]
    b = arr[1]
    c = arr[2]
    d = arr[3]

    if a < b
      ans += 1
    end
    if a < c
      ans += 1
    end
    if a < d
      ans += 1
    end
  # end
  puts ans
end

s = gets.to_i

result = []
s.times do |i|
  a, b, c, d = gets.split(" ").map(&:to_i)

  r = 0
  r += 1 if b > a
  r += 1 if c > a
  r += 1 if d > a

  result.push(r)
end

result.each { |line| puts line }

def solve
    v = gets.split.map(&:to_i)
    ans = 0
    if v[1] > v[0]
        ans = ans + 1
    end
    if v[2] > v[0]
        ans = ans + 1
    end
    if v[3] > v[0]
        ans = ans + 1
    end
    puts ans
end

gets.to_i.times do
    solve
end

gets.to_i.times do
  a, b, c, d = gets.split.map(&:to_i)
  ans = 0
  ans += 1 if a <= b
  ans += 1 if a <= c
  ans += 1 if a <= d
  puts ans
end


t = gets.to_i

1.upto t do |i|
  sum = 0
  n, m = gets.split.map(&:to_i)
  if n == 1
    sum = 0
  elsif n == 2
    sum = m
  else
    sum = 2 * m
  end
  puts sum
end

gets.to_i.times do
	a, b = gets.split.map(&:to_i)
	if a == 1
		puts 0
	elsif a == 2
		puts b
	else
		puts b * 2
	end
end

t = gets.to_i
until t==0 do
    n, m = gets.split.map(&:to_i)
    puts [2,n-1].min*m
    t-=1

end

t = gets.chomp.to_i
t.times do |testcase|
  (n,k) = gets.split.map(&:to_i)
  if n == 1
    puts 0
  elsif n == 2
    puts k
  else
    puts k*2
  end
end

gets.to_i.times {
  n, m = gets.split().map do |v|
    v.to_i
  end

  if n == 1
    puts 0
  elsif n == 2
    puts m
  else
    puts m * 2
  end
}

t=gets.chomp.to_i
while (t>0)
	n,m = gets.split.map(&:to_i)
	if(n==1)
		puts"0"
	elsif (n==2)
		puts"#{m}"
	else
		puts"#{m*2}"
	end
	t-=1
end

gets.to_i.times do
  n, m = gets.split.map &:to_i
  puts case n
  when 1
    0
  when 2
    m
  else
    2*m
  end
end

1.upto(gets.to_i) do
  n, m = gets.split(' ').map(&:to_i)

  k = n.div(2)
  l = m.div(k.zero? ? 1 : k)

  puts case n
       when 1
         0
       when 2
         m
       when proc(&:even?)
         2*m
       else
         2*l*k + 2*m.modulo(k)
       end
end

t = gets.to_i

(1).upto(t) do
  a = gets.split(' ').map(&:to_i)
  n = a[0]
  m = a[1]
  if n==1
    puts 0
  elsif n==2
    puts m
  else
    puts m*2
  end
end

t = gets.to_i
until t==0 do
    m, n = gets.split.map(&:to_i)
    puts [2,n-1].min*m
    t-=1

end


def solve(n, b)
  mn, mx = 0, b[0]
  res = []
  b.each_with_index do |e, i|
    if mn + mx == e
      res[i] = mn
      res[b.size * 2 - i -1 ] = mx
    else
      if e - mn > mx
        res[b.size * 2 - i -1 ] = mx
        res[i] = e - mx
      else
        res[i] = mn
        res[b.size * 2 - i -1 ] = e - mn
      end
    end
    mn = res[i]
    mx = res[b.size * 2 - i -1 ]
  end
  res.join(' ')
end

puts solve(gets.strip.to_i, gets.strip.split.map(&:to_i))

n = gets.to_i
b = gets.split.map(&:to_i)
a1,a2 = [],[]
l,r = 0,10**18
b.each_with_index do |v,i|
  r = r < (v-l) ? r : v - l
  l = v - r
  a1 << l
  a2 << r
end
a1.each do |v|
  print "#{v} "
end
(n/2).times do |i|
  v = a2[-i-1]
  print "#{v}"
  print " " if i < (n/2-1)
end


gets

answer = 0
stash = Hash.new { 0 }
gets.chomp.chars.each.with_index do |ch, i|
  if i % 2 == 0
    stash[ch.upcase] += 1
  else
    if stash[ch] > 0
      stash[ch] -= 1
    else
      answer += 1
    end
  end
end
puts answer

# http://codeforces.com/contest/525/problem/A

n = gets.to_i
s = gets.chomp.chars
keys = Hash.new(0)
ans = 0

s.each_slice(2) do |key, door|
  keys[key] += 1
  if keys[door.downcase] >= 1
    keys[door.downcase] -= 1
  else
    ans += 1
  end
end

puts ans

keys = Hash.new(0)
answer = 0
gets
gets.chomp.chars.each_slice(2) do |k,d|
  keys[k] += 1
  if keys[d.downcase] >= 1
    keys[d.downcase] -= 1
  else
    answer += 1
  end
end

puts answer

gets
hs=Hash.new(0)
ans=0
gets.chomp.chars{|e|
	e2=e.downcase
	if e2==e then
		hs[e]+=1
	else
		if hs[e2]>0 then
			hs[e2]-=1
		else
			ans+=1
		end

	end
}
puts ans

gets
a = gets.chomp.split(//)
has = Hash.new(0)
c = 0
a.each do |t|
  if t == t.downcase
    has[t] += 1
  elsif has[t.downcase] == 0
    c += 1
  else
    has[t.downcase] -= 1
  end
end

puts c

n = gets.chomp.to_i;
arr = gets.chomp.split("").map{|x| x.upcase.ord - 65;};
map = Array.new(26, 0);
ans = 0;

(n-1).times do |i|
  i = 2 * i;
  # print i, " ", arr[i], "\n";
  map[arr[i]] += 1;
  i += 1;
  map[arr[i]] -= 1;
  if map[arr[i]] == -1
    map[arr[i]] = 0;
    ans += 1;
  end
end
puts ans;

require 'pp'
def stdin_int; STDIN.gets.chomp.to_i; end
def stdin_ints; STDIN.gets.chomp.split(/ /).map(&:to_i); end

ans = 0

n = stdin_int
s = STDIN.gets.chomp
h = {}
h.default = 0
s.split(//).each_with_index do |c, index|
  if index.even?
    h[c] += 1
  else
    if h[c.downcase] > 0
      h[c.downcase] -= 1
    else
      ans += 1
    end
  end
end

puts ans

n = gets.to_i
a = gets.split("")
r = Array.new(123, 0)
ans = 0
a.each do |x|
  if x == x.downcase
    r[x.ord] += 1
  elsif x == x.upcase
    if r[x.downcase.ord] == 0
      ans += 1
    else
      r[x.downcase.ord] -= 1
    end
  end
end
puts ans

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

def compute(n, s)
  missing_keys = 0
  keys = Hash.new(0)

  n.times do |i|
    break if i == n - 1
    # store the key
    keys[s[i * 2].upcase] += 1

    # unlock the door
    if keys[s[i * 2 + 1]].zero?
      missing_keys += 1
    else
      keys[s[i * 2 + 1]] -= 1
    end
  end
  missing_keys
end

while true
  raw_n = f.gets
  break unless raw_n
  n = raw_n.chomp.to_i
  s = f.gets.chomp
  p compute(n, s)
end

# http://codeforces.com/contest/525/problem/A

n = gets.to_i
s = gets.chomp.chars
keys = []
ans = 0

s.each_slice(2) do |key, door|
  keys << key
  if keys.include?(door.downcase)
    keys.delete key
  else
    ans += 1
  end
end

puts ans

# http://codeforces.com/contest/525/problem/A

n = gets.to_i
s = gets.chomp.chars
keys = Hash.new(0)
ans = 0

s.each_slice(2) do |key, door|
  keys[key] += 1
  if keys[door.downcase] > 0
    keys[key] -= 1
  else
    ans += 1
  end
end

puts ans

require 'pp'
def stdin_int; STDIN.gets.chomp.to_i; end
def stdin_ints; STDIN.gets.chomp.split(/ /).map(&:to_i); end

ans = 0

n = stdin_int
s = STDIN.gets.chomp
h = {}
h.default = 0
s.split(//).each_with_index do |c, index|
  if index.even?
    h[c] += 1
  else
    if h.has_key?(c.downcase)
      h[c] -= 1
    else
      ans += 1
    end
  end
end

puts ans

require 'pp'
def stdin_int; STDIN.gets.chomp.to_i; end
def stdin_ints; STDIN.gets.chomp.split(/ /).map(&:to_i); end

ans = 0

n = stdin_int
s = STDIN.gets.chomp
h = {}
s.split(//).each_with_index do |c, index|
  if index.even?
    h[c] = true
  else
    if h.has_key?(c.downcase)
      h.delete(c.downcase)
    else
      ans += 1
    end
  end
end

puts ans


n = gets.to_i; n=n*n
([(1..n/2).to_a] + [((n/2+1)..n).to_a.reverse]).transpose.each{|x| puts x.join(' ')}

n = gets.to_i
ar = (0...n).map{|x| x*(n+1)+1}
(0...n).reverse_each do |x|
  puts ar.map(&:to_s).join(" ")
  ar = ar.map(&:succ)
  ar[x] -= n
end

n=gets.to_i
a=[*1..n*n].each_slice(n).to_a.transpose
puts (a[0...n/2]+a[n/2..-1].map(&:reverse)).transpose.map{|e|e*' '}

n = gets.chomp.to_i
for i in 1..n
  l = ""
  for j in 1..n
    if j % 2 == 0
      l = l << ((j/2)*2*n-i+1).to_s << " "
    else
      l = l << (i+(j/2)*2*n).to_s << " "
    end
  end
  puts l
end

# -*- encoding: utf-8 -*-
n = gets.chomp.to_i

candies = (1 .. n ** 2).to_a
for i in 0 .. (n - 1) do
  array = []
  (n / 2).times do
    array << candies.shift
    array << candies.pop
  end
  puts array.join(" ")
end

n = STDIN.readline.to_i
lines = []
n.times do |r|
	c = 0
	parts = []
	n.times do |d|
		parts.push((r+d)%n * n + (c+d)%n + 1)
	end
	lines.push(parts.join(' '))
end
puts lines.join("\n")

n = gets.chomp.to_i
a = (1..(n*n)).to_a

a = a.each_slice(a.length/2).to_a
a.last.reverse!
a = a.first.zip(a.last)
puts a.each_slice(n/2).to_a.map{|x| x.flatten.join(' ')}

n=gets.to_i

for i in 0..n-1
	for j in 0..n/2-1
		print 1+(i*n/2)+j," "
	end
	for j in 0..n/2-1
		print n**2-n/2+1-(i*n/2)+j," "
	end
	if i!=n-1
		print "\n"
	end
end

#!/usr/bin/env ruby
n = gets.to_i
ind = 1
for i in 1..n
  str = ""
  for j in 0...n/2
    str += "#{ind} "
    str += "#{n*n+1 - ind} "
    ind += 1
  end
  puts str
end

#!/usr/bin/env ruby
n = gets.to_i
ind = 1
for i in 1..n
  str = ""
  for j in 0...n/2
    str += "#{ind + j} "
  end
  for j in 0...n/2
    str += "#{n*n+1 - ind} "
    ind += 1
  end
  puts str
end

#http://codeforces.com/problemset/problem/129/A

n = gets.to_i

initial_first  = 1
initial_last  = n**2

first = []
second = []
loop do
    first << initial_first
    first << initial_last
    initial_first += 2
    initial_last -= 2
    break if first.size >= n**2
end

first.each_with_index do |i,ind|
  print "#{i} "
  if (ind+1)%n ==0
    puts
  end
end

n =  gets.chomp.to_i

left = 1
right = n*n
(1..n).each do |i|
  (left..left+n/2-1).each { |i| print "#{i} " }
  (right-n/2+1..right).each { |i| print "#{i} " }
  left += n/2
  right -= n/2
  puts
end

arr = (1..gets.to_i ** 2).to_a
while arr.size != 0
  puts "#{arr.shift} #{arr.pop}"
end

n = gets.to_i
a = Array.new(n*n+1);
for i in 1..n*n do
    a[i] = i
  end
l = 0x0
l = 1
r = n*n
begin
  if (l>r) then break end
  printf("%d %d\n", a[l], a[r])
  l += 1
  r -= 1
end while true

n=gets.to_i
res=[]
x=1
n.times {|i|
    res<<[*x..x+n-1]
    res[i].reverse! if i.even?
    x+=n
}
n.times {|i|
    n.times{|j| print "#{res[j][i]} " }
    puts
}

# coding: utf-8

n = gets.to_i
base = [1]
np2 = n * n
while base.last < np2
     new_inc = base.last + (n + 1)
     base << new_inc
end

n.times {
    puts base.join(' ')
    #p "---> #{base.sum}"
    for i in 0...n
        base[i] = (base[i] + n)%np2
    end
}

%{
    먼저 1을 준비한다.
    n이 될때까지 n+1을 더한다.
    이렇게 만들어진 배열의 크기는 n과 같다. ---A
    이 배열의 합은 N = n*n (최대값)이라고 할 때
    (N*(N+1)/2)/n = n*(n*n + 1)/2 이다.
    n이 홀수라면 n*n도 홀수이므로 +1에서 짝수가 되어
    2로 나눌 수 있고, n이 짝수라면 두말할 필요없이 2로 나눠져
    저 결과값은 항상 정수를 유지한다. ----B
    A에서 만들어진 수열의 합은 B의 값과 같다.
    예를 들어 n = 3인 경우는 15, n = 4의 경우는 34이다.
    여기서부터 중요한데, A에서 만들어진 수열에 각각 아래의 연산을 취한다.
    A의 배열 원소를 An이라 할때,
    1) An 에 n을 더한다
    2) 1에 mod n*n 연산을 취해 나머지 값을 얻는다.
    이렇게 되면 항상 일정한 위치의 수끼리 합을 구하게 되므로 일정한 합계가 반복된다.
    이걸 n-1 회 반복하면 원하는 값들을 얻을 수 있다.
    예) n = 3
    step1) [1, 5, 9]
    step2) [4, 8, (3 + 9)%9] -> [4, 8, 3]
    step3) [7, (8 + 3)%9, 6)] -> [7, 2, 6]
    step4) [(7 + 3)%9, 5, 9 ] -> [1, 5, 9] <==> step1

    근데 시발 왜 이게 되지?
}

def main()
	n=gets.chomp.to_i
	ar=Array.new(n){}
	for i in 0...n
		ar[i]=""
	end
	f=true
	j=1
	i=n*n
	while(j<=i)
		if f
			for k in 0...n
				ar[k]+=j.to_s+" "
				j+=1
			end
		else
			for k in 0...n
				l=n-k-1
				ar[l]+=j.to_s+" "
				j+=1
			end
		end
		f=!f
	end
	for i in 0...n
		puts ar[i]
	end
end
main()

n = gets.to_i
a = Array.new(n){|x| x += 1}
n.times do |i|
  b = []
  n.times do |j|
    b << n * j + a[(i + j) % n]
  end
  puts b.join(" ")
end

#16h26
n = gets

def run(n)
  r = n*n
  q = n/2
  n.times do |i|
    st = i*q
    s = (1+st...q+1+st).to_a
    b = (r-q+1-st...r+1-st).to_a
    puts "#{s.join(' ')} #{b.join(' ')}"
  end
end

while n != nil
  run(n.to_i)
  n = gets
end

n=gets.to_i
n.times do |i|
  n.times do |j|
    print(j*n+(j+i)%n+1, ' ')
  end
  puts
end

n = gets.to_i
puts (n**2).times.map(&:next).each_slice(n).each_with_index.map{|x, i| x.rotate i }.transpose.map{|x| x.join ' ' }

n = gets.to_i
n2 = n**2
n.times do |i|
  list = []
  (n/2).times do |j|
    list << i + 1 + j * n
    list << n2 - (i + j * n)
  end
  puts list.join(" ")
end

n=gets.to_i
a=[*1..n].each_slice(n).to_a.transpose
a[n/2..-1].map!(&:reverse)
puts a.transpose.map{|e|e*' '}

n=gets.to_i
a=[*1..n*n].each_slice(n).to_a.transpose
a[n/2..-1].map!(&:reverse)
puts a.transpose.map{|e|e*' '}

#http://codeforces.com/problemset/problem/129/A

n = gets.to_i

initial_first  = 1
initial_last  = n**2

first = []
second = []
n.times do
    first << initial_first
    first << initial_last
    initial_first += 2
    initial_last -= 2
end

second = first.shift(n)

puts first.join(' ')
puts second.join(' ')

#http://codeforces.com/problemset/problem/129/A

n = gets.to_i

initial_first  = 1
initial_last  = n**2

p initial_first
p initial_last

first = []
second = []
n.times do
    first << initial_first
    first << initial_last
    initial_first += 2
    initial_last -= 2
end

second = first.shift(n)

puts first.join(' ')
puts second.join(' ')

n = gets.to_i
([(1..n/2).to_a] + [((n/2+1)..n).to_a.reverse]).transpose.each{|x| puts x.join(' ')}

#16h26
n = gets

def run(n)
  r = n*n
  q = n/2
  n.times do |i|
    s = (i+1...i+q+1).to_a
    b = (r-i-q+1...r-i+1).to_a
    puts "#{s.join(' ')} #{b.join(' ')}"
  end
end

while n != nil
  run(n.to_i)
  n = gets
end


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

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

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

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

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

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

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

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

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

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

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

n = inp[0]
t = inp
m = na(2,0)
m[0] = 0
f = 0
ff = 0
pos = neg = 0
t.each.with_index do |d,i|
  if(d < 0)
    m[0],m[1] = m[1],m[0]
    m[1] += 1
  else
    m[0] += 1
  end
  pos += m[0]
  neg += m[1]
end
puts "#{neg} #{pos}"

def number_of_products
  n = gets.chomp.to_i
  numbers = gets.chomp.split(" ").map(&:to_i)
  positive, negative, a, b = 0, 0, 0, 0
  numbers.each do |num|
    c, d = 0, 0
    if num > 0
      c, d = a+1, b
    else
      c, d = b, a+1
    end
    a, b = c, d
    positive += c
    negative += d
  end
  puts "#{negative} #{positive}"
end

number_of_products


def number_of_steps(crt, target, step)
  ((target - crt).abs.to_f / step).ceil
end

def exact_number_of_steps(crt, target, step)
  (target - crt).abs % step == 0 && number_of_steps(crt, target, step)
end

def min_steps(max, crt, target, step)
  exact = exact_number_of_steps(crt, target, step)
  return exact if exact

  via_beginning = [number_of_steps(crt, 1, step), exact_number_of_steps(1, target, step)]
  via_end = [number_of_steps(crt, max, step), exact_number_of_steps(max, target, step)]

  possibilities = []
  possibilities << via_beginning[0] + via_beginning[1] if via_beginning[1]
  possibilities << via_end[0] + via_end[1] if via_end[1]

  possibilities.min || -1

end

def solution
  test_cases = read_int

  test_cases.times do
    max, crt, target, step = read_ints
    puts min_steps(max, crt, target, step)
  end

end

def read_int
  gets.to_i
end

def read_ints
  gets.split.map(&:to_i)
end

def read_string
  gets.chomp
end

solution unless ENV['TEST__MODE']

gets.to_i.times{
	n,x,y,d=gets.split.map &:to_i
	r = Float::INFINITY
	(y-1)%d==0 && r=[r,(x+d-2)/d+(y-1)/d].min
	(n-y)%d==0 && r=[r,(n+d-x-1)/d+(n-y)/d].min
	(y-x)%d==0 && r=[r,(y-x).abs/d].min
	p r.is_a?(Integer) ? r : -1
}

n = gets.strip.to_i
res = []
n.times do
    len, start, finish, per = gets.strip.split.map(&:to_i)

    if finish == start
        res << 0
        next
    end

    if (finish - start) % per == 0
        res << ((finish - start) / per).abs
    else
        from_start = (finish - 1) % per == 0
        from_end = (len - finish) % per == 0
        if from_start || from_end
            f_s = ((start.to_f/per).ceil + ((finish - 1) / per)).abs
            f_e = (((len - start).to_f / per).ceil + ((len - finish) / per)).abs
            r = 0
            if from_start && from_end
                if f_s > f_e
                    r = f_e
                else
                    r = f_s
                end
            else
                if from_start
                    r = f_s
                else
                    r = f_e
                end
            end
            r = 1 if r == 0
            res << r
        else
            res << -1
        end
    end
end

n.times do |x|
    p res[x]
end

gets.to_i.times do
    n,x,y,d=gets.split.map &:to_i
    if (x-y).abs%d==0
        puts (x-y).abs/d
    else
        a=nil
        a=(x-1+d-1)/d+(y-1+d-1)/d if (y-1)%d==0
        b=nil
        b=(n-x+d-1)/d+(n-y+d-1)/d if (n-y)%d==0
        if a && b
            puts [a, b].min
        elsif a
            puts a
        elsif b
            puts b
        else
            puts -1
        end
    end
end

t = gets.to_i

1..t.times do
  n, start, fin, k = gets.split.map(&:to_i)

  if (fin-start) % k == 0
    puts ((fin-start)/k).abs
  else
    ans = 9999999999
    if (fin-1)%k==0
        ans = (fin-1)/k + ((start-1)/k.to_f).ceil
    end

    if (n-fin)%k==0
        ans = [ans, (n-fin)/k + ((n-start)/k.to_f).ceil].min
    end

    if ans == 9999999999
        puts -1
    else
        puts ans
    end
  end
end

t = gets.to_i

t.times do
  nxyd = gets.chomp.split(" ").map(&:to_i)
  n = nxyd[0]
  x = nxyd[1]
  y = nxyd[2]
  d = nxyd[3]
  if (x%d==y%d)
    ans = (x-y).abs/d
  else
    if (y%d==1)
      ans = ((x.to_f-1)/d).ceil + ((y.to_f-1)/d).ceil
      if (n%d==1)
        ans = [ans,((n.to_f-x)/d).ceil+((n.to_f-y)/d).ceil].min
      end
    elsif (n%d==y%d)
      ans = ((n.to_f-x)/d).ceil+((n.to_f-y)/d).ceil
    else
      ans = -1
    end
  end

  puts ans
end

t = gets.to_i
t.times do
    n, x, y, d = gets.split.map{|x| x.to_i}
    x, y = y, x if x > y
    a = []
    a << (y - x)/d if (y - x)%d == 0
    a << (y - 1)/d + (x - 1 + d - 1)/d if (y - 1)%d == 0
    a << (n - y)/d + (n - x + d - 1)/d if (n - y)%d == 0
    puts(a.min || -1)
end

t = gets.to_i

t.times do
  nxyd = gets.chomp.split(" ").map(&:to_i)
  n = nxyd[0]
  x = nxyd[1]
  y = nxyd[2]
  d = nxyd[3]
  if (x%d==y%d)
    ans = (x-y).abs/d
  else
    if (y%d==1)
      ans = ((x.to_f-1)/d).ceil + ((y.to_f-1)/d).ceil
      if (n%d==1)
        ans = [ans,((n.to_f-x)/d).ceil+((y.to_f-1)/d).ceil].min
      end
    elsif (n%d==y%d)
      ans = ((n.to_f-x)/d).ceil+((y.to_f-1)/d).ceil
    else
      ans = -1
    end
  end

  puts ans
end

gets.to_i.times{
	n,x,y,d=gets.split.map &:to_i
	r = Float::INFINITY
	(y-1)%d==0 && r=[r,(x+d-2)/d+(y-1)/d].min
	(n-y)%d==0 && r=[r,(x+d-x-1)/d+(n-y)/d].min
	(y-x)%d==0 && r=[r,(y-x).abs/d].min
	p r.is_a?(Integer) ? r : -1
}

n = gets.strip.to_i
res = []
n.times do
    len, start, finish, per = gets.strip.split.map(&:to_i)

    if finish == start
        res << 0
        next
    end

    if (finish - start) % per == 0
        res << ((finish - start) / per).abs
    else
        from_start = (finish - 1) % per == 0
        from_end = (len - finish) % per == 0
        if from_start || from_end
            f_s = ((finish.to_f/per).floor + ((finish - 1) / per)).abs
            f_e = (((len - start).to_f / per).ceil + ((len - finish) / per)).abs
            r = 0
            if from_start && from_end
                if f_s > f_e
                    r = f_e
                else
                    r = f_s
                end
            else
                if from_start
                    r = f_s
                else
                    r = f_e
                end
            end
            r = 1 if r == 0
            res << r
        else
            res << -1
        end
    end
end

n.times do |x|
    p res[x]
end

n = gets.strip.to_i
res = []
n.times do
    len, start, finish, per = gets.strip.split.map(&:to_i)
    if (finish - start) % per == 0
        res << ((finish - start) / per).abs
    else
        from_start = (finish - 1) % per == 0
        from_end = (len - finish) % per == 0
        if from_start || from_end
            f_s = ((finish.to_f/per).floor + ((finish - 1) / per)).abs
            f_e = (((len - start).to_f / per).ceil + ((len - finish) / per)).abs
            if from_start && from_end
                if f_s > f_e
                    res << f_e
                else
                    res << f_s
                end
            else
                if from_start
                    res << f_s
                else
                    res << f_e
                end
            end
        else
            res << -1
        end
    end
end

n.times do |x|
    r = res[x]
    r = 1 if r == 0
    p r
end


# coding: utf-8

n = gets.to_i
ad = {}
gets.split.each { |i|
    i = i.to_i
    ad[i] ||= 0
    ad[i] += 1
}
sorted_keys = ad.keys.sort

if ad.length <= 2
    puts "0"
else
    puts n - (ad[sorted_keys.first] + ad[sorted_keys.last])
end

n = gets.chomp
arr= gets.split().map(&:to_i)
arr.sort!
min_val =arr.min
max_val = arr.max
count = 0
arr.each{|i| if i>min_val and i<max_val then count+=1;end}
puts count

n = gets.strip.to_i
a = gets.strip.split.map(&:to_i).sort
i = 1
min_s = a[0]
max_s = a[n - 1]
ans = 0
while i < n - 1
    ans += 1 if min_s < a[i] && a[i] < max_s
    i += 1
end
puts ans

h=Hash.new(0)
n=gets.to_i
x=gets.split.map{|e| e.to_i}.sort
x.each{|e|
	h[e]+=1
}
x=h.to_a
x.pop
x.shift
ans=0
x.each{|e|
	ans+=e[1]
}
puts ans

#!/usr/bin/env ruby

stewards_count = gets.to_i
stewards_values = gets.split.map(&:to_i)

#
max = min = stewards_values.first
stewards_map = Hash.new(0)
stewards_values.each do |v|
  stewards_map[v] += 1
  min = v if v < min
  max = v if v > max
end

count = 0
(stewards_map.keys - [min, max]).each do |v|
  count += stewards_map[v]
end

puts count

n=gets.to_i
x=gets.split.map{|e| e.to_i}

arr=[]
x.inject(x[0]){|e1,e2|
	arr<<(e2-e1).abs
	e2
}
puts arr.count{|e| e==1}

h=Hash.new(0)
n=gets.to_i
x=gets.split.map{|e| e.to_i}.sort
x.each{|e|
	h[e]+=1
}
x=h.to_a
x.pop
x.shift
p x.size

n=gets.to_i
x=gets.split.map{|e| e.to_i}.sort

arr=[]
x.inject(x[0]){|e1,e2|
	arr<<(e2-e1).abs
	e2
}
puts arr.count{|e| e==1}

h=Hash.new(0)
n=gets.to_i
x=gets.split.map{|e| e.to_i}.sort
x.each{|e|
	h[e]+=1
}
x=h.to_a
ans=0
x.inject(x[0]){|e1,e2|
	if e1[0]+1==e2[0] then
		ans+=e1[1]*e2[1]
	end
	e2
}
p ans

# coding: utf-8

n = gets.to_i
ad = {}
gets.split.each { |i|
    i = i.to_i
    ad[i] ||= 0
    ad[i] += 1
}

if ad.length - 2 <= 0
    puts "0"
else
    puts ad.length - 2
end


input_1 = gets.split.map(&:to_i)
input_2 = gets.split.map(&:to_i)

b = input_1[0]
k = input_1[1]

b_flag = 0
k_flag = 0
odd_count = 0

if b % 2 == 0
  b_flag = 0
else
  b_flag = 1
end

for i in 0..k - 2 do
  if input_2[i] % 2 != 0
    odd_count += 1
  end
end

if b_flag == 0
  if input_2[k - 1] % 2 == 0
    puts "even"
  else
    puts "odd"
  end
else
  if odd_count % 2 == 0
    if input_2[k - 1] % 2 == 0
      puts "even"
    else
      puts "odd"
    end
  else
    if input_2[k - 1] % 2 == 0
      puts "odd"
    else
      puts "even"
    end
  end
end

b,k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
ans = 0
if b%2 == 0
    ans ^= a[-1]%2
else
    for i in 0..k-1
        ans ^= a[i]%2
    end
end
puts (ans == 1 ? "odd" : "even")

DBG = true
b,k = gets.split.map{|z| z.to_i}
a = gets.split.map{|z| z.to_i}
if b%2 == 0
  iseven = (a[-1]%2 == 0)
else
  iseven = (a.inject(:+)%2 == 0)
end
puts (iseven ? "even" : "odd")

input_1 = gets.split.map(&:to_i)
input_2 = gets.split.map(&:to_i)

b = input_1[0]
k = input_2[1]

b_flag = 0
k_flag = 0
odd_count = 0

if b % 2 == 0
  b_flag = 0
else
  b_flag = 1
end

input_2.each do |num|
  if num % 2 != 0
    odd_count += 1
  end
end

if b_flag == 0
  puts "even"
else
  if odd_count % 2 == 0
    puts "even"
  else
    puts "odd"
  end
end


def r()
   gets.split().map(&:to_i)
end
a,b = r()
q = gets.to_i
g = a.gcd(b)
d = []
i = 1
while i*i<=g do
  d+=[i, g/i] if g%i==0
  i+=1
end
d.sort!
for i in (0..q-1)
  l,r=r()
  a = d.reject{|e| e>r}[-1]
  a = -1 if a<l
  print "#{a}\n"
end

a,b = gets.split().map(&:to_i)
q = gets.to_i
g = a.gcd(b)
d = []
i = 1
while i*i<=g do
  if g%i==0
    d<< i
    d<< g/i
  end
  i+=1
end
d.sort!
for i in (0..q-1)
  l,r=gets.split(' ').map(&:to_i)
  a=0
  for i in d
    if i<=r
      a = i
    else
      break
    end
   end
   print "#{a}\n" if a>=l
   print "-1\n" if a<l
end

a,b = gets.split().map(&:to_i)
q = gets.to_i
g = a.gcd(b)
d = []
i = 1
while i*i<=g do
  d+=[i, g/i] if g%i==0
  i+=1
end
d.sort!
for i in (0..q-1)
  l,r=gets.split(' ').map(&:to_i)
  a=0
  for i in d
      a = i  if i<=r
  end
  a = -1 if a<l
  print "#{a}\n"
end

def r()
   gets.split().map(&:to_i)
end
a,b = r()
q = gets.to_i
g = a.gcd(b)
d = []
i = 1
while i*i<=g do
  d+=[i, g/i] if g%i==0
  i+=1
end
d.sort!
for i in (0..q-1)
  l,r=r()
  a=0
  for i in d
      a = i  if i<=r
  end
  a = -1 if a<l
  print "#{a}\n"
end

def divisors(n)
  factors = Hash.new(0).tap do |f|
    d = 1
    2.step(n, d).each do |i|
      break if i * i > n
      while n % i == 0
        n /= i
        f[i] += 1
      end
      d = 2
    end
    f[n] += 1 unless n == 1
  end.to_a

  [].tap do |ret|
    f = lambda do |i, r|
      if i == factors.size
        ret << r
        return
      end
      (factors[i][1] + 1).times do
        f.call(i + 1, r)
        r *= factors[i][0]
      end
    end
    f.call(0, 1)
  end
end

a, b = gets.chomp.split.map{|s| s.to_i}
cds = (divisors(a) & divisors(b)).sort
ret = []
gets.to_i.times do
  result = -1
  r = gets.chomp.split.map{|s| s.to_i}
  min, max = 0, cds.size - 1
  n = r[1]
  while min <= max
    mid = (min + max) / 2
    if n == cds[mid]
      min = mid
      break
    elsif n < cds[mid]
      max = mid - 1
    else
      min = mid + 1
    end
  end
  i =  min
  i -= 1 unless cds[i] == r[1]
  if cds[i] < r[0]
    ret << -1
  else
    ret << cds[i]
  end
end
ret.each{|s| puts s}

def search(x,res)
        lb=-1
        ub=res.length
        while ub-lb>1
                mid=(ub+lb)>>1
                if res[mid]<=x then
                        lb=mid
                else
                        ub=mid
                end
        end
        return ub
end

input=gets.split.map(&:to_i)
a=input.min
b=input.max

res=[]
for i in 1..a
        if i*i>a then
                break
        end
        if a%i ==0 then
                if b%i==0 then
                        res.push(i)
                end
        end
end
for i in 1..a
        if i*i>=a then
                break
        end
        if a%i ==0 then
                if b%(a/i)==0 then
                        res.push(a/i)
                end
        end
end
res.sort!

#p res
#p search(2,res)
q=gets.to_i
(1..q).each{
        input=gets.split.map(&:to_i)
        x=res[search(input[1],res)-1]
        if x>=input[0] then
                puts x
        else
                puts -1
        end
}

def factors(n)
  Hash.new(0).tap do |factors|
    d = 1
    2.step(n, d).each do |i|
      next if i * i > n
      while n % i == 0
        n /= i
        factors[i] += 1
      end
      d = 2
    end
    factors[n] += 1 unless n == 1
  end.to_a
end

def divisors(factors)
  [].tap do |ret|
    f = lambda do |i, r|
      if i == factors.size
        ret << r
        return
      end
      (factors[i][1] + 1).times do
        f.call(i + 1, r)
        r *= factors[i][0]
      end
    end
    f.call(0, 1)
  end
end

def bsearch(array, n)
  min, max = 0, array.size - 1
  while min <= max
    mid = (min + max) / 2
    if n == array[mid]
      return mid
    elsif n < array[mid]
      max = mid - 1
    else
      min = mid + 1
    end
  end
  return min
end

a, b = gets.chomp.split.map{|s| s.to_i}
cds = divisors(factors(a)) & divisors(factors(b))
ret = []
gets.to_i.times do
  result = -1
  r = gets.chomp.split.map{|s| s.to_i}
  i = bsearch(cds, r[1])
  i -= 1 unless cds[i] == r[1]
  if cds[i] < r[0]
    ret << -1
  else
    ret << cds[i]
  end
end
ret.each{|s| puts s}

require 'mathn'
a, b = gets.chomp.split.map{|s| s.to_i}
divisors = (2..[a,b].min).select do |i|
  a % i == 0 && b % i == 0
end
ret = []
gets.to_i.times do
  i = gets.chomp.split.map{|s| s.to_i}
  if n = divisors.detect{|d| (i[0]..i[1]).to_a.include?(d)}
    ret << n
  else
    ret << -1
  end
end
ret.each{|i| puts i}

def bsearch(array, n)
  min, max = 0, array.size - 1
  while min <= max
    mid = (min + max) / 2
    if n == array[mid]
      return mid
    elsif n < array[mid]
      max = mid - 1
    else
      min = mid + 1
    end
  end
  return min
end
a, b = gets.chomp.split.map{|s| s.to_i}
divisors = [1]
(2..(a > b ? b : a)).each do |i|
  divisors << i if a % i == 0 && b % i == 0
end
ret = []
gets.to_i.times do
  result = -1
  r = gets.chomp.split.map{|s| s.to_i}
  if divisors.last < r[0]
  elsif r[1] < divisors.first
  end
  i = bsearch(divisors, r[1])
  i -= 1
  if divisors[i] < r[0]
    ret << -1
  else
    ret << divisors[i]
  end
end
ret.each{|i| puts i}


gets.to_i.times do

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

  res = 0
  m = n + n -1
  hs = Hash[(1..arr.length).zip arr].lazy.
    sort_by{|i, v| v}

  (0..m).each do |i|
    j = i+1
    e = m/hs[i][1]
    break if j >= n or hs[j][1] > e
    while j < n and hs[j][1] <= e
      res += 1 if hs[i][1]*hs[j][1] == hs[i][0] + hs[j][0]

      j += 1
    end
  end
  puts res
end

t = gets.to_i
t.times{ |x|
  n = gets.to_i
  res = 0
  m = n + n -1
  arr = gets.chomp.split(" ").map(&:to_i)
  hs = Hash[(1..arr.length).zip arr].lazy.
    sort_by{|i, v| v}
  #p hs
  (0..m).each{ |i|
    j = i+1
    e = m/hs[i][1]
    #p j
    #p n
    #p j >= n
    break if j >= n or hs[j][1] > e
    while j < n and hs[j][1] <= e
      res += 1 if hs[i][1]*hs[j][1] == hs[i][0] + hs[j][0]

      j += 1
    end
  }
  puts res
}


gets.to_i.times { puts ([1] * gets.to_i).join(' ')  }

t = gets.chomp.to_i
#p n
t.times do
    n = gets.chomp.to_i
    i = 0
    until n == i
        a = 1
        print a
        if i != n- 1
        print " "
        end
        i += 1
    end
    print "\n"
end

t = gets.to_i
t.times do
	n = gets.to_i
	puts "1 "*n
end

gets.to_i.times do
    res = ""
    gets.to_i.times do
        res += "1 "
    end
    puts res
end


n = gets.to_i
a = gets.chomp.split.map(&:to_i)
b = a.sort
if a == b
  puts "YES"
  exit
end
count = 0
n.times do |i|
  count +=1 if a[i] != b[i]
end
puts count == 2 ? "YES" : "NO"

n = gets.to_i
a = gets.split.map &:to_i
b = a.sort
s = 0
a.zip(b).each do |x, y|
  s += x != y ? 1 : 0
end
puts s > 2 ? "NO" : "YES"

n = gets.to_i
ar = gets.split.map(&:to_i)
br = ar.sort

cnt = 0
n.times do |i|
	cnt += 1 if ar[i] != br[i]
end

puts (cnt >2 ? "NO":"YES")

STDIN.readline.to_i; numbers = STDIN.readline.split(' ').map { |x| x.to_i }
sorted = numbers.sort

count = 0
for i in 0..sorted.length
  count += 1 if sorted[i] != numbers[i]
end

if count <= 2; puts "YES"; else puts "NO"; end

n=gets.to_i
a=gets.split.map(&:to_i)
b=a.sort
pos=0
n.times{|i|pos+=1 unless a[i]==b[i]}
puts pos<3 ? "YES" : "NO"

n = gets.to_i
a = gets.split.map(&:to_i)
b = a.sort
cnt = 0
for i in 0..n - 1 do
    cnt += 1 if a[i] != b[i]
end
puts "YES" if cnt <= 2
puts "NO" if cnt > 2

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

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

c = a.zip(a.sort).count { |x, y| x != y }
puts (c <= 2 ? 'YES' : 'NO')

n = gets.to_i
arr = gets.split(" ").map(&:to_i)
c = 0
sorted = arr.sort
arr.each_with_index do |a,i|
	c += 1 if a != sorted[i]
end
puts c <= 2 ? "YES" : "NO"

n = gets.to_i
a = gets.split.collect{|i| i.to_i}
b = a.sort
cnt = 0
for i in 0...n
    if a[i] != b[i]
        cnt += 1
    end
end
if cnt <= 2
    puts 'YES'
else
    puts 'NO'
end

n = gets.to_i
arr = gets.split(" ").map(&:to_i)
c = 0
arr.each_with_index do |a,i|
	c += 1 if a != (i + 1 )
end
puts c <= 2 ? "YES" : "NO"


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

a = []

n.times do
	a << gets.strip.split(' ').map(&:to_i)
end

max_till_now = 0

mp = Hash.new(nil)
bool = true
a.each do |x|
	mp[x[0]] = true
	mp[x[1]] = true
	if x[0] > max_till_now
		bool = false
		break
	else
		max_till_now = [x[1], max_till_now].max
	end
end

if !bool
	puts 'NO'
else
	if mp[m]
		puts 'YES'
	else
		puts 'NO'
	end
end

n,m=gets.split.map &:to_i
last=0
n.times{
	a,b=gets.split.map &:to_i
	if a>last
		puts :NO
		exit
	else
		last=[b,last].max
		if last>=m
			puts :YES
			exit
		end
	end
}
puts :NO

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

for i in 1..n
  st, en = gets.chomp.split.map(&:to_i)
  if st > pos
    puts "NO"
    exit 0
  else
    pos = [pos, en].max
  end
end

if pos >= m
  puts "YES"
else
  puts "NO"
end

#!/bin/ruby

n, m = gets.strip.split(' ')
n = n.to_i
m = m.to_i
visiting = 'NO'
ps = 0
pd = 0
for i in (1..n)
    s, d = gets.strip.split(' ')
    s = s.to_i
    d = d.to_i
    if s.between? ps, pd
        ps = s
        pd = d if pd <= d
        if m.between? s, d
            visiting = 'YES'
            break
        end
    else
        visiting = 'NO'
        break
    end
end
puts visiting

#!/bin/ruby

n, m = gets.strip.split(' ')
n = n.to_i
m = m.to_i
visiting = 'NO'
ps = 0
pd = 0
for i in (1..n)
    s, d = gets.strip.split(' ')
    s = s.to_i
    d = d.to_i
    if s.between? ps, pd
        ps = s
        pd = d
        if m.between? s, d
            visting = 'YES'
            break
        end
    else
        visting = 'NO'
        break
    end
end
puts visting

#!/bin/ruby

n, m = gets.strip.split(' ')
n = n.to_i
m = m.to_i
visiting = 'NO'
ps = 0
pd = 0
for i in (1..n)
    s, d = gets.strip.split(' ')
    s = s.to_i
    d = d.to_i
    if s.between? ps, pd
        ps = s
        pd = d
        if m.between? s, d
            visiting = 'YES'
            break
        end
    else
        visiting = 'NO'
        break
    end
end
puts visiting

#!/bin/ruby

n, m = gets.strip.split(' ')
n = n.to_i
m = m.to_i
ps = 0
pd = 0
for i in (1..n)
    s, d = gets.strip.split(' ')
    s = s.to_i
    d = d.to_i
    if s.between? ps, pd
        ps = s
        pd = d
        if m.between? s, d
            visting = 'YES'
            break
        end
    else
        visting = 'NO'
        break
    end
end
puts visting

#!/bin/ruby

n, m = gets.strip.split(' ')
n = n.to_i
m = m.to_i
ps = 0
pd = 0
for i in (1..n)
    s, d = gets.strip.split(' ')
    s = s.to_i
    d = d.to_i
    if pd.between? s, d
        pd = d
        if m.between? s, d
            visting = 'YES'
            break
        end
    else
        visting = 'NO'
        break
    end
end
puts visting

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

a = []

n.times do
	a << gets.strip.split(' ').map(&:to_i)
end

max_till_now = a[0][0]

mp = Hash.new(nil)
bool = true
a.each do |x|
	mp[x[0]] = true
	mp[x[1]] = true
	if x[0] > max_till_now
		bool = false
		break
	else
		max_till_now = [x[1], max_till_now].max
	end
end

if !bool
	puts 'NO'
else
	if mp[m]
		puts 'YES'
	else
		puts 'NO'
	end
end

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

a = []

n.times do
	a << gets.strip.split(' ').map(&:to_i)
end

max_till_now = a[0][0]

mp = Hash.new(0)
bool = true
a.each do |x|
	mp[x[0]] = true
	mp[x[1]] = true
	if x[0] > max_till_now
		bool = false
		break
	else
		max_till_now = [x[1], max_till_now].max
	end
end

if !bool
	puts 'NO'
else
	if mp[m]
		puts 'YES'
	else
		puts 'NO'
	end
end

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

a = []

n.times do
	a << gets.strip.split(' ').map(&:to_i)
end

max_till_now = 0

mp = Hash.new(0)
bool = true
a.each do |x|
	mp[x[0]] = true
	mp[x[1]] = true
	if x[0] > max_till_now
		bool = false
		break
	else
		max_till_now = [x[1], max_till_now].max
	end
end

if !bool
	puts 'NO'
else
	if mp[m]
		puts 'YES'
	else
		puts 'NO'
	end
end


copy = gets.chomp
ans = -1
last = copy[-1].to_i

# if copy.length < 20
# (0..(copy.length - 1)) do |i|
# 	v = copy[i].to_i
# 	if v.even? && v < last
# 		copy[i],copy[-1] = copy[-1],copy[i]
# 		ans = copy.to_i
# 		break
# 	end
# end
# if ans == -1
# 	((copy.length - 1).downto(0)).each do |i|
# 		v = copy[i].to_i
# 		if v.even? && v > last
# 			copy[i],copy[-1] = copy[-1],copy[i]
# 			ans = copy.to_i
# 			break
# 		end
# 	end
# end
# even_nos = copy.each_char.with_index.map{|k,i| [k.to_i,i] if k.to_i.even?}.compact
copy.each_char.with_index do |e,i|
	v = e.to_i
	next if v.to_i.odd?

	if v < last
		ans = i
		break
	else
		ans = i
	end
end
if ans != -1
	copy[ans],copy[-1] = copy[-1],copy[ans]
	ans = copy
end
puts ans
# else

# 	copy.each_char.with_index do |e,i|
# 	v = e.to_i
# 	next if v.to_i.odd?

# 	if v < last
# 		ans = i
# 		break
# 	else
# 		ans = i
# 	end
# 	end
# 	#
# 	puts copy[-1]
# end

n = gets.strip
if n.chars.all? {|x| x.to_i.odd?}
	puts -1
else
	m = n.chars.select{|x| x.to_i.even?}
	i = m.min > n[-1] ? n.rindex(m[-1]) : n.index(m.find{|x| x < n[-1]})
	n[i], n[-1] = n[-1] , n[i]
	puts n
end

n = gets.chomp
if n.each_char.all?{|x| x.to_i.odd?}
  puts -1
else
  m = []
  n.each_char{|x| m << x if x.to_i.even?}
  i = if m.all?{|x| x > n[-1]}
        n.rindex(m[-1])
      else
        n.index(m.find{|x| x < n[-1]})
      end
  n[i], n[-1] = n[-1], n[i]
  puts n
end

a=gets.chomp.split('').map(&:to_i)
n=a.length
i,max,x=0,-1,-1
while i<n
	if a[i]&1==0
		max,x=a[i],i
		break if max<a[n-1]
	end
	i+=1
end
if max==-1
	puts "-1"
else
	i=a[x]
	a[x]=a[n-1]
	a[n-1]=i
	puts a.join
end

n = gets.chomp
if n.chars.all?{|x| x.to_i.odd?}
  puts -1
else
  m = n.chars.select{|x| x.to_i.even?}
  i = if m.min > n[-1]
        n.rindex(m[-1])
      else
        n.index(m.find{|x| x < n[-1]})
      end
  n[i], n[-1] = n[-1], n[i]
  puts n
end

a=gets.chomp
t=-1
mi=-10
(a.length-2).downto(0) do |i|
if a[i].to_i%2==0
if t==-1
t=i
next
end
if a[i]<a[a.length-1]
t=i
end
end

end

if t==-1
puts "-1"
else
mi=a[a.length-1]
a[a.length-1]=a[t]
a[t]=mi
puts a
end

n=gets.chomp
m=n.size-1

ans=""

last1=n[m].to_i
p1=-1
m.times{|i|
	e=n[i].to_i
	if e%2==0 && e<last1 then
		p1=i
		break
	end
}
if p1!=-1 then
	n[p1],n[m]=n[m],n[p1]
	ans=(n+"")
	n[p1],n[m]=n[m],n[p1]
end

i=m-1
p1=-1
while i>=0
	e=n[i].to_i
	if e%2==0 && e>last1 then
		p1=i
		break
	end
	i-=1
end

if p1!=-1 then
	n[p1],n[m]=n[m],n[p1]
	ans=n if ans<n
end
if ans=="" then
	puts -1
else
	puts ans
end

a=Array.new
str=gets.to_s
a=str.split("")
h=-1
for i in 0..a.length-2
#  puts a.length
  if a[i].to_i%2==0
    h=i
  end
  if a[i].to_i%2==0 and a[i].to_i<a[-2].to_i
#   a[-1] 字符串最后一般是换行符，可用chomp方法去除
#    puts a[-2]
    t=a[-2]
    a[-2]=a[i]
    a[i]=t
    h=-2
    break
  end
end
if h==-2
  for i in 0..a.length-1
    print a[i].chomp
  end
  puts
elsif h==-1
  puts -1
else
  t=a[-2]
  a[-2]=a[h]
  a[h]=t
   for i in 0..a.length-1
    print a[i].chomp
   end
   puts
end

def check(s)
	unless s=~/[02468]/
		puts "-1"
		return
	end
	i=0
	flag=false
	hold=s[-1].to_i
	max=-1
	found=false
	while true && i<=8
		if i<hold
			m=s=~/#{i}/
		else
			m=s.reverse=~/#{i}/
			flag=true
		end
		if $~
			if flag
				if found
					break
				end
				m=s.size-m-1
				if m>max
					max=m
				end
			else
				found=true
				if max==-1 || max>m
					max=m
				end
			end
		end
		$~=nil
		i+=2
	end
	#puts max
	puts s[0...max]+s[-1]+s[max+1...-1]+s[max]
end
s=gets.chomp.to_s
check(s)

# coding: utf-8

# 한 자리의 숫자(반드시 짝수) 와 마지막 자리(반드시 홀수)를 교체했을 때
# 가장 큰 숫자를 만들어라
# 단 짝수가 없어서 짝수를 못만들면 -1

# Time limit: 0.5sec

# ex) 2431 라면
# 1432 vs 2134 이면 당연히 후자가 더 크겠지
# ex) 2439 라면
# 9432 vs 2934 이면 당연히 전자가 더 크지
# 즉 교환하려는 홀수가 타겟보다 크다면 최대한 앞자리에 있는게 유리하고(숫자가 커짐)
# 교환하려는 홀수가 타겟보다 작다면 최대한 뒷자리에서 바꾸는게 유리하다
even_indexes = []
ar = []
gets.chomp.split(//).each_with_index { |i, index|
    i = i.to_i
    if i.even?
        even_indexes << index
    end
    ar << i
}

if even_indexes.empty?
    puts "-1"
else
    exchanged = false
    for i in even_indexes
        if ar[i] < ar[-1]
            ar[i], ar[-1] = ar[-1], ar[i]
            exchanged = true
            break
        end
    end

    if !exchanged
        last_even_index = even_indexes.last
        ar[last_even_index], ar[-1] = ar[-1], ar[last_even_index]
    end

    puts ar.join('')
end

n = gets.chomp
l = n.size

( l - 1 ).times do | i |
	d = n[i].to_i
	if d.odd?
		next
	end

	if d < n[ l - 1 ].to_i
		s = String.new( n )
		s[i], s[ l - 1 ] = s[ l - 1 ], s[i]
		puts s
		exit
	end
end

( l - 2 ).downto( 0 ) do | i |
	d = n[i].to_i
	if d.odd?
		next
	end

	s = String.new( n )
	s[i], s[ l - 1 ] = s[ l - 1 ], s[i]
	puts s
	exit
end

puts -1

n = gets
l = n.size

p l

( l - 1 ).times do | i |
	d = n[i].to_i
	if d.odd?
		next
	end

	if d < n[ l - 1 ].to_i
		s = String.new( n )
		s[i], s[ l - 1 ] = s[ l - 1 ], s[i]
		puts s
		exit
	end
end

( l - 2 ).downto( 0 ) do | i |
	d = n[i].to_i
	if d.odd?
		next
	end

	s = String.new( n )
	s[i], s[ l - 1 ] = s[ l - 1 ], s[i]
	puts s
	exit
end

puts -1

n = gets
l = n.size

( l - 1 ).times do | i |
	d = n[i].to_i
	if d.odd?
		next
	end

	if d < n[ l - 1 ].to_i
		s = String.new( n )
		s[i], s[ l - 1 ] = s[ l - 1 ], s[i]
		puts s
		exit
	end
end

( l - 2 ).downto( 0 ) do | i |
	d = n[i].to_i
	if d.odd?
		next
	end

	s = String.new( n )
	s[i], s[ l - 1 ] = s[ l - 1 ], s[i]
	puts s
	exit
end

puts -1

n = gets
l = n.size

l.times do | i |
	d = n[i].to_i
	if d.odd?
		next
	end

	if d < n[ l - 1 ].to_i
		s = String.new( n )
		s[i], s[ l - 1 ] = s[ l - 1 ], s[i]
		puts s
		exit 0
	end
end

( l - 2 ).downto( 0 ) do | i |
	d = n[i].to_i
	if d.odd?
		next
	end

	s = String.new( n )
	s[i], s[ l - 1 ] = s[ l - 1 ], s[i]
	puts s
	exit 0
end

puts -1

n = gets
l = n.size

l.times do | i |
	d = n[i].to_i
	if d.odd?
		next
	end

	if d < n[ l - 1 ].to_i
		s = String.new( n )
		s[i], s[ l - 1 ] = s[ l - 1 ], s[i]
		print s
		exit 0
	end
end

( l - 2 ).downto( 0 ) do | i |
	d = n[i].to_i
	if d.odd?
		next
	end

	s = String.new( n )
	s[i], s[ l - 1 ] = s[ l - 1 ], s[i]
	print s
	exit 0
end

print -1

n = gets
l = n.size

res = -1

l.times do | i |
	s = String.new( n )
	s[i], s[ l - 1 ] = s[ l - 1 ], s[i]

	if s.to_i.even?
		res = [ res, s.to_i ].max
	end
end

puts res

n = gets
l = n.size

res = -1
l.times do | i |
	s = String.new( n )
	s[i], s[ l - 1 ] = s[ l - 1 ], s[i]

	m = s.to_i
	if m.even?
		res = [ res, m ].max
	end
end
puts res

n = gets.strip
numbers = n.split("").map {|i| i.to_i}
even = numbers.select {|n| n.even?}
max = 0
last_index = numbers.size - 1
even.each do |number|
	even_index = numbers.index(number)
	temp = numbers[even_index]
	numbers[even_index] = numbers[last_index]
	numbers[last_index] = temp
	current = numbers.join("").to_i
	if (current > max)
		max = current
	end
	temp = numbers[even_index]
	numbers[even_index] = temp
	numbers[last_index] = temp
end
if even.size == 0
	puts -1
else
	puts max
end

n = gets.strip
numbers = n.split("").map {|i| i.to_i}
numbers2 = numbers.map do |e| e end
even = numbers.select {|n| n.even?}
max = 0
i = -1
j = -1
last_index = numbers.size - 1

numbers.each_with_index do |number, index|
	if (number.even? && number < numbers[last_index])
		i = index
		break
	end
end

numbers.reverse.each_with_index do |number, index|
	if (number.even? && number >= numbers[last_index])
		j = numbers.size - index - 1
		break
	end
end
puts j
if even.size == 0
	puts -1
elsif (i != -1)
	temp = numbers[last_index]
	numbers[last_index] = numbers[i]
	numbers[i] = temp
	puts numbers.join("").to_i
elsif (j != -1)
	temp = numbers[last_index]
	numbers[last_index] = numbers[j]
	numbers[j] = temp
	puts numbers.join("").to_i
end

a=gets.chomp
t=-1
mi=-10
(a.length-2).downto(0) do |i|
if a[i].to_i%2==0 && a[a.length-1].to_i-a[i].to_i>=mi
t=i
mi=a[a.length-1].to_i-a[i].to_i
end
end

if t==-1
puts "-1"
else
mi=a[a.length-1]
a[a.length-1]=a[t]
a[t]=mi
puts a
end

a=gets.chomp
t=-1
mi=-10
(a.length-2).downto(0) do |i|
if a[i].to_i%2==0 && a[a.length-1].to_i-a[i].to_i>mi
t=i
mi=a[a.length-1].to_i-a[i].to_i
end
end

if t==-1
puts "-1"
else
mi=a[a.length-1]
a[a.length-1]=a[t]
a[t]=mi
puts a
end

def check(s)
	unless s=~/[02468]/
		return "-1"
	end
	i=0
	flag=false
	hold=s[-1].to_i
	while true && i<=8
		if i<hold
			m=s=~/#{i}/
		else
			m=s.reverse=~/#{i}/
			flag=true
		end
		if $~
			if flag
				y=s[m]+s[1...m]+s[0]+s[m+1..-1]
				return y.reverse
			else
				y=s[0...m]+s[-1]+s[m+1...-1]+s[m]
				return y
			end
		end
		$~=nil
		i+=2
	end
end
s=gets.chomp.to_s
hold=check(s)
if hold!='-1'
	puts hold
else
	puts "-1"
end

def check(s)
	unless s=~/[02468]/
		puts "-1"
	end
	i=0
	flag=false
	hold=s[-1].to_i
	max=-1
	found=false
	while true && i<=8
		if i<hold
			m=s=~/#{i}/
		else
			m=s.reverse=~/#{i}/
			flag=true
		end
		if $~
			if flag
				if found
					break
				end
				m=s.size-m+1
				if m>max
					max=m
				end
			else
				found=true
				if max==-1 || max>m
					max=m
				end
			end
		end
		$~=nil
		i+=2
	end
	puts s[0...max]+s[-1]+s[max+1...-1]+s[max]
end
s=gets.chomp.to_s
check(s)

def check(s)
	unless s=~/[02468]/
		return "-1"
	end
	i=0
	flag=false
	hold=s[-1].to_i
	while true && i<=8
		if i<hold
			m=s=~/#{i}/
		else
			m=s.reverse=~/#{i}/
			flag=true
		end
		if $~
			if flag
				s=s.reverse
				y=s[m]+s[1...m]+s[0]+s[m+1..-1]
				return y.reverse
			else
				y=s[0...m]+s[-1]+s[m+1...-1]+s[m]
				return y
			end
		end
		$~=nil
		i+=2
	end
end
s=gets.chomp.to_s
hold=check(s)
if hold!='-1'
	puts hold
else
	puts "-1"
end

def check(s)
	unless s=~/[02468]/
		puts "-1"
	end
	i=0
	flag=false
	hold=s[-1].to_i
	max=-1
	found=false
	while true && i<=8
		if i<hold
			m=s=~/#{i}/
		else
			m=s.reverse=~/#{i}/
			flag=true
		end
		if $~
			if flag
				if found
					break
				end
				m=s.size-m-1
				if m>max
					max=m
				end
			else
				found=true
				if max==-1 || max>m
					max=m
				end
			end
		end
		$~=nil
		i+=2
	end
	#puts max
	puts s[0...max]+s[-1]+s[max+1...-1]+s[max]
end
s=gets.chomp.to_s
check(s)

def check(s)
	unless s=~/[02468]/
		return "-1"
	end
	i=0
	s=s.reverse
	while true && i<=8
		m=s=~/#{i}/
		if $~
			y=s[m]+s[1...m]+s[0]+s[m+1..-1]
			return y.reverse
		end
		$~=nil
		i+=2
	end
end
s=gets.chomp.to_s
hold=check(s)
if hold!='-1'
	puts hold
else
	puts "-1"
end

copy = gets.chomp
ans = -1
last = copy[-1].to_i
if copy.length < 20
# (0..(copy.length - 1)) do |i|
# 	v = copy[i].to_i
# 	if v.even? && v < last
# 		copy[i],copy[-1] = copy[-1],copy[i]
# 		ans = copy.to_i
# 		break
# 	end
# end
# if ans == -1
# 	((copy.length - 1).downto(0)).each do |i|
# 		v = copy[i].to_i
# 		if v.even? && v > last
# 			copy[i],copy[-1] = copy[-1],copy[i]
# 			ans = copy.to_i
# 			break
# 		end
# 	end
# end
# even_nos = copy.each_char.with_index.map{|k,i| [k.to_i,i] if k.to_i.even?}.compact
copy.each_char.with_index do |e,i|
	v = e.to_i
	next if v.to_i.odd?

	if v < last
		ans = i
		break
	else
		ans = i
	end
end
if ans != -1
	copy[ans],copy[-1] = copy[-1],copy[ans]
	ans = copy.to_i
end
puts ans
else
	puts copy[-1]
end

copy = gets.chomp
ans = -1
last = copy[-1].to_i
if copy.length < 20
# (0..(copy.length - 1)) do |i|
# 	v = copy[i].to_i
# 	if v.even? && v < last
# 		copy[i],copy[-1] = copy[-1],copy[i]
# 		ans = copy.to_i
# 		break
# 	end
# end
# if ans == -1
# 	((copy.length - 1).downto(0)).each do |i|
# 		v = copy[i].to_i
# 		if v.even? && v > last
# 			copy[i],copy[-1] = copy[-1],copy[i]
# 			ans = copy.to_i
# 			break
# 		end
# 	end
# end
# even_nos = copy.each_char.with_index.map{|k,i| [k.to_i,i] if k.to_i.even?}.compact
copy.each_char.with_index do |e,i|
	v = e.to_i
	next if v.to_i.odd?

	if v < last
		ans = i
		break
	else
		ans = i
	end
end
if ans != -1
	copy[ans],copy[-1] = copy[-1],copy[ans]
	ans = copy.to_i
end
puts ans
else
	copy.each_char.with_index do |e,i|
	v = e.to_i
	next if v.to_i.odd?

	if v < last
		ans = i
		break
	else
		ans = i
	end
	end
	puts copy[-1]
end

copy = gets.chomp
ans = -1
last = copy[-1].to_i
if copy.length < 20
# (0..(copy.length - 1)) do |i|
# 	v = copy[i].to_i
# 	if v.even? && v < last
# 		copy[i],copy[-1] = copy[-1],copy[i]
# 		ans = copy.to_i
# 		break
# 	end
# end
# if ans == -1
# 	((copy.length - 1).downto(0)).each do |i|
# 		v = copy[i].to_i
# 		if v.even? && v > last
# 			copy[i],copy[-1] = copy[-1],copy[i]
# 			ans = copy.to_i
# 			break
# 		end
# 	end
# end
# even_nos = copy.each_char.with_index.map{|k,i| [k.to_i,i] if k.to_i.even?}.compact
copy.each_char.with_index do |e,i|
	v = e.to_i
	next if v.to_i.odd?

	if v < last
		ans = i
		break
	else
		ans = i
	end
end
if ans != -1
	copy[ans],copy[-1] = copy[-1],copy[ans]
	ans = copy.to_i
end
puts ans
else
	copy.each_char.with_index
	puts copy[-1]
end

n = gets.to_i
ans = -1
copy = n.to_s
last = copy[-1].to_i
# (0..(copy.length - 1)) do |i|
# 	v = copy[i].to_i
# 	if v.even? && v < last
# 		copy[i],copy[-1] = copy[-1],copy[i]
# 		ans = copy.to_i
# 		break
# 	end
# end
# if ans == -1
# 	((copy.length - 1).downto(0)).each do |i|
# 		v = copy[i].to_i
# 		if v.even? && v > last
# 			copy[i],copy[-1] = copy[-1],copy[i]
# 			ans = copy.to_i
# 			break
# 		end
# 	end
# end
even_nos = copy.each_char.with_index.map{|k,i| [k.to_i,i] if k.to_i.even?}.compact
even_nos.each do |e|
	if e[0] < last
		copy[e[1]],copy[-1] = copy[-1],copy[e[1]]
		ans = copy.to_i
		break
	end
end

even_nos.reverse_each do |e|
	if e[0] > last
		copy[e[1]],copy[-1] = copy[-1],copy[e[1]]
		ans = copy.to_i
		break
	end
end

puts ans

copy = gets.chomp
ans = -1
last = copy[-1].to_i
if copy.length < 20
# (0..(copy.length - 1)) do |i|
# 	v = copy[i].to_i
# 	if v.even? && v < last
# 		copy[i],copy[-1] = copy[-1],copy[i]
# 		ans = copy.to_i
# 		break
# 	end
# end
# if ans == -1
# 	((copy.length - 1).downto(0)).each do |i|
# 		v = copy[i].to_i
# 		if v.even? && v > last
# 			copy[i],copy[-1] = copy[-1],copy[i]
# 			ans = copy.to_i
# 			break
# 		end
# 	end
# end
# even_nos = copy.each_char.with_index.map{|k,i| [k.to_i,i] if k.to_i.even?}.compact
copy.each_char.with_index do |e,i|
	v = e.to_i
	next if v.to_i.odd?

	if v < last
		ans = i
		break
	else
		ans = i
	end
end
if ans != -1
	copy[ans],copy[-1] = copy[-1],copy[ans]
	ans = copy.to_i
end
puts ans
else
	copy.each_char.with_index do |e,i|
	v = e.to_i
	next if v.to_i.odd?

	if v < last
		ans = i
		break
	else
		ans = i
	end
	end
	#
	puts copy[-1]
end

n = gets.chomp
if n.each_char.all?{|x| x.to_i.odd?}
  puts -1
else
  i = n.index(n.each_char.find{|x| x.to_i.even?})
  n[i], n[-1] = n[-1], n[i]
  puts n
end

n = gets.chomp
if n.each_char.all?{|x| x.to_i.odd?}
  puts -1
else
  m = []
  n.each_char{|x| m << x if x.to_i.even?}
  i = if m[0] < n[-1]
        n.index(m[0])
      else
        n.rindex(m.min)
      end
  n[i], n[-1] = n[-1], n[i]
  puts n
end

n = gets.chomp
if n.each_char.all?{|x| x.to_i.odd?}
  puts -1
else
  m = []
  n.each_char{|x| m << x if x.to_i.even?}
  i = if m.min > n[-1]
        n.rindex(m.min)
      else
        n.index(m.min)
      end
  n[i], n[-1] = n[-1], n[i]
  puts n
end

n = gets.chomp
if n.each_char.all?{|x| x.to_i.odd?}
  puts -1
else
  m = []
  n.each_char{|x| m << x if x.to_i.even?}
  i = n.rindex(m.min)
  n[i], n[-1] = n[-1], n[i]
  puts n
end

n = gets.chomp
if n.each_char.all?{|x| x.to_i.odd?}
  puts -1
else
  m = []
  n.each_char{|x| m << x if x.to_i.even?}
  i = if m.all?{|x| x < n[-1]}
        n.index(m.find{|x| x < n[-1]})
      else
        n.index(m.min)
      end
  n[i], n[-1] = n[-1], n[i]
  puts n
end

n = gets.chomp
if n.each_char.all?{|x| x.to_i.odd?}
  puts -1
else
  m = []
  n.each_char{|x| m << x if x.to_i.even?}
  i = if m.all?{|x| x < n[-1]}
        n.index(m.find{|x| x < n[-1]})
      else
        n.rindex(m.min)
      end
  n[i], n[-1] = n[-1], n[i]
  puts n
end

a=Array.new
str=gets.to_s
a=str.split("")
h=0
for i in 0..a.length-1
  if a[i].to_i>0 and a[i].to_i%2==0
#   a[-1] 字符串最后一般是换行符，可用chomp方法去除
#    puts a[-2]
    t=a[-2]
    a[-2]=a[i]
    a[i]=t
    h=1
    break
  end
end
if h==1
  for i in 0..a.length-1
    print a[i].chomp
  end
  puts
elsif h==0
  puts -1
end


gets.to_i.times do
  n = gets.to_i
  s = gets.chomp
  t = gets.chomp

  if s.count('b') != t.count('b')
    puts 'NO'
    next
  end

  j = 0
  ok = true
  n.times do |i|
    next if s[i] == 'b'

    while t[j] == 'b'
      j += 1
    end

    if s[i] != t[j] || (s[i] == 'a' && i > j) || (s[i] == 'c' && i < j)
      ok = false
      break
    end
    j += 1

  end
  puts ok ? 'YES' : 'NO'
end

gets.to_i.times do
  n = gets.to_i
  s = gets.chomp.chars.to_a
  t = gets.chomp.chars.to_a
  si, ti = s.zip(0..), t.zip(0..)
  sa = si.filter_map { |c, i| i if c == "a" }
  sc = si.filter_map { |c, i| i if c == "c" }
  ta = ti.filter_map { |c, i| i if c == "a" }
  tc = ti.filter_map { |c, i| i if c == "c" }
  ok = s.select { |c| c != "b" } == t.select { |c| c != "b" } &&
       sa.zip(ta).all? { |x, y| x <= y } &&
       sc.zip(tc).all? { |x, y| x >= y }
  puts ok ? "YES" : "NO"
end

gets.to_i.times do
  n = gets.to_i
  s = gets.chomp.chars.to_a
  t = gets.chomp.chars.to_a
  si, ti = s.zip(0..), t.zip(0..)
  sa = si.filter_map { |c, i| i if c == "a" }
  sc = si.filter_map { |c, i| i if c == "c" }
  ta = ti.filter_map { |c, i| i if c == "a" }
  tc = ti.filter_map { |c, i| i if c == "c" }
  ok = s.select { |c| c != "b" } == t.select { |c| c != "b" } && (sa <=> ta) <= 0 && (sc <=> tc) >= 0
  puts ok ? "YES" : "NO"
end

gets.to_i.times do
  n = gets.to_i
  s = gets.chomp.chars.to_a
  t = gets.chomp.chars.to_a
  si, ti = s.zip(0..), t.zip(0..)
  sa = si.filter_map { |c, i| i if c == "a" }
  sb = si.filter_map { |c, i| i if c == "b" }
  sc = si.filter_map { |c, i| i if c == "c" }
  ta = ti.filter_map { |c, i| i if c == "a" }
  tb = ti.filter_map { |c, i| i if c == "b" }
  tc = ti.filter_map { |c, i| i if c == "c" }
  ok = sa.count == ta.count && sb.count == tb.count && sc.count == tc.count && (sa <=> ta) <= 0 && (sc <=> tc) >= 0
  puts ok ? "YES" : "NO"
end


#!/usr/bin/env ruby

class Main
  attr_reader :computer_count, :student_count, :array

  def initialize(computer_count, student_count, array)
    @computer_count = computer_count
    @student_count = student_count
    @array = array.sort.reverse
  end

  def run
    array[student_count - 1]
  end
end

computer_count, student_count = gets.split(" ")
array = gets.split(" ")
puts Main.new(computer_count.to_i, student_count.to_i, array.map(&:to_i)).run

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

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

puts a[k-1]

n, m = gets.split
a = gets.split.map{|i|i.to_i}.sort
print a[-m.to_i]

# https://codeforces.com/problemset/problem/412/B

input = gets.split(' ').map(&:to_i)
transfer_speed_table = gets.split(' ').map(&:to_i)

k = input[1]

transfer_speed_table.sort! { |a, b| b <=> a }

puts transfer_speed_table[k-1]

nk = gets.split(' ')
n = nk[0].to_i
k = nk[1].to_i
ai = gets.split(' ').map!{ |el| el.to_i }
ai = ai.sort.reverse
puts ai[k-1]


n = gets.to_i
ab = n.pred.times.map {gets.split.map(&:to_i).map(&:pred)}
cnt = Array.new(n, 0)
ab.each do |a, b|
	cnt[a] += 1
	cnt[b] += 1
end

pos = cnt.index {|c| c >= 3}
ans = Array.new(n.pred, -1)
if pos
	x = 0
	n.pred.times do |i|
		if ab[i].index(pos) && x < 3
			ans[i] = x
			x += 1
		end
	end
	n.pred.times do |i|
		if ans[i] == -1
			ans[i] = x;
			x += 1
		end
	end
else
	ans = (0...n.pred).to_a
end
puts ans.join("\n")

n = gets.to_i
ab = n.pred.times.map {gets.split.map(&:to_i).map(&:pred)}
cnt = Array.new(n, 0)
ab.each{|a| a.each{|i| cnt[i] += 1}}
ans = Array.new(n.pred, -1)
if (pos = cnt.index{|c| c >= 3})
	(0...n.pred).to_a.select{|i| ab[i].index(pos)}.take(3).each_with_index{|i, x| ans[i] = x}
	(0...n.pred).to_a.select{|i| ans[i] == -1}.each_with_index{|i, x| ans[i] = x + 3}
else
	ans = (0...n.pred).to_a
end
puts ans.join("\n")


gets.to_i.times{
    n=gets.to_i
    a=gets.split.map(&:to_i).sort
    p (0...n-1).count{|i|a[i]+1==a[i+1]}>0 ? 2 : 1
}

gets.to_i.times do
  n = gets.to_i
  as = gets.split.map(&:to_i).sort
  flg = false
  (0..n-2).each do |i|
    flg = true if (as[i] - as[i+1]).abs == 1
  end
  puts flg ? 2 : 1
end

def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end

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

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

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

def kaizyo(n)(n < 2)? 1 : (2..n).inject(:*) end

def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end

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

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

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

def bit(n) n.to_s(2).split("").map(&:to_i) end

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

n = inp[0]
n.times do
  q = inp[0]
  st = inp
  mae = -9
  ans = 1
  st.sort!
  st.each do |d|
    if(d - mae == 1)
      ans = 2
      break
    end
    mae = d
  end
  puts ans

end

q = gets.to_i
q.times do
  n = gets.to_i
  a = gets.split.map(&:to_i).sort
  nteams, nused, used = 0, 0, []
  while nused < n
    i = 0
    t = nil
    while i < n
      if not used[i] and (not t or (a[i] - t).abs > 1)
        t = a[i]
        nused += 1
        used[i] = true
      end
      i += 1
    end
    nteams += 1
  end
  puts nteams
end

n = readline.to_i
n.times do |i|
  m = readline.to_i
  a = readline.to_s.split
  ni = []
  a.each {|ite|
    ni.push(ite.to_i)
  }
  ni = ni.sort
  last = ni[0]
  ch = 0
  ni.each { |ite |
    if (ite - last).abs == 1
      ch = 1
      break
    end
    last = ite
  }
  if ch == 1
    puts 2
  else
    puts 1
  end
end

q = gets.to_i
q.times do
  n = gets.to_i
  a = gets.split.map &:to_i
  nteams, nused, used = 0, 0, []
  while nused < n
    i = 0
    t = nil
    while i < n
      if not used[i] and (not t or (a[i] - t).abs > 1)
        t = t || a[i]
        nused += 1
        used[i] = true
      end
      i += 1
    end
    nteams += 1
  end
  puts nteams
end


t = gets.chomp.to_i
t.times do
  n = gets.chomp.to_i
  a = ""
  b = ""
  diff = false
  x = gets.chomp
  for i in 0..n-1
    if x[i] == "2"
      if diff
        a << "0"
        b << "2"
      else
        a << "1"
        b << "1"
      end
    elsif x[i] == "1"
      if diff
        a << "0"
        b << "1"
      else
        a << "1"
        b << "0"
        diff = true
      end
    else
      a << "0"
      b << "0"
    end
  end
  puts a
  puts b
end

gets.to_i.times do
	n = gets.to_i
	s = gets.split('').map(&:to_i)
	a = Array.new(0, n)
	b = Array.new(0, n)

	flag = false
	n.times do |i|
		if flag
			a[i] = 0
			b[i] = s[i]
		else
			a[i] = (s[i] + 1) / 2
			b[i] = s[i] / 2
			flag = true if a[i] != b[i]
		end
	end
	puts a.join('')
	puts b.join('')
end

# coding: utf-8

# if __FILE__ == $0
# end

t = gets.to_i
t.times {
    len = gets.to_i
    tnr = gets.chomp
    a = []
    b = []
    a_equals_b = true
    for i in 0...len
        case tnr[i]
        when '2' # how to split 2? (2, 0), (1, 1), (0, 2)
            if a_equals_b == true
                a << 1
                b << 1
            else
                a << 0
                b << 2
            end
        when '1' # where to increase one?
            if a_equals_b == true
                a << 1
                b << 0
                a_equals_b = false
            else
                a << 0
                b << 1
            end
        when '0' # nothing to do
            a << 0
            b << 0
        else
            raise Exception.new("should not reach here")
        end
    end

    puts a.join('')
    puts b.join('')
}

t = gets.to_i
t.times do
  n = gets.to_i
  x = gets.chomp
  a = []
  b = []
  diff = false
  x.each_char do |c|
    case c
    when "0"
      a.push("0")
      b.push("0")
    when "1"
      if diff
        a.push("0")
        b.push("1")
      else
        a.push("1")
        b.push("0")
        diff = true
      end
    when "2"
      if diff
        a.push("0")
        b.push("2")
      else
        a.push("1")
        b.push("1")
      end
    end
  end
  puts a.join
  puts b.join
end

1.upto(gets.to_i) do
  n = gets.to_i
  s = gets.chomp

  pos = s.index('1')
  beg = s[0, pos ? pos : s.size ].chars.map { |c| c == '2' ? '1' : '0' }.join

  if pos
    puts beg + '1' + '0' * (n - pos - 1)
    puts beg + '0' + s[pos+1, n - pos - 1]
  else
    puts beg
    puts beg
  end

  next

  odd = false
  result = ['', '']
  gets.chomp.chars.each_with_index do |char, idx|
    if odd
      result[1] += char
      next
    end

    case char
    when '2'
      result.map! { |s| s + '1' }
    when '1'
      result[0] += '1' + '0' * (n - idx - 1)
      result[1] += '0'
      odd = true
    when '0'
      result.map! { |s| s + '0' }
    end
  end

  result.each { |s| puts s }
end

t = gets.to_i
(1..t).each do
  n = gets.to_i
  s = gets.split('')
  b = false
  s.each do |c|
    if c=="\n"
      break
    end
    if b
      print '0'
    else
      print c.to_i/2+c.to_i.modulo(2)
    end
    if c=='1'
      b=true
    end
  end
  print "\n"
  b=false
  s.each do |c|
    if c=="\n"
      break
    end
    if b
      print c
    else
      print c.to_i/2
    end
    if c=='1'
      b=true
    end
  end
  print "\n"
end

t = gets.chomp.to_i
t.times do
  n = gets.chomp.to_i
  a = ""
  b = ""

  x = gets.chomp.split('')
  x.each do |i|
    if i == "2"
      a << "1"
      b << "1"
    elsif i == "1"
      a << "1"
      b << "0"
    else
      a << "0"
      b << "0"
    end
  end
  puts a
  puts b
end

1.upto(gets.to_i) do
  n = gets.to_i

  odd = false
  result = ['', '']
  gets.chomp.chars.each_with_index do |char, idx|
    if odd
      result[1] += char
      next
    end

    case char
    when '2'
      result.map! { |s| s + '1' }
    when '1'
      result[0] += '1' + '0' * (n - idx)
      result[1] += '0'
      odd = true
    when '0'
      result.map! { |s| s + '0' }
    end
  end

  result.each { |s| puts s }
end


n = gets.to_i
arr = []
n.times do
	x, w = gets.split.map(&:to_i)
	arr << [x - w, x + w]
end

arr.sort! do |a, b|
	a[1] <=> b[1]
end

ans = 0
now = -10**9
arr.each do |ele|
	if ele[0] >= now
		ans += 1
		now = ele[1]
	end
end

puts ans

n = gets.strip.to_i
xws = readlines.map {|line| line.strip.split.map(&:to_i) }

xws = xws.map {|x,w| [x-w, x+w] }.sort_by(&:last)

result=0
target=0
index=target
until index==n
  index=target+1
  ct = xws[target].last
  index+=1 while xws[index] && xws[index].first < ct
  target = index

  result+=1
end

p result


#Infinity
#geti,getia
#Object # dcopy
#
#String # to_a
#   "abc".to_a #=> ["a","b","c"]
#String # to_ia
#   "1 2 3".to_ia #=> [1,2,3]
#
#Array # rsort,rsort!
#   [1,3,2,4].rsort #=> [4,3,2,1]
#
#Integer # divisor
#   24.divisor #=> [1,2,3,4,6,8,12,24]
#
include Math
require "prime"
require "bigdecimal"
require "bigdecimal/math"
require "matrix"
require "pp"
require "benchmark"

Infinity = 1/0.0
class Matrix;def inspect;empty? ? "Matrix.empty(#{row_size}, #{column_size})":"Matrix[\n#{@rows.map(&:inspect).join("\n")}\n]";end;end
def pbin(obj);case obj;when Integer;puts obj.to_s(2);end;end
class String;def to_a;split("");end;end
class String;def to_ia;split.map(&:to_i);end;end
def getia;gets.to_ia;end
def geti;gets.to_i;end
class Object;def dcopy;Marshal.load(Marshal.dump(self));end;end
class Array;def rsort;sort.reverse;end;def rsort!;sort!.reverse!;end;end

def dfs(a,b,x,y,n)
    mask = ((1<<n)-1)
    return false if ((x+y)&mask) != a&mask || (x^y)&mask != b&mask
    return [x,y] if x+y == a && x^y == b
    return false if x+y > a
    for p in 0..1
        for q in 0..1
            s = x | (p * (1<<n))
            t = y | (q * (1<<n))
            w = dfs(a,b,s,t,n+1)
            return w if w != false
        end
    end
    return false
end
a = geti
b = geti
res = dfs(a,b,0,0,0)
if res == false
    puts -1
else
    puts "#{res[0]} #{res[1]}"
end

a = gets.to_i
b = gets.to_i

x = (a - b)/2

if a - b >= 0 and (a - b) % 2 == 0
  puts x.to_s + " " + (x + b).to_s + "\n"
else
  puts "-1\n"
end


T = gets.to_i
T.times do
  n = gets.to_i
  t = 1
  ans = 0
  9.times do
    l = []
    r = []
    n.times do |i|
      if i & t > 0
        l << i+1
      else
        r << i+1
      end
    end
    if l.length>0 && r.length>0
      puts "#{l.length} #{r.length} #{l.join(" ")} #{r.join(" ")}"
      STDOUT.flush
      x = gets.to_i
      ans = x if x > ans
    end
    t *= 2
  end
  puts "-1 #{ans}"
  STDOUT.flush
end

def say(s)
  puts s
  STDOUT.flush
end

readline.to_i.times do
  n = readline.to_i
  r = 0
  bit = 1
  while bit < n do
    a, b = (1..n).partition { |i| i & bit > 0 }
    say "#{a.length} #{b.length} #{a.join " "} #{b.join " "}"
    r1 = readline.to_i
    if r1 > r then r = r1 end
    if r1 < 0 then exit end
    bit <<= 1
  end
  say "-1 #{r}"
end


n = gets.to_i

hash = Hash.new([])
(1..n).each do |x|
  hash[x] += gets.chomp.split(" ").map(&:to_i)
end

arr = []

thefirstpair = hash[1]
if hash[thefirstpair[0]].include?(thefirstpair[1])
  nextone = thefirstpair[0]
  otherone = thefirstpair[1]
else
  nextone = thefirstpair[1]
  otherone = thefirstpair[0]
end

arr.push 1

while nextone != 1
  arr.push nextone
  asdf = nextone
  nextone = otherone
  otherone = (hash[asdf] - [nextone])[0]
end

arr.each do |x|
  print x
  print " "
end

puts

# Utility
class Child
  attr_reader :memorised
  attr_reader :index

  def to_s
    @index.to_s
  end

  def log
    "Index: #{@index}. Memory: #{@memorised}"
  end

  def to_i
    @index
  end

  def remembers?(e)
    @memorised.any? { |o| o == e.to_i }
  end

  def initialize(index, *other)
    @index = index
    case other.length
    when 2
      @memorised = [other[0], other[1]]
    when 1
      @memorised = other[0].split.map { |s| s.to_i }
    end
  end
end

# Input
n = gets.to_i
children = []
n.times { |i| children.push Child.new(i + 1, gets) }

if n == 3
  # Special case
  puts "1 2 3"
  exit 0
end

# Processing
roundelay = Array.new(n)
roundelay[0] = children[0]
1.upto(n - 1) do |i|
  mem = roundelay[i - 1].memorised
  c_1 = children[mem[0] - 1]
  c_2 = children[mem[1] - 1]

  #puts roundelay[i - 1].log
  #puts c_1.log
  #puts c_2.log
  #puts

  roundelay[i] = c_1.remembers?(c_2) ? c_1 : c_2
end

# Output
puts roundelay.join(" ")

# Utility
class Child
  attr_reader :memorised
  attr_reader :index

  def to_s
    @index.to_s
  end

  def to_i
    @index
  end

  def remembers?(e)
    @memorised.find_index(e.to_i) != nil
  end

  def initialize(index, *other)
    @index = index
    case other.length
    when 2
      @memorised = [other[0], other[1]]
    when 1
      @memorised = other[0].split.map { |s| s.to_i }
    end
  end
end

# Input
n = gets.to_i
children = []
n.times { |i| children.push Child.new(i + 1, gets) }

# Processing
#p children
roundelay = Array.new(n)
roundelay[0] = children[0]
1.upto(n - 1) do |i|
  mem = roundelay[i - 1].memorised
  #p mem
  roundelay[i] = children[mem[0] - 1].remembers?(mem[1]) ? children[mem[0] - 1] : children[mem[1] - 1]
  #puts roundelay[i]
end

# Output
puts roundelay.join(" ")


t = gets.chomp.to_i
t.times do
  n, k = gets.chomp.split(' ').map(&:to_i)
  arr = gets.chomp.split(' ').map(&:to_i)
  arr << 0
  arr << 1000
  pik = 0
  prev_pik = 0
  sum = 0

  while arr[pik] >= arr[pik + 1]
    pik += 1
  end
  # puts "PIK = #{pik}"
  while (pik != n && sum < k)
    prev_pik = pik
    sum += [arr[pik + 1], arr[pik - 1] + 1].min - arr[pik]
    arr[pik] = [arr[pik + 1], arr[pik - 1] + 1].min
    pik = 0
    while arr[pik] >= arr[pik + 1]
      pik += 1
    end

    # puts "Arr = #{arr.to_s}"
  end

  # puts "SUM = #{sum}"
  # puts "PIK = #{pik}"
  # puts "Arr = #{arr.to_s}"
  if sum < k
    puts -1
  else
    puts prev_pik + 1
  end
end

#     int t,n,k;
#     cin>>t;
#     while(t--)
#     {
#         cin>>n>>k;
#         int a[n];
#         for(int i=0;i<n;i++)
#         cin>>a[i];
#         int j=0,c=0;
#         int p[100000]={0};
#         while(true)
#         {int f=0;
#             for(int i=0;i<n-1;i++)
#             {
#                 if(a[i]<a[i+1])
#                 {f=1;
#                     a[i]=a[i]+1;
#                     c++;
#                     p[c]=i+1;

#                     break;
#                 }
#             }
#             if(f==0)
#             break;
#         }
#         if(k>c)
#         cout<<-1<<"\n";
#         else
#         cout<<p[k]<<"\n";
#     }
# }

t = gets.chomp.to_i;
while t>0 do
    b=Array.new(2)
    b=gets.chomp.split().map { |e| e.to_i  }
    n = b[0];
    k =b[1];

    a=Array.new(n+1);
    i=0;
    p=Array.new(100000);
    a=gets.chomp.split().map { |e| e.to_i  }

    c=0
    h=0
    while h==0 do
        f=0
        j=0
        while j<n-1 do
            if a[j]<a[j+1]
                f=1
                a[j]=a[j]+1
                c=c+1
                p[c]=j+1
                break
            end
            j=j+1
        end
        if f==0
           h=1
        end
    end
    if k>c
        puts -1;
    else
        puts p[k];
    end
    t=t-1
end

def read
    gets.split.map &:to_i
end
gets.to_i.times do
    n, k = read
    a = read
    if n * a.max < k
        puts -1
        next
    end
    res = n + 1
    k.times do
        to = -2
        (n - 1).times do |i|
            if a[i] < a[i + 1]
                to = i
                break
            end
        end
        res = to + 1
        break if res == -1
        a[to] += 1
    end
    puts res
end

def solve
  n, k = ints
  h = ints

  ans = -1
  k.times do
    has_valley = false
    (n-1).times do |i|
      if h[i] < h[i+1]
        ans = i + 1
        has_valley = true
        h[i] += 1
        break
      end
    end
    unless has_valley
      ans = -1
      break
    end
  end
  puts ans
end

def main
  t = int
  t.times do
    solve
  end
end

DEBUG = true
MOD = 10**9+7
YESNO = %w(NO YES)
INF = 10**9

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

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

class TrueClass
  include Boolean
  def to_i; 1 end
end

class FalseClass
  include Boolean
  def to_i; 0 end
end

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

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

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

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

main

gets.to_i.times do
  n,k=gets.split.map(&:to_i)
  h=gets.split.map(&:to_i)
  f=false
  k.times do |kk|
    f=false
    (n-1).times do |i|
      if h[i]<h[i+1]
        h[i]+=1
        f=i
        break
      end
    end
    if !f
      puts "-1"
      break
    end
  end
  if f
    puts f+1
  end
end

t = gets.chomp.to_i
t.times do
  n, k = gets.chomp.split(' ').map(&:to_i)
  arr = gets.chomp.split(' ').map(&:to_i)
  arr << 0
  arr << 1000
  pik = 0
  prev_pik = 0
  sum = 0

  while arr[pik] >= arr[pik + 1]
    pik += 1
  end
  # puts "PIK = #{pik}"
  while (pik != n && sum < k)
    prev_pik = pik
    sum += arr[pik + 1] - arr[pik]
    arr[pik] = arr[pik + 1]
    pik = 0
    while arr[pik] >= arr[pik + 1]
      pik += 1
    end

  end

  # puts "SUM = #{sum}"
  # puts "PIK = #{pik}"
  # puts "Arr = #{arr.to_s}"
  if sum < k
    puts -1
  else
    puts prev_pik + 1
  end
end


n,h,k=gets.split.map(&:to_i)
s=r=0
gets.split.each{|p|p=p.to_i
r+=p
r,s=p,s+1if r>h
s+=r/k
r%=k}
s+=1if r>0
p s

#!/usr/bin/ruby
N,H,K=gets.split.map(&:to_i)
r=h=0
gets.split.map(&:to_i).each{|x|
	if h+x<=H
		h+=x
	else
		r+=1
		h=x
	end
	r+=h/K
	h%=K
}
p r+(h+K-1)/K

n, h, k = readline.split(' ').collect(&:to_i)
arr = readline.split(' ').collect(&:to_i)
left = 0
ct = 0
arr.each do |num|
  if left + num > h
    left = num
    ct += 1
  else
    left += num
  end
  ct += (left / k)
  left %= k
end

ct += 1 if left > 0
puts ct

n, h, k = gets.split.map { |x| x.to_i }
a = gets.split.map { |x| x.to_i }
ans = 0
sum = 0
a.each do |now|
	cut = [(now - (h - sum) + k - 1) / k, 0].max
	ans += cut
	sum = [sum - cut * k, 0].max
	sum += now
end
ans += (sum + k - 1) / k
puts ans

n, h, k = gets.chomp.split.map(&:to_i)
as = gets.chomp.split.map(&:to_i)

t = 0
l = 0

for i in 0...n
  t += l / k
  l = l % k
  if h < l + as[i]
    t += 1
    l = 0
  end
  l += as[i]
end
t += (l + k - 1) / k

puts t

n, h, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
ans = 0
left = 0
i = 0
while i < n
  ans += (left + a[i]) / k
  left = (left + a[i]) % k
  if i == n - 1 && left > 0
    ans += 1
  elsif i != n - 1 && left != 0 && left + a[i + 1] > h
    ans += 1
    left = 0
  end
  i += 1
end
puts ans

totalPotatos, processorHeight, smashUnits = gets.split.map(&:to_i)
seconds = 0
remain = 0
gets.split.map(&:to_i).each { |potato|
  if remain + potato <= processorHeight
    remain += potato
  else
    seconds += 1
    remain = potato
  end
  seconds += remain / smashUnits
  remain %= smashUnits
}
seconds += 1 if remain > 0
puts seconds

$now = 0

$n, $h, $k = gets.chomp.split(' ').map { |i| i.to_i }
$potatos = gets.chomp.split(' ').map { |i| i.to_i }

def put_potato
	#puts "Before put_potato : #{$inQueue}"
	#puts "Now : #{$now}"

	until $inQueue + $potatos[$now] > $h
	#	puts "Now inQueue : #{$inQueue}"
		$inQueue += $potatos[$now]
		$now += 1

		break if $now == $potatos.length
	end

	#puts "After put_potato : #{$inQueue}"
end

time = 0
$inQueue = 0
put_potato

until $now == $potatos.length
	nn = ($inQueue / $k)
	time += nn
	time += 1 if nn == 0
	$inQueue -= (nn * $k)
	$inQueue = 0 if nn == 0
	put_potato
end

time += ($inQueue / $k)
time += 1 if ($inQueue % $k > 0)

puts time

now = 0

n, h, k = gets.chomp.split(' ').map { |i| i.to_i }
potatos = gets.chomp.split(' ').map { |i| i.to_i }

time = 0
remain = potatos[0]

i = 0

until i >= (potatos.length - 1)
	time += 1
	remain -= k
	#puts "Remain : #{remain}"
	#puts "Next potatos : #{potatos[i + 1]}"
	if remain + potatos[i + 1] <= h
		remain += potatos[i + 1]

	#puts "Insidle Remain : #{remain}"

		if remain < 0
			i += 1
			until remain >= 0
				#puts "Interpol Remain : #{remain}"
				break if i >= potatos.length
				remain += potatos[i + 1]
				i += 1
			end
		end
	else
		remain = potatos[i + 1]
		time += 1
	end

	i += 1
end

time += (remain / k)
time += 1 if remain % k > 0

puts time