def unequal_split(n, bm, ary)
  zs = 0
  os = 0
  n.times do |s|
    b = (1 << s)
    if b & bm > 0
      os += ary[s]
    else
      zs += ary[s]
    end
  end
  os != zs
end

def print_ans(n, bm)
  zc = 0
  zpos = []
  n.times do |s|
    b = (1 << s)
    if b & bm == 0
      zc += 1
      zpos << (s+1)
    end
  end
  puts zc
  puts zpos.join(" ")
end

n = gets.to_i
ary = gets.strip.split.map(&:to_i)

if n == 1
  puts -1
elsif n == 2
  if ary[0] == ary[1]
    puts -1
  else
    puts "1 1"
  end
else
  ans_found = false
  1.upto((2**n)-2).each do |bm|
    break if ans_found
    if unequal_split(n, bm, ary)
      print_ans(n, bm)
      ans_found = true
    end
  end
  puts -1 unless ans_found
end

n = gets.chomp
n = n.to_i

arr = gets.chomp
arr = arr.split " "
arr.map! {|a| a.to_i}

if (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])
  puts "-1"
else
  puts "1"
  min = arr.min
  puts arr.index(min) + 1
end

N = gets.to_i
as = gets.split.map(&:to_i)
if N == 1 || (N == 2 && as[0] == as[1])
    puts -1
else
    puts 1
    puts N.times.min_by{|i| as[i]} + 1
end

n = gets.chomp
n = n.to_i

arr = gets.chomp
arr = arr.split " "
arr.map! {|a| a.to_i}

if (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])
  puts "-1"
else
  puts "1"
  puts arr[0 + (arr.count/2)]
end

n = gets.chomp
n = n.to_i

arr = gets.chomp
arr = arr.split " "
arr.map! {|a| a.to_i}

if (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])
  puts "-1"
else
  puts "1"
  arr.sort!
  puts arr[0 + arr.count/2]
end

n = gets.chomp
n = n.to_i

arr = gets.chomp
arr = arr.split " "
arr.map! {|a| a.to_i}

if (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])
  puts "-1"
else
  puts "1"
  min = arr.min
  puts "1"
end

n = gets.chomp
n = n.to_i

arr = gets.chomp
arr = arr.split " "
arr.map! {|a| a.to_i}

if (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])
  puts "-1"
else
  puts "1"
  puts arr[0]
end

n = gets.chomp
n = n.to_i

arr = gets.chomp
arr = arr.split " "
arr.map! {|a| a.to_i}

if (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])
  puts "-1"
else
  puts "1"

  i = 0
  dup = true
  while i <= arr.count - 2
    dup = false if arr[i] != arr[i + 1]
    i = i + 1
  end

  even = (arr.count % 2 == 0)

  if dup and !even
    puts "-1"
  else
    puts arr[0]
  end
end

n = gets.chomp
n = n.to_i

arr = gets.chomp
arr = arr.split " "
arr.map! {|a| a.to_i}

if (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])
  puts "-1"
else
  puts "1"

  sum = arr.reduce 0, :+
  dup = true
  arr.each_with_index do |a, i|
    break if i >= arr.count - 2

    next if arr[i] == arr[i + 1]

    if arr[i] != arr[i+1]
      dup = false
      break
    end
  end

  if dup
      puts -1
  else
      puts arr[0]
  end
end

n = gets.chomp
n = n.to_i

arr = gets.chomp
arr = arr.split " "
arr.map! {|a| a.to_i}

if (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])
  puts "-1"
else
  puts "1"

  sum = arr.reduce 0, :+

  if arr[0] == sum - arr[0]
      puts arr[1]
  else
      puts arr[0]
  end
end

n = gets.chomp
n = n.to_i

arr = gets.chomp
arr = arr.split " "
arr.map! {|a| a.to_i}

if (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])
  puts "-1"
else
  puts "1"

  i = 0
  dup = true
  while i <= arr.count - 2
    dup = false if arr[i] != arr[i + 1]
    i = i + 1
  end

  even = (arr.count % 2 == 0)

  if dup and even
    puts "-1"
  else
    puts arr[0]
  end
end

n = gets.chomp
n = n.to_i

arr = gets.chomp
arr = arr.split " "
arr.map! {|a| a.to_i}

if (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])
  puts "-1"
else
  puts "1"

  sum = arr.reduce 0, :+

  if arr[0] == sum - arr[0]
      puts -1
  else
      puts arr[0]
  end
end

n = gets.chomp
n = n.to_i

arr = gets.chomp
arr = arr.split " "
arr.map! {|a| a.to_i}

if (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])
  puts "-1"
else
  puts "1"
  puts arr[-1]
end

n = gets.chomp
n = n.to_i

arr = gets.chomp
arr = arr.split " "
arr.map! {|a| a.to_i}

if (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])
  puts "-1"
else
  puts "1"
  arr.sort!
  puts arr[-1]
end


#!/usr/bin/env ruby

newspapper = gets.strip
letter_count = Hash.new(0)
pokemon = 'Bulbasaur'
newspapper.each_char do |char|
  letter_count[char] += 1 if pokemon.include? char
end

def compute_count(letter_count, pokemon)
  count = 0
  loop do
    pokemon.each_char do |char|
      cur_count = letter_count[char]
      return count if cur_count == 0
      letter_count[char] = cur_count - 1
    end
    count += 1
  end
end

puts compute_count(letter_count, pokemon)

a=gets.chomp

ans=0
h=Hash.new(0)
"Bulbasaur".chars{|e|
	h[e]=0
}

a.chars{|e|
	if h.key?(e) then
		h[e]+=1
	end
}
h["a"]/=2
h["u"]/=2

ans=h["B"];
h.each{|k,v|
	ans=v if ans>v
}

puts ans

s = gets.chomp
required = {'B' => 1, 'u' => 2,'l' => 1, 'b' => 1,'a' => 2,'s' => 1,'r' => 1}
count = Hash.new(0)
s.each_char do |a|
	count[a] += 1
end
val = []
required.each_key do |k|
	val << count[k] / required[k]
end
puts val.min

inp = gets.strip
str = "Bulbasaur"
puts str.chars.map { |c| inp.count(c) / str.count(c) }.min

word = gets.chomp
container = {}

"Blbsaur".each_char { |x| container[x] = 0 }

word.each_char do |x|
	if container.has_key?(x)
		container[x] += 1
	end
end

container[ "a" ] /= 2
container[ "u" ] /= 2

puts container.values.min

x,y=['Bulbasaur',gets.chomp].map{|s|
	h=Hash.new 0
	s.chars{|c|h[c]+=1}
	h
}
p x.map{|k,v|y[k]/v}.min

#!/usr/bin/env ruby
count = gets.chomp.chars.reduce(Hash.new(0)) do |count, c|
  count.tap{ |h| h[c] += 1 }
 end
puts [
  count['B'],
  count['u'] / 2,
  count['l'],
  count['b'],
  count['a'] / 2,
  count['s'],
  count['r'],
].min

s = gets.strip
exp_counts = { 'B' => 1, 'u' => 2, 'l' => 1, 'b' => 1, 'a' => 2, 's' => 1, 'r' => 1 }
counts = {}
s.each_char do |c|
    counts[c] = 0 if !counts[c]
    counts[c] += 1
end
act_counts = counts.select { |k, v| exp_counts.keys.include? k }
ans = 0
if act_counts.length == exp_counts.length
    bu_cnt = act_counts['B'] / exp_counts['B']
    u_cnt = act_counts['u'] / exp_counts['u']
    l_cnt = act_counts['l'] / exp_counts['l']
    b_cnt = act_counts['b'] / exp_counts['b']
    a_cnt = act_counts['a'] / exp_counts['a']
    s_cnt = act_counts['s'] / exp_counts['s']
    r_cnt = act_counts['r'] / exp_counts['r']
    ans = [bu_cnt, u_cnt, l_cnt, b_cnt, a_cnt, s_cnt, r_cnt].min
end
puts ans

a=gets.chomp

ans=0
h=Hash.new(0)
"Bulbasaur".chars{|e|
	h[e]=0
}

a.chars{|e|
	if h.key?(e) then
		h[e]+=1
	end
}
h["a"]/=2
ans=h["B"];
h.each{|k,v|
	ans=v if ans>v
}

puts ans


gets.to_i.times do
  n, k = gets.split.map(&:to_i)
  freq = Hash.new(0)
  gets.split.map(&:to_i).each { freq[_1] += 1 }
  freq.filter! { |_, v| v >= k }
  keys = freq.keys.sort

  best = [0, nil]
  cur = [0, nil]
  prev = nil

  keys.each do |key|
    if prev && (prev + 1) == key
      cur[0] += 1
    else
      cur[0] = 1
    end
    cur[1] = key
    prev = key
    best = cur.clone if cur[0] > best[0]
  end

  unless best[1]
    p -1
    next
  end

  puts "#{best[1] - best[0] + 1} #{best[1]}"
end

gets.to_i.times do
  n, k = gets.split.map(&:to_i)
  as = gets.split.map(&:to_i)
  xs = as.tally.filter_map { |a, count| a if count >= k }.sort
  ys = xs.chunk_while { |a, b| a + 1 == b }.max_by(&:size)
  if ys
    puts "#{ys[0]} #{ys[-1]}"
  else
    p -1
  end
end

def solve
  _, x = gli
  a = gli.tally.map { |k, v| k if v >= x }.compact.sort
  if a.empty?
    puts(-1)
    return
  end
  ans = 0
  al = a[0]
  cur = 0
  l = a[0]
  (1...a.size).each do |i|
    if a[i - 1] + 1 != a[i]
      if ans < cur
        al = l
        ans = cur
      end
      cur = 0
      l = a[i]
    else
      cur += 1
    end
  end
  if ans < cur
    al = l
    ans = cur
  end
  puts [al, al + ans].join(' ')
end

MOD = 10**9 + 7
def gs = gets.chomp
def gi = gets.to_i
def gli = gets.split.map(&:to_i)
def cyesno(x) = x ? :Yes : :No
def uyesno(x) = x ? :YES : :NO

gets.to_i.times { solve }

main = -> {
  t = int
  t.times do
      n, k = ints
      a = ints.tally
      prev = -1
      prev_l = nil
      count = 0
      ans = -1
      ans_len = -1
      a.keys.sort.each do |key|
          if a[key] >= k
              if prev == key - 1
              else
                  prev_l = key
              end
              if ans_len < key - prev_l
                ans = "#{prev_l} #{key}"
                ans_len = key - prev_l
              end
              prev = key
          end
      end
      puts ans
  end
}

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

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] end
def YesNo t; puts YesNo[t] 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 * 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[]


zeroes, ones, k = gets.split(/\s+/).map(&:to_i)
x = ('1'*ones + '0'*zeroes).to_i(2)

r = ('1'*k + '0'*[zeroes-k,0].max).to_i(2)
y = x-r

if y > 0 && y.to_s(2).count('1') == ones && y.to_s(2).count('0') == zeroes
  puts "Yes"
  puts x.to_s(2)
  puts y.to_s(2)
else
  puts "No"
end

a,b,k = gets.chomp.split(" ").map(&:to_i)
b -= 1
if a == 0 && b == 0 && k == 0
  puts "Yes"
  puts 1
  puts 1
elsif k >= a+b || (k != 0 && a == 0) || (b == 0 && k > 0)
  puts "No"
else
  puts "Yes"
  x = Array.new(a+b,0)
  y = Array.new(a+b,0)
  if b > 0
    y[-1] = 1
    x[-(k+1)] = 1
  end
  i = 0
  (b-1).times do
    while x[i] == 1 || y[i] == 1
      i += 1
    end
    x[i] = 1
    y[i] = 1
    i += 1
  end
  x.unshift("1")
  y.unshift("1")
  puts x.join
  puts y.join
end

a,b,k = gets.chomp.split(" ").map(&:to_i)
b -= 1
if k >= a+b || (k != 0 && a == 0)
  puts "No"
else
  puts "Yes"
  x = Array.new(a+b,0)
  y = Array.new(a+b,0)
  y[-1] = 1
  x[-(k+1)] = 1
  i = 0
  (b-1).times do
    while x[i] == 1 || y[i] == 1
      i += 1
    end
    x[i] = 1
    y[i] = 1
    i += 1
  end
  x.unshift("1")
  y.unshift("1")
  puts x.join
  puts y.join
end

a,b,k = gets.chomp.split(" ").map(&:to_i)
if k == a+b || (k != 0 && a == 0)
  puts "No"
else
  puts "Yes"
  x = Array.new(a+b,0)
  y = Array.new(a+b,0)
  y[-1] = 1
  x[-(k+1)] = 1
  i = 0
  (b-1).times do
    while x[i] == 1 || y[i] == 1
      i += 1
    end
    x[i] = 1
    y[i] = 1
    i += 1
  end
  puts x.join
  puts y.join
end


gets.to_i.times do
	a = (1..9).map { gets.chomp.split('').map &:to_i }
	(0...9).each do |i|
		j = i % 3 * 3 + i / 3
		a[i][j] = a[i][j] == 9 ? 1 : a[i][j] + 1
	end
	puts a.map(&:join)
end

t = gets.chomp.to_i

(1..t).each{
    (0...9).each{|i|
        s = gets.chomp
        a = i / 3
        b = i % 3

        n = 3*b + a
        if s[n] == '9' then
            s[n] = '1'
        else
            s[n] = (s[n].ord + 1).chr
        end

        puts s
    }
}


n=gets.to_i
a=[]
(n-1).times {
a.push gets(' ').to_i
}
a.push gets.to_i

prog=(a.inject{|sum,x| sum + x })/2

suma=0
licznik=0

for i in a.sort.reverse
suma+=i
licznik+=1
if suma>prog
p licznik
break
end
end

def sum(numbers)
  total = 0

  numbers.each do |i|
    total += i
  end

  total
end

def quick_sort(numbers, lower_bound, upper_bound)
  if lower_bound < upper_bound
    p = partition(numbers, lower_bound, upper_bound)
    quick_sort(numbers, lower_bound, p - 1)
    quick_sort(numbers, p + 1, upper_bound)
  end

end

def partition(numbers, lower_bound, upper_bound)
  pivot = numbers[upper_bound]
  i, j = lower_bound, lower_bound

  while j <= upper_bound
    if numbers[j] < pivot
      numbers[i], numbers[j] = numbers[j], numbers[i]
      i += 1
    end

    j += 1
  end

  numbers[i], numbers[upper_bound] = numbers[upper_bound], numbers[i]
  i
end

def main
  number_of_coins = gets.to_i
  coins = gets.split.map(&:to_i)

  total_value = sum coins

  quick_sort(coins, 0, number_of_coins - 1)

  coins_needed = 0
  sum = 0

  until sum > total_value / 2
    sum += coins[number_of_coins - coins_needed - 1]
    coins_needed += 1
  end

  puts coins_needed
end

main if __FILE__ == $PROGRAM_NAME

n,*a=gets(p).split.map &:to_i;z=eval a*?+;p n-a.sort.index{|i|0>=z-=i*2}

n = STDIN.readline.to_i
coins = STDIN.readline.split.map {|s| s.to_i }
total = coins.inject(0, :+)
sum = 0
count = 0
coins.sort.reverse.each do |coin|
  sum += coin
  count += 1
  break if 2*sum > total
end
puts count

n = gets.chomp.to_i

array = gets.chomp.split(" ").map(&:to_i).sort.reverse
arr_sum = array.inject(&:+)
res = array[0]
ans = 0
(1..n).each{ |elem|
  if( res > arr_sum / 2.0)
    ans = elem
    break
  else
    res += array[elem]
  end
}
puts ans

gets
a = gets.strip.split.map(&:to_i)
sum = a.sort!.reverse!.inject(0) {|acc, m| acc + m }
f = 0
i = 0
while f <= sum-f
  f += a[i]
  i += 1
end
puts i

n = gets.to_i
a = gets.split(" ").map(&:to_i).sort{ |x,y| y <=> x }

for i in 0..n
  l = a[0..i].inject(:+)
  r = a[(i+1)..(a.size)].inject(:+) || 0
  if (l) > (r)
    puts i+1
    break
  end
end

n=gets.to_i
a=gets.split.map(&:to_i).sort{|x,y|y<=>x}
n.times do |i|
  if i+1<a.size&&a.slice(0,i+1).reduce(:+)>a.slice(i+1,a.size-i-1).reduce(:+)
  	p i+1
  	break
  elsif i+1==a.size
  	p i+1
  end
end

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

counter = a.reduce(:+)
xounter = 0
c = 0
for i in 0..n-1
  counter-=a[i]
  xounter+=a[i]
  c+=1
  break if xounter>counter
end

puts c

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

a.sort!.reverse!
$s = a.inject(:+)
#puts "s=#{$s}"

# returns [s1, t]
def find(a,n)
    if n == 1
        return [a.first, 1]
    else
        s1, t = find(a,n-1)
        #puts "s1=#{s1}, t=#{t}"
        s2 = $s - s1
        an = a[n-1]
        if s2>=s1
            s1 += an
            t += 1
        end
        return [s1, t]
    end
end

#p a
s1, t = find(a, a.count)
#p s1
p t

n =gets.chomp.to_i
a= gets.chomp
arr = a.split(/\s/).map(&:to_i)
arr.sort!.reverse!
sum1 =0
count  =0
check =0
arr.each{|x| check+=x }

check =check/2
arr.each do |i|
	sum1+=i
	count+=1
	if sum1>check
		break
	end
end
puts count

n = gets.chomp.to_i
a = gets.chomp.split(/ /).map!{|x| x.to_i}

a = a.sort
s = 0
for i in 0..n-1
    s = s + a[i]
end
ss = 0
nr = 0

i = n-1
begin
    if ss <= s
        ss = ss + a[i]
        s = s - a[i]
        nr = nr + 1
    else
        break
    end
    i = i - 1
end while i >= 0

puts nr

gets
inp = gets.chomp.split.map { |x| x.to_i }.sort
count, total = 0, 0
while total <= inp.inject(0, :+)
  total += inp.pop
  count += 1
end
puts count

a=gets.chomp.to_i
b=gets.chomp.split(" ")
sum=0
0.upto(a-1) do |i|
   b[i]= b[i].to_i
sum=sum+b[i]
end
r=0
if sum%2==0
    r=1
end

sum=(sum/2.0).ceil

b.sort!
b.reverse!
p=0
0.upto(a-1) do |i|
p=p+b[i].to_i

if ( p>=sum && r==0)
p=i+1
break
end
if  (p>sum && r==1)
p=i+1
break
end
end

puts "#{p}"

require 'pp'

gets
coins = gets.chomp.split(' ').map(&:to_i).sort

i = coins.length - 1
while i >= 0
  head = coins[0..i-1]
  tail = coins[i..-1]
  head_sum = head.inject(&:+)
  tail_sum = tail.inject(&:+)

  debug =  {
    head: head,
    tail: tail,
    head_sum: head_sum,
    tail_sum: tail_sum,
  }

  if tail_sum > head_sum
    break
  end
  # pp debug
  i -= 1
end
puts coins.length - [i, 0].max
#pp coins

n= gets.to_i
a = gets.split.map(&:to_i)
tot, sum, i= 0,0,0
a.each {|x| tot += x}
a.sort! {|x,y| y<=>x}
until sum>tot-sum
  sum += a[i]
  i += 1
end
puts i

def sum( coins )
    sum = 0
    coins.each do |coin|
        sum += coin
    end
    sum
end

gets.chomp
coins = gets.chomp.split(/ /).map(&:to_i)
coins.sort!
my_coins = []
(coins.length - 1).downto(0).each do |coin|
    break if ( sum( my_coins ) > sum( coins ) )
    my_coins << coins.delete_at( coin )
end
puts my_coins.length

n = gets.to_i
a = gets.split.map(&:to_i).push(0).sort
b = [0]
c = 0
loop do
  break if b.inject(:+) > a.inject(:+)
  b << a.pop
  c += 1
end

p c

class C160A
  n = gets.to_i
  a = []
  gets.split.map{|c| a << c.to_i}
  a.sort!
  a.reverse!
  s = 0
  a.map{|c| s += c}
  t = 0
  q = 0
  a.map{|c| t += c; q += 1; break if t * 2 > s}
  puts q
end

a=[]
n=gets.to_i
b=gets.split
n.times{|i|
	a[i]=b[i].to_i}
a.sort!

b=0
ans=0
halfsum=a.inject(:+)/2

n.times{|i|
	break if b>halfsum
	b+=a[-i-1]
	ans+=1}
p ans

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

n = $stdin.gets.to_i
xs = $stdin.gets.split.map(&:to_i).sort.reverse
s = xs.inject 0, :+
acc = 0
xs.each_with_index do |x, i|
  acc += x
  if acc*2 > s
    puts i+1
    break
  end
end

n = gets.to_i
a = gets.chomp.split.map(&:to_i).sort.reverse
sum = a.inject(:+)
count = 0
money = 0

a.each { |i| count += 1; money += i; break if money > (sum/2.0) }

puts count

n = gets.to_i
a = gets.split().map &:to_i
a=a.sort.reverse
sum = a.inject 0 do |x,y| x + y end
s=0
cnt = 0

while s + s <= sum
    s += a[cnt]
    cnt = cnt + 1
end

puts cnt

n = gets.strip.to_i
a = gets.strip.split.map(&:to_i)[0..(n-1)].sort! {|x, y| y <=> x}
sum = a.reduce(:+)
segment = 0
count = 0
a.each do |item|
	segment += item
	count += 1
	if segment * 2 > sum
		break
	end
end
puts count

n = Integer(gets)
input = gets.chomp
nums = input.split
value = Array.new
for i in 0...n
    value[i] = Integer(nums[i])
end

value = value.sort{|x,y| y <=> x}
sum = 0
for i in 0...n
    sum = sum + value[i]
end

v = Array.new
x = 0
for i in 0..n
    if x > sum - x then
        break

    else
        v.push(value[i])
        x = x + value[i]
    end
end

puts v.length

coins = gets.chomp.to_i
values = gets.chomp
values = values.split

total = 0
for i in (0..coins-1)
	for x in (i..coins-1)
		if i != x
			if values[i].to_i < values[x].to_i
				temp = values[i].to_i
				values[i] = values[x].to_i
				values[x] = temp
			end
		end
	end
	total += values[i].to_i
end

test_values = 0
count = 0
for i in (0..coins-1)
	if test_values <= total - test_values
		test_values += values[i].to_i
		count += 1
	else
		break
	end
end

print count

n=gets.to_i
a=gets.split.map(&:to_i)
a.sort!
a.reverse!
#puts a[0]
sum = 0
a.each do
  |t|
  sum += t
end
 res = 1
 sum2=0
a.each do
  |t|
  sum2+=t
  break if sum2 > (sum-sum2)
  res += 1
end
puts res

n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i).sort_by{ |x| -x }

s = a.reduce(&:+)
sum = 0

a.each_with_index do |x, i|
    sum += x
    if sum > s / 2
        puts i + 1
        break
    end
end

def sum(a)
    a.inject(0){|sum,x| sum + x}
end

n = gets.to_i
arr = gets.split(" ").map(&:to_i)
arr.sort!{|x, y| y <=> x}
total = sum(arr)
i = 0
while i < n
    arr_sum = sum arr[0,i+1]
    i += 1
    if arr_sum > total - arr_sum
        puts i
        break
    end

end

def sum(a)
    a.inject(0){|sum,x| sum + x}
end

n = gets.to_i
arr = gets.split(" ").map(&:to_i)
arr.sort!{|x, y| y <=> x}
total = sum(arr)
i = 0
arr_sum = 0
while i < n
    arr_sum += arr[i]
    i += 1
    if arr_sum > total - arr_sum
        puts i
        break
    end

end

gets
cs = gets.split.map(&:to_i).sort.reverse
sum = cs.inject(:+)
puts cs.index{ |x| 0 > sum -= 2*x } + 1

n,*a=gets(p).split.map &:to_i;z=eval a*?+;p n-a.sort.index{|i|0>=z-=i*2}

gets
l = gets.split.map(&:to_i).sort { |x, y| y <=> x }
s = l.reduce(:+)
t = 0
c = 0

l.each { |x|
			c += 1
			t += x
			if t > s - t
				break
			end
		}

puts c

coin_number = gets.chomp.to_i
coin_seq_number = gets.chomp.split
coin_seq_number = coin_seq_number.map{|item| item.to_i}
coin_seq_sum = coin_seq_number.inject {|sum, i| sum + i}
coin_seq_number = coin_seq_number.sort{|a,b| b <=> a}
i = 0
coin_res_sum = 0
begin
  coin_res_sum = coin_seq_number[i] + coin_res_sum
  i = i + 1
end while coin_res_sum < coin_seq_sum / 2
if coin_res_sum == coin_seq_sum/2 then
  p i+1
else
  p i
end

n = STDIN.gets.chomp.to_i
coins = []

coins = STDIN.gets.split.map { |n| n.to_i }

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

total = coins.reduce(:+)

sum = 0
numC = 0
while sum <= total/2
  sum += coins[numC]
  numC += 1
end

puts numC

n = gets.to_i
a = gets.split.map(&:to_i).sort.reverse
sum = a.reduce(:+)

(0...n).each do |i|
  former = a[0..i].reduce(:+)
  if former > sum - former
    puts i + 1
    break
  end
end

n = gets.to_i
a = gets.chomp.split(" ")

for x in 0...a.size
	a[x] = a[x].to_i
end

a.sort! {|y,x| x<=>y}

sum1 = 0
sum2 = 0
m = 0

for x in 0...a.size
	sum1 += a[x]
	for y in x+1...a.size
		sum2 += a[y]
	end
	if sum1>sum2
		m = x+1
		break
	end
	sum2 = 0
end

puts m

n, coins = gets.to_i, gets.split.map(&:to_i).sort.reverse
sum = 0
total = coins.inject(:+)
(n + 1).times do |i|
	if sum > total / 2
		puts i
		break
	end
	sum += coins[i]
end

t = gets.to_i
a = gets.split(" ").map(&:to_i)
a = a.sort.reverse
sum=-1
for i in 0..t
    if a[0,i].inject(0, :+)>a[i,t].inject(0, :+)
        sum=i
        break
    end
end
print(sum)

n = gets.chomp.to_i
coins = gets.split.collect{|i| i.to_i}
coins = coins.sort{|x,y| y <=> x}

target = coins.inject(:+) / 2
sum = 0
coins.each_index{|i|
  sum += coins[i]
  if sum > target
    puts i + 1
    break
  end
}

n = gets.to_i
a = gets.split.map(&:to_i)
a = a.sort.reverse
total = a.inject(:+)
s = 0
a.each_with_index do |x, i|
  s += x
  if 2 * s > total
    puts i + 1
    break
  end
end

gets
a=gets.split.map(&:to_i)
a.sort!
a.reverse!
sum=a.inject{|res,x|res+x}
k=0
for i in 0..a.length-1
 if 2*k<=sum
   k+=a[i]
 end
 if 2*k>sum
   break
 end
end
puts i+1

n = gets
a = gets.split(' ').map(&:to_i).sort
s = []

while s.inject(0, &:+) <= a.inject(0, &:+)
  s << a.pop
end

puts s.size

n = gets.to_i
a = gets.split

sum = 0
for i in 0 ... a.size
	a[i] = a[i].to_i
	sum += a[i]
end

a.sort!.reverse!

sum2 = 0
for i in 0 ... a.size
	sum2 += a[i]
	if sum2 > sum / 2 then
		puts((i + 1).to_s)
		break
	end
end

_ = gets.chomp
a = gets.chomp.split(/ /).map(&:to_i).sort { |a,b| b <=> a}
my_count = 0
my = 0
all = a.inject(0) { |sum, x| sum + x }
a.each do |a_i|
  my += a_i
  all -= a_i
  my_count += 1
  break if my > all
end
puts my_count

input = STDIN.read.split("\n")[1].split(" ").map(&:to_i).sort!

count = 0
sum = 0

while !input.empty? and sum <= input.inject {|sum, v| sum += v} do
	sum += input.pop
	count += 1
end

STDOUT.puts count

coinNum = gets.chomp.to_i
coins = gets.chomp.split(' ').map(&:to_i).sort.reverse
ans = 0
coins << 0

for i in (0...coinNum)
	ans += 1
	break if coins[0..i].reduce(:+) > coins[(i + 1)...coins.length].reduce(:+)
end

puts ans

ln1 = gets
n = ln1.to_i
ln2 = gets
s = ln2.split(' ')
a = Array.new(0)
sum = 0
for i in 0..n-1
  a << s[i].to_i
  sum += a[i]
end
a = a.sort
a = a.reverse
idx = 0
have = 0
for i in 0..n-1
  sum -= a[i]
  have += a[i]
  if(have > sum)
    idx = i
    break
  end
end
p idx + 1

n = gets.to_i
a = gets.split.map(&:to_i)
sum = 0
a.each { |e|
  sum += e
}
a.sort!.reverse!
res = 0
have = 0
n.times { |i|
  sum -= a[i]
  have += a[i]
  (res = i + 1; break) if have > sum
}
p res

n = gets.to_i
a = gets.split.map(&:to_i).sort.reverse
sum = 0
a.each { |e|
  sum += e
}
res = 0
have = 0
n.times { |i|
  sum -= a[i]
  have += a[i]
  (res = i + 1; break) if have > sum
}
p res

n = gets.to_i
m = gets.split(' ').map{|_|_.to_i}.sort{|x,y| y<=>x}
total = m.inject(:+)
sum=0
m.each.with_index do |obj,id|
  sum+=obj
  if sum*2>total
    puts id+1
    break
  end
end

gets
a = gets.strip.split.map(&:to_i)
sum = a.sort!.reverse!.inject(0) {|acc, m| acc + m }
f = 0
i = 0
while f <= sum-f
  f += a[i]
  i += 1
end
puts i

n = gets
coins = gets.chomp.split(' ').map(&:to_i).sort{|x,y| y <=> x}
sum = coins.reduce(:+)
counter = 0
taken_sum = 0
coins.each do |coin|
  taken_sum += coin
  counter += 1
  sum -= coin
  break if taken_sum > sum
end

puts counter

n = gets.chomp.to_i

coins = gets.chomp.split().map { |x| x.to_i }
coins.sort!
coins.reverse!

sumLeft = 0
for i in coins
    sumLeft += i
end

i = 0
sumRight = 0
while i < n
    sumLeft -= coins[i]
    sumRight += coins[i]
    if sumRight > sumLeft
        break
    end
    i += 1
end

puts (i+1)

n = gets.to_i
st = gets.split
i = 0
sum = 0
while i<n do
    st[i] = st[i].to_i
    sum += st[i]
    i += 1
end
st = st.sort.reverse
min = sum/2
coins = 1
s1 = st[0]
j = 0
while s1<=min do
    j += 1
    i = st.size-1
    while (i>j && s1+st[i]<=min) do
        i -= 1
    end
    if i<=j then
        s1 = s1 + st[j]
    else
        s1 = s1 + st[i]
    end
    coins += 1
end
puts "#{coins}"

n = gets.chomp.to_i
m = gets.chomp.split(/ /).map!{|x| x.to_i}
m.sort!.reverse!
sum = 0
for i in 0..m.length-1
	sum += m[i]
end
wsum = 0
ret = 0
for i in 0..m.length-1
	ret += 1
	wsum += m[i]
	rest = sum - wsum
	if rest < wsum
		break
	end
end
puts ret

# cook your code here

n = gets.to_i
a = gets.chomp.split
sum = 0
cum = Array.new

for i in 0...n
    a[i] = a[i].to_i
    sum += a[i]
end

a =  a.sort { |x,y| y.to_i <=> x.to_i }

cum[0] = a[0]
i = 0

until cum[i] > sum/2
    i+=1
    cum[i] = cum[i-1] + a[i]
end

puts i+1

n,*a=gets(p).split.map &:to_i;z=eval a*?+;p n-a.sort.index{|i|0>=z-=i*2}

n = gets.to_i
a = gets.split.map(&:to_i).sort.reverse
b = []
a.each do |_|
    b << _
    if a.inject(&:+) < b.inject(&:+) * 2
        p b.size
        break
    end
end

n,*a=gets(p).split.map &:to_i;z=eval a*?+;n-=1while 0<z-=a.sort[-n]*2;p n

gets
a=gets.split.map &:to_i
z=a.inject:+
p a.sort.reverse.count{|i|0<=z-=i*2}+1

sum=0
n=gets.to_i
a=gets.split.map(&:to_i)
a.sort!
a.reverse!
a.each{|i| sum+=i }
ans=0
tmp=0
a.each{|i|
        ans+=1
        sum-=i
        tmp+=i
        if tmp>sum
                p ans
                exit
        end
}

n = gets.to_i
a = gets.split.map &:to_i
a.sort!{|a,b|b<=>a}

sumAll = 0
a.each {|el| sumAll += el }

cnt = 0
sum = 0
a.each do |el|
  sum += el
  cnt += 1
  break if sum > sumAll / 2
end
puts cnt

n = gets.chomp.to_i
a = gets.chomp.split(" ").map{|e| e.to_i}.sort!{|a, b| -(a <=> b)}
b = []
c = 0
while a.length > 0 do
  b << a.shift
  c += 1
  if b.inject(0){|s, i| s += i} > a.inject(0){|s, i| s += i}
    break
  end
end

puts c

n = gets
coins = gets.chomp.split(' ').map(&:to_i).sort
sum = coins.reduce(:+)
counter = 0
taken_sum = 0
coins.each do |coin|
  taken_sum += coin
  counter += 1
  sum -= coin
  break if taken_sum > sum
end

puts counter

n = gets.to_i
st = gets.split
i = 0
sum = 0
while i<n do
    st[i] = st[i].to_i
    sum += st[i]
    i += 1
end
st = st.sort.reverse
min = sum/2
coins = 1
s1 = st[0]
j = 0
while s1<=min do
    j += 1
    i = st.size-1
    while (i>1 && s1+st[i]<=min) do
        i -= 1
    end
    if i<=1 then s1 = s1 + st[j]
    else
        s1 = s1 + st[i]
    end
    coins += 1
end
puts "#{coins}"

sum=0
n=gets.to_i
a=gets.split.map(&:to_i)
a.sort!
a.reverse!
a.each{|i| sum+=i }
ans=0
tmp=0
a.each{|i|
        ans+=1
        sum-=i
        tmp+=i
        if tmp>i
                p ans
                exit
        end
}

n = gets.chomp.to_i
a = gets.chomp.split(" ").map{|e| e.to_i}.sort!
b = []
c = 0
while a.length > 0 do
  b << a.shift
  c += 1
  if b.inject(0){|s, i| s += i} > a.inject(0){|s, i| s += i}
    break
  end
end

puts c

n = gets.to_i
a = gets.split(" ").map(&:to_i).sort{ |x,y| y <=> x }

for i in 0..n
  l = a[0..i].inject(:+)
  r = a[i..(a.size)].inject(:+) || 0
  if (l) > (r)
    puts i+1
    break
  end
end

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

a.sort!.reverse!
$s = a.inject(:+)
#puts "s=#{$s}"

# returns [s1, t]
def find(a,n)
    if n == 1
        return [a.first, 1]
    else
        s1, t = find(a,n-1)
        #puts "s1=#{s1}, t=#{t}"
        s2 = $s - s1
        an = a[n-1]
        if s2>s1
            s1 += an
            t += 1
        end
        return [s1, t]
    end
end

#p a
s1, t = find(a, a.count)
#p s1
p t

require 'pp'

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

i = coins.length - 1
while i >= 0
  head = coins[0..i-1]
  tail = coins[i..-1]
  head_sum = head.inject(&:+)
  tail_sum = tail.inject(&:+)

  debug =  {
    head: head,
    tail: tail,
    head_sum: head_sum,
    tail_sum: tail_sum,
  }

  if tail_sum > head_sum
    break
  end
  # pp debug
  i -= 1
end
puts coins.length - [i, 0].max
#pp coins

n = gets.to_i
a = gets.chomp.split(//).sort.reverse.map(&:to_i)
sum = a.inject(:+)
count = 0
money = 0

a.each { |i| count += 1; money += i; break if money > (sum/2.0).ceil }

puts count

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

sum = a.inject 0 do |x,y| x + y end
s=0
cnt = 0

while s + s <= sum
    s += a[cnt]
    cnt = cnt + 1
end

puts cnt

n = Integer(gets)
input = gets.chomp
nums = input.split
value = Array.new
for i in 0...n
	value[i] = Integer(nums[i])
end

value = value.sort{|x,y| y <=> x}
sum = 0
for i in 0...n
	sum = sum + value[i]
end

v = Array.new
x = 0
for i in 0...n
	if x > sum - x
		puts v.length
	else
		v.push(value[i])
		x = x + value[i]
	end
end

n = Integer(gets)
input = gets.chomp
nums = input.split
value = Array.new
for i in 0...n
    value[i] = Integer(nums[i])
end

value = value.sort{|x,y| y <=> x}
sum = 0
for i in 0...n
    sum = sum + value[i]
end

v = Array.new
x = 0
for i in 0..n
    if x > sum - x
        puts v.length
    else
        v.push(value[i])
        x = x + value[i]
    end
end

n=gets.to_i
a=gets.split.map(&:to_i)
a.sort!
sum = 0
a.each do
  |t|
  sum += t
end
 res = 1
 sum2=0
a.each do
  |t|
  sum2+=t
  break if sum2 > (sum-sum2)
  res += 1
end
puts res

def sum(a)
    a.inject(0){|sum,x| sum + x}
end

n = gets.to_i
arr = gets.split(" ").map(&:to_i)
arr.sort!{|x, y| y <=> x}
total = sum(arr)
i = 0
while i < n
    arr_sum = sum arr[0,i+1]
    i += 1
    if arr_sum >= total - arr_sum
        puts i
        break
    end

end

coin_number = gets.chomp.to_i
coin_seq_number = gets.chomp.split

coin_seq_number = coin_seq_number.map{|item| item.to_i}
coin_seq_sum = coin_seq_number.inject {|sum, i| sum + i}

i = 0
coin_res_sum = 0
begin
  coin_res_sum = coin_seq_number[i] + coin_res_sum
  i = i + 1
end while coin_res_sum < coin_seq_sum / 2
if coin_number < i+1  then
  p coin_number
else
  p i+1
end

coin_number = gets.chomp.to_i
coin_seq_number = gets.chomp.split

coin_seq_number = coin_seq_number.map{|item| item.to_i}
coin_seq_sum = coin_seq_number.inject {|sum, i| sum + i}

i = 0
coin_res_sum = 0
begin
  coin_res_sum = coin_seq_number[i] + coin_res_sum
  i = i + 1
end while coin_res_sum < coin_seq_sum / 2
p i+1

t = gets.to_i
a = gets.split(" ").map(&:to_i)
a = a.sort
sum=-1
for i in 0..t
    if a[0,i].inject(0, :+)>a[i,t].inject(0, :+)
        sum=i
        break
    end
end
print(sum)

a=gets.chomp.to_i
b=gets.chomp.split(" ").sort.reverse
sum=0
0.upto(a-1) do |i|
sum=sum+b[i].to_i
end
sum=(sum/2)+1
p=0
0.upto(a-1) do |i|
p=p+b[i].to_i
if  p>sum
p=i+1
break
end
end

puts "#{p}"

a=gets.chomp.to_i
b=gets.chomp.split(" ")
sum=0
0.upto(a-1) do |i|
   b[i]= b[i].to_i
sum=sum+b[i]
end
r=0
if sum%2==0
    r=1
end

sum=(sum/2.0).ceil
b.sort!
b.reverse!
p=0
0.upto(a-1) do |i|
p=p+b[i].to_i

if  p>=sum && r==0
p=i+1
break
end
if  p>sum && r==1
p=i+1
break
end
end

a=gets.chomp.to_i
b=gets.chomp.split(" ")
sum=0
0.upto(a-1) do |i|
   b[i]= b[i].to_i
sum=sum+b[i]
end
sum=(sum/2.0).ceil
b.sort!
b.reverse!
p=0
0.upto(a-1) do |i|
p=p+b[i].to_i
if  p>sum
p=i+1
break
end
end

puts "#{p}"

n=gets.to_i
a=[]
(n-1).times {
a.push gets(' ').to_i
}
a.push gets.to_i

prog=(a.inject{|sum,x| sum + x })/2

suma=0
licznik=0

for i in a.sort
suma+=i
licznik+=1
if suma>prog
p licznik
break
end
end

_ = gets.chomp
a = gets.chomp.split(/ /).map(&:to_i).sort { |a,b| b <=> a}
my_count = 0
my = 0
twins = 0
a.each do |a_i|
  if twins + a_i >= my
    my += a_i
    my_count += 1
  else
    twins += a_i
  end
end
puts my_count

_ = gets.chomp
a = gets.chomp.split(/ /).map(&:to_i)
my_count = 0
my = 0
twins = 0
a.each do |a_i|
  if twins + a_i >= my
    my += a_i
    my_count += 1
  else
    twins += a_i
  end
end
puts my_count

input = STDIN.read.split("\n")[1].split(" ").map(&:to_i).sort!
count = 0

while !input.empty? and count < input.inject {|sum, v| sum += v} do
	input.pop
	count += 1
end

STDOUT.puts count


x1, y1, x2, y2 = gets.split(' ').map(&:to_i)

if x1 != x2  &&  y1 != y2
  if (x1-x2).abs != (y1-y2).abs
    puts -1
  else
    puts "#{x1} #{y2} #{x2} #{y1}"
  end
elsif x1 != x2
  delta = (x1 - x2).abs
  puts "#{x1} #{y1+delta} #{x2} #{y2+delta}"
elsif y1 != y2
  delta = (y1 - y2).abs
  puts "#{x1+delta} #{y1} #{x2+delta} #{y2}"
else
  puts -1
end

x1, y1, x2, y2 = gets.split.map &:to_i

def evaluate_vertical_side x1, x2, y1, y2
  delta_y = (y2 - y1).abs
  if x1 + delta_y <= 1000
    x3 = x1 + delta_y
    return [x3, y1, x3, y2]
  elsif x1 - delta_y >= -1000
    x3 = x1 - delta_y
    return [x3, y1, x3, y2]
  else
    return -1
  end
end

if x1 == x2 #vertical side
  new_points = evaluate_vertical_side x1, x2, y1, y2
  puts new_points == -1? "-1" : "#{new_points[0]} #{new_points[1]} #{new_points[2]} #{new_points[3]}"
elsif y1 == y2 #horizontal side
  x1, y1 = y1, x1
  x2, y2 = y2, x2
  new_points = evaluate_vertical_side x1, x2, y1, y2
  puts new_points == -1? "-1" : "#{new_points[1]} #{new_points[0]} #{new_points[3]} #{new_points[2]}"
elsif (y2 - y1).abs == (x2 - x1).abs #diagonal
  x3 = x1
  y3 = y2
  x4 = x2
  y4 = y1
  puts "#{x3} #{y3} #{x4} #{y4}"
else #not squar
  puts "-1"
end

x, y, a, b = gets.split.map(&:to_i)
x, y, a, b = [[x, y], [a, b]].min[0], [[x, y], [a, b]].min[1], [[x, y], [a, b]].max[0], [[x, y], [a, b]].max[1]
if x == a
  puts [x + (y - b).abs, y, a + (y - b).abs, b].map(&:to_s).join(" ")
elsif y == b
  puts [x, y + (x - a).abs, a, b + (x - a).abs].map(&:to_s).join(" ")
else
  if a > x && b > y
    if a - x == b - y
      puts [x, b, a, y].map(&:to_s).join(" ")
    else
      puts "-1"
    end
  else
    if a - x == y - b
      puts [x, b, a, y].map(&:to_s).join(" ")
    else
      puts "-1"
    end
  end
end

x1,y1,x2,y2 = gets.split.map(&:to_i)
dx = (x2-x1)
dy = (y2-y1)

if dx != 0 and dy != 0 and dx.abs != dy.abs
  puts -1
elsif dx == 0
  puts "#{x1+dy} #{y1} #{x1+dy} #{y1+dy}"
elsif dy == 0
  puts "#{x1} #{y1+dx} #{x1+dx} #{y1+dx}"
else
  puts "#{x1} #{y1+dy} #{x1+dx} #{y1}"
end

x1, y1, x2, y2 = gets.chomp.split(/ /).map(&:to_i)
x3, y3, x4, y4 = [0, 0, 0, 0]
invalid = false
if x1 == x2
    diff = (y2 - y1).abs
    x3, x4 = x1 + diff, x2 + diff
    y3, y4 = y1, y2
elsif y1 == y2
    diff = (x2 - x1).abs
    x3, x4 = x1, x2
    y3, y4 = y1 + diff, y2 + diff
elsif (x2 - x1).abs == (y2 - y1).abs
    x3, y3, x4, y4 = x1, y2, x2, y1
else
    invalid = true
end
if !invalid
    puts "#{x3} #{y3} #{x4} #{y4}"
else
    puts "-1"
end

x1,y1,x2,y2=gets.split.map{|e| e.to_i}

dx=x2-x1
dy=y2-y1
dx2=dx.abs
dy2=dy.abs
if dx2==0 && dy2==0 then
	puts -1
elsif dx2==dy2 then
	puts [x1,y2,x2,y1]*" "
elsif dx2==0 then
	puts [x1+dy,y1,x2+dy,y2]*" "
elsif dy2==0 then
	puts [x1,y1+dx,x2,y2+dx]*" "
else
	puts -1
end

class Point
  def initialize(x_c,y_c)
    @x_coord=x_c
    @y_coord=y_c
  end
  def x
    return @x_coord
  end
  def y
    return @y_coord
  end
end

a,b,c,d = gets.split(" ").map {|x| x.to_i}

p1=Point.new(a,b)
p2=Point.new(c,d)

if p1.x==p2.x
  d = (p1.y-p2.y).abs
  print "#{p1.x+d} #{p1.y} #{p2.x+d} #{p2.y}"
  exit
end

if p1.y==p2.y
  d = (p1.x-p2.x).abs
  print "#{p1.x} #{p1.y+d} #{p2.x} #{p2.y+d}"
  exit
end

if (p1.x-p2.x).abs!=(p1.y-p2.y).abs
  print "-1"
  exit
end

print "#{p1.x} #{p2.y} #{p2.x} #{p1.y}"

# coding: utf-8

# if __FILE__ == $0
# end

x1, y1, x2, y2 = gets.split.map(&:to_i)
# -100..100
if x1 == x2
    # vertical edge
    len = (y1 - y2).abs
    puts "#{x1 + len} #{y1} #{x2 + len} #{y2}"
elsif y1 == y2
    # horizontal edge
    len = (x1 - x2).abs
    puts "#{x1} #{y1 + len} #{x2} #{y2 + len}"
elsif (x1-x2).abs == (y1-y2).abs
    # diagonal edge (must be square)
    if x1 < x2
        puts "#{x1} #{y2} #{x2} #{y1}"
    else
        puts "#{x2} #{y1} #{x1} #{y2}"
    end
else
    # impossible
    puts -1
end

xxyy = gets.chomp
xxyy = xxyy.split
x1 = xxyy[0].to_i
y1 = xxyy[1].to_i
x2 = xxyy[2].to_i
y2 = xxyy[3].to_i

if x1 == x2 && y1 != y2
	print x1 + [y1, y2].max - [y1,y2].min
	print " "
	print [y1, y2].max
	print " "
	print x1 + [y1, y2].max - [y1,y2].min
	print " "
	print [y1,y2].min
elsif y1 == y2 && x1 != x2
	print [x1,x2].min
	print " "
	print y1 - ([x1,x2].max - [x1,x2].min)
	print " "
	print [x1,x2].max
	print " "
	print y1 - ([x1,x2].max - [x1,x2].min)
else
	if (x1 - x2).abs == (y1 - y2).abs
		print x1
		print " "
		print y2
		print " "
		print x2
		print " "
		print y1
	else
		print -1
	end
end

line = gets
x1, y1, x2, y2 = line.split.map(&:to_i)
if y1 == y2
	l = (x1 - x2).abs
	y3 = y1 + l
	x3 = x1
	y4 = y2 + l
	x4 = x2
	puts [x3, y3, x4, y4].join " "
elsif x1 == x2
	l = (y1 - y2).abs
	x3 = x1 + l
	y3 = y1
	x4 = x2 + l
	y4 = y2
	puts [x3, y3, x4, y4].join " "
elsif (x1 - x2).abs == (y1 - y2).abs
	l = (x1 - x2).abs
	x3 = x1
	y3 = if y1 > y2
		y1 - l
	else
		y1 + l
	end
	x4 = if x1 > x2
		x1 - l
	else
		x1 + l
	end

	y4 = y1
	puts [x3, y3, x4, y4].join " "
else
	puts "-1"
end

x, y, a, b = gets.split.map(&:to_i)

x, y, a, b = [[x, y], [a, b]].min[0], [[x, y], [a, b]].min[1],
              [[x, y], [a, b]].max[0], [[x, y], [a, b]].max[1]

if x == a
  puts [x + (y-b).abs, y, a + (y-b).abs, b].map(&:to_s).join(" ")
elsif y == b
  puts [x, y + (x-a).abs, a, b + (x-a).abs].map(&:to_s).join(" ")
else
  if a > x && b > y
    if a - x == b - y
      puts [x, b, a, y].map(&:to_s).join(" ")
    else
      puts "-1"
    end
  else
    if a - x == y - b
      puts [x, b, a, y].map(&:to_s).join(" ")
    else
      puts "-1"
    end
  end
end

x1, y1, x2, y2 = gets.split.map &:to_i

def evaluate_vertical_side x1, x2, y1, y2
  delta_y = (y2 - y1).abs
  if x1 + delta_y <= 1000
    x3 = x1 + delta_y
    return [x3, y1, x3, y2]
  elsif x1 - delta_y >= -1000
    x3 = x1 - delta_y
    return [x3, y1, x3, y2]
  else
    return -1
  end
end

if x1 == x2 #vertical side
  new_points = evaluate_vertical_side x1, x2, y1, y2
  puts new_points == -1? "-1" : "#{new_points[0]} #{new_points[1]} #{new_points[2]} #{new_points[3]}"
elsif y1 == y2 #horizontal side
  x1, y1 = y1, x1
  x2, y2 = y2, x2
  new_points = evaluate_vertical_side x1, x2, y1, y2
  puts new_points == -1? "-1" : "#{new_points[0]} #{new_points[1]} #{new_points[2]} #{new_points[3]}"
elsif (y2 - y1).abs == (x2 - x1).abs #diagonal
  x3 = x1
  y3 = y2
  x4 = x2
  y4 = y1
  puts "#{x3} #{y3} #{x4} #{y4}"
else #not squar
  puts "-1"
end

x1, y1, x2, y2 = gets.split.map &:to_i

def evaluate_vertical_side x1, x2, y1, y2
  if x1 + (y2 - y1) <= 1000
    x3 = x1 + (y2 - y1)
    return [x3, y1, x3, y2]
  elsif x1 - (y2 - y1) >= -1000
    x3 = x1 - (y2 - y1)
    return [x3, y1, x3, y2]
  else
    return -1
  end
end

if x1 == x2 #vertical side
  new_points = evaluate_vertical_side x1, x2, y1, y2
  puts new_points == -1? "-1" : "#{new_points[0]} #{new_points[1]} #{new_points[2]} #{new_points[3]}"
elsif y1 == y2 #horizontal side
  x1, y1 = y1, x1
  x2, y2 = y2, x2
  new_points = evaluate_vertical_side x1, x2, y1, y2
  puts new_points == -1? "-1" : "#{new_points[0]} #{new_points[1]} #{new_points[2]} #{new_points[3]}"
elsif (y2 - y1).abs == (x2 - x1).abs #diagonal
  x3 = x1
  y3 = y2
  x4 = x2
  y4 = y1

  puts "#{x3} #{y3} #{x4} #{y4}"
else #not squar
  puts "-1"
end

x1, y1, x2, y2 = gets.chomp.split(/ /).map(&:to_i)
x3, y3, x4, y4 = [0, 0, 0, 0]
invalid = false
if x1 == x2
    diff = (y2 - y1).abs
    x3, x4 = x1 + diff, x2 + diff
    y3, y4 = y1, y2
elsif y1 == y2
    diff = (y2 - y1).abs
    x3, x4 = x1, x2
    y3, y4 = y1 + diff, y2 + diff
elsif (x2 - x1).abs == (y2 - y1).abs
    x3, y3, x4, y4 = x1, y2, x2, y1
else
    invalid = true
end
if !invalid
    puts "#{x3} #{y3} #{x4} #{y4}"
else
    puts "-1"
end

x1,y1,x2,y2=gets.split.map{|e| e.to_i}

dx=x2-x1
dy=y2-y1
if dx==0 && dy==0 then
	puts -1
elsif dx==dy then
	puts [x1,y1+dx,x2,y2-dy]*" "
elsif dx==0 then
	puts [x1+dy,y1,x2+dy,y2]*" "
elsif dy==0 then
	puts [x1,y1+dx,x2,y2+dx]*" "
else
	puts -1
end

x1,y1,x2,y2 = gets.split.map(&:to_i)
dx = (x2-x1)
dy = (y2-y1)

if dx != 0 and dy != 0 and dx.abs != dy.abs
  puts -1
elsif dx == 0
  puts "#{x1+dx} #{y1} #{x1+dx} #{y1+dy}"
elsif dy == 0
  puts "#{x1} #{y1+dy} #{x1+dx} #{y1+dy}"
else
  puts "#{x1} #{y1+dy} #{x1+dx} #{y1}"
end

x1,y1,x2,y2 = gets.split.map(&:to_i)
dx = (x2-x1)
dy = (y2-y1)
if dx != 0 and dy != 0 and dx != dy
  puts -1
elsif dx == 0
  puts "#{x1+dy} #{y1} #{x1+dy} #{y1+dy}"
elsif dy == 0
  puts "#{x1} #{y1+dx} #{x1+dx} #{y1+dx}"
else
  puts "#{x1} #{y1+dx} #{x1+dx} #{y1}"
end

line = gets
x1, y1, x2, y2 = line.split.map(&:to_i)
if y1 == y2
	l = (x1 - x2).abs
	y3 = y1 + l
	x3 = x1
	y4 = y2 + l
	x4 = x2
	puts [x3, y3, x4, y4].join " "
elsif x1 == x2
	l = (y1 - y2).abs
	x3 = x1 + l
	y3 = y1
	x4 = x2 + l
	y4 = y2
	puts [x3, y3, x4, y4].join " "
elsif (x1 - x2).abs == (y1 - y2).abs
	l = (x1 - x2).abs
	x3 = x1
	y3 = y1 + l
	x4 = x1 + l
	y4 = y1
	puts [x3, y3, x4, y4].join " "
else
	puts "-1"
end


n = gets.to_i
seqs = []
n.times do |i|
  seqs << gets.strip
end

hsh = {}

seqs.each do |seq|
  b = 0
  balanced = true
  seq.each_char do |c|
    if c == '('
      b += 1
    end
    if c == ')'
      b -= 1
    end
    balanced = false if b < 0
  end
  hsh[b] = (hsh[b] || 0) + 1 if balanced

  b = 0
  balanced = true
  seq.reverse.each_char do |c|
    if c == '('
      b += 1
    end
    if c == ')'
      b -= 1
    end
    balanced = false if b > 0
  end
  hsh[b] = (hsh[b] || 0) + 1 if balanced && b<0
end

# puts hsh
ans = 0
ans += (hsh[0] * hsh[0]) if hsh[0]
pos_ub = hsh.keys.select{|x| x>0}
pos_ub.each do |pub|
  nub = -1 * pub
  ans += (hsh[pub] * (hsh[nub] || 0))
end
puts ans

# http://codeforces.com/problemset/problem/990/C

def count_seq
  n = gets.to_i
  h = {}
  regular = 0
  0.upto(n - 1) do |i|
    bs = gets.chomp
    ret = parse(bs)
    next if ret.nil?

    if ret == ''
      regular += 1
    elsif
      h[ret] ||= 0
      h[ret] += 1
    end
  end

  c = regular * regular
  # puts h.inspect

  h.each do |key, count|
    next if key[0] == ')'

    other_key = [')', key[1]]
    other_c = h[other_key]
    # puts "other_c #{other_c}"
    if other_c
      c += other_c * count
    end
  end

  c
end

def parse(bs)
  a = []
  bs.each_char do |c|
    if a.empty? || a.last == c
      a << c
      next
    end

    if a.last == '('
      a.slice!(a.size - 1)
    else
      a << c
    end
  end

  return '' if a.empty?
  return nil if a.first != a.last

  return [a.first, a.size]
end

puts count_seq

def left_stack(a)
  stack = []
  a.each_char do |c|
    if c == '('
      stack.push(c)
    else
      if stack.pop != '('
        return nil
      end
    end
  end
  stack
end

def right_stack(a)
  stack = []
  a.reverse.each_char do |c|
    if c == ')'
      stack.push(c)
    else
      if stack.pop != ')'
        return nil
      end
    end
  end
  return stack
end

def left_sign_stack(a)
  stack = left_stack(a)
  stack && stack.length
end

def right_sign_stack(a)
  stack = right_stack(a)
  stack && stack.length
end

left_count = Hash.new(0)
right_count = Hash.new(0)

n = gets.to_i
n.times do
  s = gets.chomp
  left_sign = left_sign_stack(s)
  right_sign = right_sign_stack(s)
  left_count[left_sign] += 1 if left_sign
  right_count[right_sign] += 1 if right_sign
end

res = 0
left_count.each do |sign, cnt1|
  res += cnt1 * right_count[sign]
end

puts res

n = gets.to_i
seqs = []
n.times do |i|
  seqs << gets.strip
end

hsh = {}

seqs.each do |seq|
  b = 0
  balanced = true
  seq.each_char do |c|
    if c == '('
      b += 1
    end
    if c == ')'
      b -= 1
    end
    balanced = false if b < 0
  end
  balanced = false if b > 0
  hsh[0] = (hsh[0] || 0) + 1 if balanced
  if b < 0
    hsh[b] = (hsh[b] || 0) + 1
  end
  if b > 0
    hsh[b] = (hsh[b] || 0) + 1
  end
end

ans = 0
ans += (hsh[0] * hsh[0]) if hsh[0]
pos_ub = hsh.keys.select{|x| x>0}
pos_ub.each do |pub|
  nub = -1 * pub
  ans += (hsh[pub] * (hsh[nub] || 0))
end
puts ans

# http://codeforces.com/problemset/problem/990/C

def count_seq
  n = gets.to_i
  h = {}
  regular = 0
  0.upto(n - 1) do |i|
    bs = gets.chomp
    ret = parse(bs)
    next if ret.nil?

    if ret == ''
      regular += 1
    elsif
      h[ret] ||= 0
      h[ret] += 1
    end
  end

  c = regular * regular
  # puts h.inspect

  h.each do |key, count|
    next if key[0] == ')'

    other_key = ['(', key[1]]
    other_c = h[other_key]
    if other_c
      c += other_c * count
    end
  end

  c
end

def parse(bs)
  a = []
  bs.each_char do |c|
    if a.empty? || a.last == c
      a << c
      next
    end

    if a.last == '('
      a.slice!(a.size - 1)
    else
      a << c
    end
  end

  return '' if a.empty?
  return nil if a.first != a.last

  return [a.first, a.size]
end

puts count_seq

# http://codeforces.com/problemset/problem/990/C

def count_seq
  n = gets.to_i
  h = {}
  regular = 0
  0.upto(n - 1) do |i|
    bs = gets.chomp
    ret = parse(bs)
    if ret.nil?
      regular += 1
    else
      h[ret] ||= 0
      h[ret] += 1
    end
  end

  c = regular * regular
  # puts h.inspect

  h.each do |key, count|
    next if key[0] == 'r'

    other_key = ['r', key[1]]
    other_c = h[other_key]
    if other_c
      c += other_c * count
    end
  end

  c
end

def parse(bs)
  l = 0
  r = 0
  bs.each_char do |c|
    (c == '(') ? (l += 1) : (r += 1)
  end

  return nil if l == r

  if l > r
    ['l', l - r]
  else
    ['r', r - l]
  end
end

puts count_seq


N, K = gets.split.map(&:to_i)
goal = gets.split.map(&:to_i)
road = gets.split.map(&:to_i)
road.concat(gets.split.map(&:to_i).reverse)
goal.concat(gets.split.map(&:to_i).reverse)

def index2road(i)
    i %= 2*N
    i < N ? [2, i+1] : [3, 2*N-i]
end
def index2goal(i)
    i %= 2*N
    i < N ? [1, i+1] : [4, 2*N-i]
end

goaled = []
ans = []
(2*N).times do |i|
    if goal[i] > 0 && goal[i] == road[i]
        num = goal[i]
        ans.push([num] + index2goal(i))
        goaled[num] = true
        road[i] = 0
    end
end

if road.count(0) == 0
    puts -1
    exit
end

while goaled.count{|v| v} < K
    index = road.index(0)
    (index+1).upto(index+2*N-1) do |i|
        i %= 2*N
        next if road[i] == 0
        ans.push([road[i]] + index2road(i-1))
        road[(i-1) % (2*N)] = road[i]
        road[i] = 0
    end
    (2*N).times do |i|
        if goal[i] > 0 && goal[i] == road[i]
            num = goal[i]
            ans.push([num] + index2goal(i))
            goaled[num] = true
            road[i] = 0
        end
    end
end

puts ans.length
ans.each do |arr|
    puts arr.join(' ')
end

n, k = gets.strip.split.map(&:to_i)
r1 = gets.strip.split.map(&:to_i)
r2 = gets.strip.split.map(&:to_i)
r3 = gets.strip.split.map(&:to_i)
r4 = gets.strip.split.map(&:to_i)

if 2*n == k
  match_found = false
  0.upto(n-1).each do |i|
    if r1[i] == r2[i]
      match_found = true
      break
    end
  end
  if !match_found
    0.upto(n-1).each do |i|
      if r3[i] == r4[i]
        match_found = true
        break
      end
    end
  end
  if !match_found
    puts -1
    exit
  end
end

seq = []
0.upto(n-1).each do |i|
  if r2[i]!=0 && r1[i] == r2[i]
    seq << [r2[i], 1, i+1]
    r2[i] = 0
  end
end
0.upto(n-1).each do |i|
  if r3[i]!=0 && r3[i] == r4[i]
    seq << [r3[i], 4, i+1]
    r3[i] = 0
  end
end

loop do
  if r2[n-1]!=0 && r2[n-1]==r1[n-1]
    seq << [r2[n-1], 1, n]
    r2[n-1] = 0
  end
  if r2[n-1]!=0 && r3[n-1]==0
    seq << [r2[n-1], 3, n]
    r3[n-1] = r2[n-1]
    r2[n-1] = 0
  end
  (n-2).downto(0).each do |i|
    if r2[i]!=0 && r2[i]==r1[i]
      seq << [r2[i], 1, i+1]
      r2[i] = 0
    end
    if r2[i]!=0 && r2[i+1]==0
      seq << [r2[i], 2, i+2]
      r2[i+1] = r2[i]
      r2[i] = 0
    end
  end
  if r3[0]!=0 && r3[0]==r4[0]
    seq << [r3[0], 4, 1]
    r3[0] = 0
  end
  if r3[0]!=0 && r2[0]==0
    seq << [r3[0], 2, 1]
    r2[0] = r3[0]
    r3[0] = 0
  end
  (1).upto(n-1).each do |i|
    if r3[i]!=0 && r3[i]==r4[i]
      seq << [r3[i], 4, i+1]
      r3[i] = 0
    end
    if r3[i]!=0 && r3[i-1]==0
      seq << [r3[i], 3, i]
      r3[i-1] = r3[i]
      r3[i] = 0
    end
  end
  break if r2.uniq == [0] && r3.uniq == [0]
end

puts seq.size
seq.each do |s|
  puts s.join(" ")
end


z,o = gets.split(" ").map(&:to_i)
if z >= o
	if o < z-1
		ans = "-1"
	else
		ans = "01" * (z-1)
		ans << "0"
		ans << "1" if z  == o
	end
else
	spaces = z + 1
	if o > (spaces * 2)
		ans = "-1"
	else
		pairs = o - spaces
		rem_ones = o - pairs * 2
		arr = ["11"] * pairs + ["1"] * rem_ones
		ans = arr.join("0")
	end
end

puts ans

#f = File.open('test1.txt', 'r')
f = STDIN

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

n, m = gets(f)
res =
    if m < n - 1
      -1
    elsif m <= (n + 1) * 2 #1010101010101010101
      remainder = m - (n - 1)
      s = '0'
      (n - 1).times do
        s << '1'
        if remainder > 0
          s << '1'
          remainder -= 1
        end
        s << '0'
      end
      if remainder > 0
        s.insert 0, ('1' * [remainder, 2].min)
        remainder -= [remainder, 2].min
      end
      if remainder > 0
        s.concat ('1' * remainder)
      end
      s
    else
      -1
    end
puts res

n, m = gets.split.map(&:to_i)
len = n + m
if n > m + 1
  p -1
  exit
end
if n == 0
  if m <= 2
    p "1" * m
  else
    p -1
  end
  exit
end
s = "01" * (n - 1) + "0"
m -= (n - 1)

k = [m, 2].min
m -= k
s = "1" * k + s
k = [m, 2].min
m -= k
s = s + "1" * k
if m > n - 1
  p -1
  exit
end
s = s[0, 2] + "011" * m + s[2 + 2 * m, s.length - (2 + 2 * m)] if m != 0
puts s

m,n = gets.chomp!.split.map { |e|  e.to_i}

if n+1 < m
    p -1
    exit
end

if (m+1)*2 < n
    p -1
    exit
end

if n == m
    n.times{printf "10" }
    puts ""

elsif m == n+1
    n.times{print "01"}
    puts 0
elsif (m+1)*2 == n
    m.times{printf "110"}
    puts "11"
elsif m*2 == n
    m.times{print "110"}
    puts ""
else
    k = n - 1 - m
    (k).times {print "110"}
    (m-k).times{print "10"}
    puts "1"
end

n, m = gets.split.collect{|i| i.to_i}
if m < n-1 or m > (n+1)*2
    puts -1
elsif m == n-1
    puts (['0']*n).join('1')
elsif m == n
    puts (['0']*n).join('1')+'1'
else
    cnt = m-n-1
    puts (['11']*cnt+['1']*(n+1-cnt)).join('0')
end

n, m = gets.split.collect{|i| i.to_i}
if m < n+1 or m > (n+1)*2
    puts -1
    exit
end
cnt = m-n-1
puts (['11']*cnt+['1']*(n+1-cnt)).join('0')


n = gets.chomp
array = Array.new(n.to_i) { |i| gets.chomp}

found = false
array.each do |i|
  if i[0] == 'O' && i[1] == 'O'
    i[0] = '+'
    i[1] = '+'
    found = true
    break
  elsif i[3] == 'O' && i[4] == 'O'
    i[3] = '+'
    i[4] = '+'
    found = true
    break
  end
end

if found == true
  puts 'YES'
  puts array
else
  puts 'NO'
end

n = gets.to_i
a = n.times.map{gets.chomp.chars}
ans = false
a.each do |x|
  if x[0] == 'O' && x[1] == 'O'
    x[0], x[1] = '+', '+'
    ans = true
    break
  elsif x[3] == 'O' && x[4] == 'O'
    x[3], x[4] = '+', '+'
    ans = true
    break
  end
end
puts ans ? 'YES' : 'NO'
puts a.map{|x| x.join('')} if ans

n = gets.to_i
f = false
a = Array.new(n, "")
n.times{|i|
    x, y = gets.chomp.split('|')
    if !f && x == "OO"
        f = true
        a[i] += "++"
    else
        a[i] += x
    end
    a[i] += "|"
    if !f && y == "OO"
        f = true
        a[i] += "++"
    else
        a[i] += y
    end
    }
if f
    puts "YES"
    puts a
else
    puts "NO"
end

n = gets.to_i
a = 1.upto(n).map { gets.chomp }

index = a.find_index { |s| s.include? 'OO' }

if index
  puts 'YES'
  a[index].sub!('OO', '++')

  puts a.join("\n")
else
  puts 'NO'
end

n=readline.to_i
result = []
found = false
(1..n).each do
	seats = readline.split('|').map{|x| x.strip}
	seats.each_index{ |x|
		if !found && seats[x]=='OO'
			seats[x]='++'
			found=true
		end
	}
	result << seats.join('|')
end
puts found ? 'YES' : 'NO'
puts result if found

n = gets.to_i

f =  false
out = []
n.times do
    s = gets.strip

    if !f && s["OO"]
        f = true
        s["OO"]="++"
    end

    out << s
end
if f
    puts "YES",out
else
    puts "NO"
end

n = gets.to_i

f =  false
out = []
n.times do
    l, r = gets.strip.split("|")

    if f == false && l == "OO"
        l = "++"
        f = true
    end

    if f == false && r == "OO"
        r = "++"
        f = true
    end

    out << l + "|" + r
end
if f
    puts "YES",out
else
    puts "NO"
end

n = gets.to_i

f =  false
out = []
n.times do
    s = gets.strip

    if !f && s.include?("OO")
        f = true
        s = s.sub("OO",'++')
    end

    out << s
end
if f
    puts "YES",out
else
    puts "NO"
end

n = gets.to_i

f =  false
out = []
n.times do
    s = gets.strip

    if !f && s.include?("OO")
        f = true
        s["OO"]="++"
    end

    out << s
end
if f
    puts "YES",out
else
    puts "NO"
end

#!/usr/bin/ruby
gets;a=$<.map(&:chomp)
if a.any?{|e|
	if e[0,2]=='OO'
		e[0,2]='++'
	elsif e[3,2]=='OO'
		e[3,2]='++'
	else
		false
	end
}
	puts :YES
	puts a
else
	puts :NO
end

n = gets.chomp.to_i

s = "".tap do |out|
  n.times { out << gets }
end

replaced = s.sub(/OO/, '++')
if s == replaced
  puts "NO"
else
  puts "YES"
  puts replaced
end

n = gets.to_i
ans = 'NO'
res = []
n.times do
  s1, s2 = gets.chomp.split("|")
  if s1 == "OO"
    s1 = "++" unless ans == 'YES'
    ans = 'YES'
  elsif s2 == "OO"
    s2 = "++" unless ans == 'YES'
    ans = 'YES'
  end
  res << [s1, s2].join("|")
end

if ans == 'YES'
  puts ans
  puts res
else
  puts ans
end

n = gets.strip.to_i
first = Array.new(n)
second = Array.new(n)
n.times do |i|
    first[i], second[i] = gets.strip.split("|")
end
found = false
n.times do |i|
    if first[i] == "OO"
        first[i] = "++"
        found = true
        break
    end
    if second[i] == "OO"
        second[i] = "++"
        found = true
        break
    end
end
if found
    puts "YES"
    n.times do |i|
        print first[i]
        print "|"
        print second[i]
        print "\n"
    end
else
    puts "NO"
end

n=gets.to_i
s=STDIN.read
if s.scan("OO").size>0 then
	s.sub!("OO","++")
	puts "YES",s
else
	puts "NO"
end

t = gets.chomp.to_i
change = true
arr = []
t.times.each do
  arr << gets.chomp
end
arr.each do |ts|
  if ts.include?('OO') and change
    ts.sub!('OO','++')
    change = false
  end
end

if change
  puts "NO"
else
  puts "YES"
  arr.each do |rr|
    puts rr
  end
end

n = gets.to_i
s = []
n.times do |i|
	s[i] = gets.chomp
end
x = false
for i in 0...n
	if x == false
		if s[i][0...2] == 'OO'
			s[i][0...2] = '++'
			x = true
		elsif s[i][3...5] == 'OO'
			s[i][3...5] = '++'
			x = true
		end

	end
end
if x == false
	puts 'NO'
else
	puts 'YES'
	0.upto(n-1) do |i|
		puts s[i]
	end
end

s = ''
(1..gets.chomp.to_i).each do
  s << gets.chomp << '#'
end
begin
  s[/OO/] = '++'
  puts 'YES'
  s.split('#').each { |q| puts q }
rescue
  puts 'NO'
end

def answer(a, b, lines)
  puts "YES"
  for i in 0..(lines.length-1) do
    if (i == a)
      if (b == 0)
        print "++|" + lines[i][1] + "\n"
      else
        print lines[i][0] + "|++\n"
      end
    else
      print lines[i][0] + "|" + lines[i][1] + "\n"
    end
  end
end

n = gets.strip.to_i
lines = []
n.times do
  input = gets.strip
  lines << [input[0..1], input[3..4]]
end
found = false
for i in 0..(lines.length-1) do
  if (lines[i][0] == "OO")
    answer(i, 0, lines)
    found = true
    break
  end
  if (lines[i][1] == "OO")
    answer(i, 1, lines)
    found = true
    break
  end
end
if not found
  puts "NO"
end

gets
s=$<.read
res=s.sub "OO", "++"
if res!=s
    puts "YES"
    puts res
else
    puts "NO"
end

# coding: utf-8

# if __FILE__ == $0
# end

n = gets.to_i
rows = []
n.times {
    rows << gets.chomp.split("|")
}
found = false
for i in 0...n
    if rows[i][0] == "OO"
        found = true
        rows[i][0] = "++"
        break
    end

    if rows[i][1] == "OO"
        found = true
        rows[i][1] = "++"
        break
    end
end

if found
    puts "YES"
    for row in rows
        puts row.join("|")
    end
else
    puts "NO"
end

n = Integer(gets.chomp)
bus = Array.new(n)
for i in 0...n
    bus[i] = gets.chomp.split("")
end

can_seat_together = false

for i in 0...n
    if bus[i][0] == "O" && bus[i][1] == "O"
        can_seat_together = true
        bus[i][0] = "+"
        bus[i][1] = "+"
        break
    elsif bus[i][3] == "O" && bus[i][4] == "O"
        can_seat_together = true
        bus[i][3] = "+"
        bus[i][4] = "+"
        break
    end
end

if can_seat_together
    puts " YES"
    for i in 0...n
        print bus[i].join
        puts
    end
else
    puts "NO"
end

rows = gets.chomp.to_i
seats = []
for i in (0..rows-1)
	seats[i] = gets.chomp
end

has_seat = -1
for i in (0..rows-1)
	split = seats[i].split("")
	for x in (0..split.size-1)
		if split[x] == "O" && split[x+1] == "O"
			split[x] = "+"
			split[x+1] = "+"
			puts "YES"
			new_seats = []
			for a in (0..4)
				new_seats << split[a]
			end
			has_seat = i
			break
		end
	end
	if has_seat != -1
		break
	end
end

if has_seat != -1
	for i in (0..has_seat)
		if i < has_seat
			puts seats[i]
		else
			for x in (0..4)
				if x == 4
					puts new_seats[x]
				else
					print new_seats[x]
				end
			end
		end
	end
	for i in (has_seat+1..rows-1)
		puts seats[i]
	end
else
	puts "NO"
end

require 'pp'
rows = gets.chomp.to_i
row = []
fact = "NO"
rows.times do |i|

  row << gets.chomp.to_s
  values = row[-1].split('|')
  if values.include?("OO") && fact == "NO"
  	fact = "YES"
  	row[-1].sub!("OO", "++")
  end
 end
 puts fact
 puts row if fact == "YES"

d = gets.to_i.times.map{|x| gets.strip.split("|")}
ans = false
list = []
d.each do |x|
    if ans == false && x.include?("OO")
        if x[0] == "OO"
            list.push(['++', x[1]])
        else
            list.push([x[0],'++'])
        end
        ans = true
    else
        list.push(x)
    end
end
puts (ans)? 'YES' : 'NO'
if ans
    list.each{|x| puts x.join('|')}
end

n = gets.to_i

f =  false
out = []
n.times do
    s = gets.strip

    if s.include?("OO")
        f = true
        s = s.sub("OO",'++')
    end

    out << s
end
if f
    puts "YES",out
else
    puts "NO"
end

n = gets.to_i
s = []
n.times do |i|
	s[i] = gets.chomp
end
x = false
for i in 0...5
	if x == false
		if s[i][0...2] == 'OO'
			s[i][0...2] = '++'
			x = true
		elsif s[i][3...5] == 'OO'
			s[i][3...5] = '++'
			x = true
		end

	end
end
if x == false
	puts 'NO'
else
	puts 'YES'
	0.upto(4) do |i|
		puts s[i]
	end
end

s = ''
(1..gets.chomp.to_i).each do
  s << gets.chomp << '#'
end
begin
  s[/OO/] = '++'
  s.split('#').each { |q| puts q }
rescue
  puts 'NO'
end

d = gets.to_i.times.map{|x| gets.strip.split("|")}
ans = false
list = []
d.each do |x|
    if ans == false && x.include?("OO")
        if x[0] == "00"
            list.push(['++', x[1]])
        else
            list.push([x[0],'++'])
        end
        ans = true
    else
        list.push(x)
    end
end
puts (ans)? 'YES' : 'NO'
list.each{|x| puts x.join('|')}

d = gets.to_i.times.map{|x| gets.strip.split("|")}
ans = false
list = []
d.each do |x|
    if ans == false && x.include?("OO")
        if x[0] == "OO"
            list.push(['++', x[1]])
        else
            list.push([x[0],'++'])
        end
        ans = true
    else
        list.push(x)
    end
end
puts (ans)? 'YES' : 'NO'
list.each{|x| puts x.join('|')}

n = gets.to_i
a = n.times.map{gets.chomp.chars}
ans = false
a.each do |x|
  if x[0] == 'O' && x[1] == 'O'
    x[0], x[1] = '-', '-'
    ans = true
    break
  elsif x[3] == 'O' && x[4] == 'O'
    x[3], x[4] = '-', '-'
    ans = true
    break
  end
end
puts ans ? 'YES' : 'NO'
puts a.map{|x| x.join('')} if ans

n = gets.to_i
a = n.times.map{gets.chomp.chars}
ans = false
a.each do |x|
  if x[0] == 'O' && x[1] == 'O'
    x[0], x[1] = '-', '-'
    ans = true
    break
  elsif x[3] == 'O' && x[4] == 'O'
    x[3], x[4] = '+', '+'
    ans = true
    break
  end
end
puts ans ? 'YES' : 'NO'
puts a.map{|x| x.join('')} if ans


n=gets.to_i
a=gets.split.map(&:to_i).sort
p a[~-n/2]

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

puts arr.size.even? ? arr[n/2 - 1] : arr[n/2]

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

puts arr.size.even? ? arr[n/2 - 1] : arr[n/2]


test_cases = gets.chomp.to_i
for i in 1..test_cases do
    line = gets.chomp.split(" ")
    n = line[0].to_i
    k = line[1].to_i
    if k <= (n - 1) / 2
        a = Array.new(n, -1)
        for j in 1..k do
            a[2 * j - 1] = n + 1 - j
        end
        x = k + 1
        for j in 0..n - 1 do
            if a[j] == -1
                a[j] = n + 1 - x
                x += 1
            end
        end
        for j in 0..n - 1 do
            print "#{a[j]} "
        end
        puts ""
    else
        puts -1
    end
end

t = gets.to_s.to_i

1.upto(t) do |casenum|
  n, k = gets.to_s.split.map {|x| x.to_i }
  a = (1 .. n).to_a
  swap_pos = a.size - 1
  while k > 0 && swap_pos > 1
    a[swap_pos], a[swap_pos - 1] = a[swap_pos - 1], a[swap_pos]
    k -= 1
    swap_pos -= 2
  end

  if k > 0
    printf("-1\n")
  else
    printf("%s\n", a.join(" "))
  end
end

def array_peaks(n, k)
  # n is size of output array
  # k is number of peaks required

  # if even max possible peaks is (n - 2) / 2
  # if odd max possible peaks is (n - 1) / 2
  if (n % 2) == 0
    if k > (n-2)/2
      puts -1
      return
    end
  else
    if k > (n-1)/2
      puts -1
      return
    end
  end

  a = (1..n).to_a
  o = []
  peaks = 0
  asc = true

  while(a.size > 0) do
    if peaks < k
      if asc
        o << a.shift
        asc = false
      else
        o << a.pop
        asc = true
        peaks += 1
      end
    else
      o << a.pop
    end
  end

  puts o.join(" ")
end

num_input = gets.chomp
num_input.to_i.times do
  args = gets.chomp.split(' ').map(&:to_i)
  array_peaks(*args)
end


a=gets.chomp.to_i
b=gets.chomp.split(" ")
if a==1
puts "0"
else
max=b[0].to_i
min=b[0].to_i
amz=0
1.upto(a-1) do |i|
if b[i].to_i>max
max=b[i].to_i
amz+=1
elsif b[i].to_i<min
min=b[i].to_i
amz+=1
end
end
puts "#{amz}"
end

gets
l = gets.split.map(&:to_i)
c = 0
l.each_with_index { |x, i| c += 1 if i != 0 and (l[0...i].all? { |y| y > x } or l[0...i].all? { |y| y < x }) }
puts c

n = gets.to_i
m = gets.split.collect &:to_i

min_rec = m[0]
max_rec = m[0]
asr = 0
i = 0

while i < n do
  if (min_rec > m[i])
    begin
      min_rec = m[i]
      asr += 1
    end
  end
  if (max_rec < m[i])
    begin
      max_rec = m[i]
      asr += 1
    end
  end
  i += 1
end
puts asr

n = gets.to_i
scs = gets.split.map {|s| s.to_i}
min = scs[0]
max = scs[0]
count = 0
for s in scs
  if(s < min)
  	min = s
  	count += 1
  elsif (s > max)
  	max = s
  	count += 1
  end
end
puts count

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

x = a.shift
result = a.inject({min: x, max: x, result: 0}) do |hash, i|
  r = hash[:result] + ((i<hash[:min] || i>hash[:max]) ? 1 : 0)
  { min: [hash[:min], i].min, max: [hash[:max], i].max, result: r }
end

puts result[:result]

gets

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

min = max = scores[0]

amazing = 0

scores.each do |score|
  if score < min
    min = score
    amazing += 1
  elsif score > max
    max = score
    amazing += 1
  end
end

puts amazing

gets
while 1 do
    gets and $a = $_.chomp.split(" ")
    $_ and $max = $min = $a.shift.to_i
    $_ and $sum = 0
    $a.empty? and break
    $p = $a.shift.to_i
    $p > $max and $max = $p and $sum+=1
    $p < $min and $min = $p and $sum+=1
end
puts $sum

n=gets.to_i
a=0
b=gets.split.map(&:to_i)
min=max=b.first
b.each{|c|
	if c>max
		a+=1
		max=c
	end
	if c<min
		a+=1
		min=c
	end
}
p a

gets; input = gets.strip.split.map &:to_i
min, max, c = input[0], input[0], 0

input.each do |i|
  (min = i; c += 1) if min > i
  (max = i; c += 1) if max < i
end

print c

#!ruby

n = gets.to_i

a = gets.split.map{|e|e.to_i}

max = min = a.shift

count = 0

a.each do |e|
  if e < min
    count += 1
    min = e
  elsif e > max
    count += 1
    max = e
  end
end

puts count

n = gets.to_i
ar = gets.split(' ',n).map(&:to_i)
min, max, record = ar[0], ar[0], 0
ar[1..-1].each do |x|
  record += 1 if x<min
  record += 1 if x>max
  min, max = [min, max, x].minmax
end
puts record

n = gets.to_i
a = gets.split.map &:to_i
ans = -2
mx = -1e50
mi = -mx
a.each do |x|
  if x > mx
    mx = x
    ans += 1
  end
  if x < mi
    mi = x
    ans += 1
  end
end
p ans

n = gets.to_i

res = gets.split.map{|i| i.to_i}

max = res[0]
min = res[0]
result = 0
i = 1
while i < res.size do
    if res[i] > max then
        max = res[i]
        result += 1
    else
        if res[i] < min then
            min = res[i]
            result += 1
        end
    end
    i += 1
end

puts result

gets
a = []
gets.split.map(&:to_i).each do |b|
    a << b if a.empty? || b < a.min || b > a.max
end
p a.size - 1

n=gets.to_i
a=gets.split.map(&:to_i)
arr=[a[0]]
ans=0
1.upto(a.length-1){|i|
        ans+=1 if arr.min>a[i]||arr.max<a[i]
        arr.push(a[i])
}
p ans

n = gets.to_i
a = gets.split(" ").map(&:to_i)
min = a[0]
max = a[0]
cnt = 0
for i in 1...a.size
  if min > a[i]
    cnt += 1
    min = a[i]
  end
  if max < a[i]
    cnt += 1
    max = a[i]
  end
end
puts cnt

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

past = []
past << points[0]
c = 0
(1..n-1).each do |i|
  if points[i] > past.max
    c += 1
  elsif points[i] < past.min
    c += 1
  end
  past << points[i]
end

puts c

def count(a)
  tot_amazing = 0
  # The first content is the max and the min number of points
  min = a.shift
  max = min
  a.each do |p|
    if p < min
      min = p
      tot_amazing += 1
    elsif p > max
      max = p
      tot_amazing += 1
    end
  end
  tot_amazing
end

n = gets.to_i
a = gets.split(/\s/).map(&:to_i)

puts count(a)

n = STDIN.readline.to_i
scores = STDIN.readline.split.map {|s| s.to_i }
min, max = scores[0], scores[0]
count = 0
scores[1..-1].each do |score|
  if score < min
    count += 1
    min = score
  end
  if score > max
    count += 1
    max = score
  end
end
puts count

def i_arr(arr)
	for i in 0...arr.length
		arr[i] = arr[i].to_i
	end
	return arr
end

n = gets.to_i
arr = i_arr(gets.chomp.split)
min = arr[0]
max = arr[0]
t = 0

for i in 1...n
	a = arr[i]
	if a > max
		max = a
		t += 1
	elsif a < min
		min = a
		t += 1
	end
end

puts t

n = STDIN.gets.chomp.to_i
scores = STDIN.gets.chomp.split(/ /).take(n).map(&:to_i)

amazings = 0
min = 100000
max = -1
scores.each_with_index do |score, i|
  if score < min
    min = score
    amazings += 1 unless i == 0
  end
  if score > max
    max = score
    amazings += 1 unless i == 0
  end
end
p amazings

n=gets.chomp.to_i
a=gets.chomp.split(' ').map(&:to_i)
b=[a[0]]
i=1
count=0
while i<a.length
	if a[i]<b.min || a[i]>b.max
		#puts "YAY!"
		count+=1
	end
	b.push(a[i])
	i+=1
end
puts count

n = gets.to_i
a = gets.strip.split.map(&:to_i)
max = a[0]
min = a[0]
k = 0
(1...n).each do |i|
  if a[i] > max
    k+=1
    max = a[i]
  end
  if a[i] < min
    k+=1
    min = a[i]
  end
end
puts k

l = STDIN.read.split("\n")
n  = l[0].to_i
marks = l[1].split(" ").map(&:to_i)
n_i = 0
min = max = marks[0]

for i in 1..(n-1)
  if (min > marks[i])
  	n_i += 1
  	min = marks[i]
  elsif (max < marks[i])
  	n_i+= 1
  	max = marks[i]
  end
end

puts n_i

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

max = a[0]
min = a[0]
k = 0

a.each do |x|
  if x > max
    k+=1
    max = x
  end

  if x < min
    k+=1
    min = x
  end
end

puts k

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

  counter = 0
  min,max = a[0],a[0]
  for i in 1..n-1
    if a[i]>max
      max = a[i]
      counter+=1
    elsif a[i] < min
      min = a[i]
      counter+=1
    end
  end
  puts counter

def Floodico(n,a)

  counter = 0
  min,max = a[0],a[0]
  for i in 1..n-1
    if a[i]>max
      max = a[i]
      counter+=1
    elsif a[i] < min
      min = a[i]
      counter+=1
    end
  end
  puts counter

end
Floodico(gets.to_i,gets.split.map(&:to_i))

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

max_count = 0
min_count = 0
max = f.first
min = f.first

for i in 1...f.count
    elem = f[i]
    if elem > max
        max_count+=1
        max = elem
    end
    if elem < min
        min_count+=1
        min = elem
    end
end

puts min_count + max_count

#!/usr/bin/ruby
def read_int; gets.chomp.to_i; end
def read_ints; gets.chomp.split.map(&:to_i); end

n = read_int
arr = read_ints

first = arr.shift
min = first
max = first
count = 0
arr.each do |i|
  if i < min
    min = i
    count += 1
  elsif i > max
    max = i
    count += 1
  end
end

puts count

gets
arr = gets.split.map &:to_i
max, min = arr.first, arr.first
k = 0
arr.shift
arr.each do |p|
  if p > max
    max = p
    k += 1
  elsif p < min
    min = p
    k += 1
  end
end
puts k

n = gets.chomp.to_i
arr = gets.split.map(&:to_i)
big = arr[0]
small = arr[0]
arr.shift
res = 0
arr.each do |num|
  if num > big
    big = num
    res+=1
  elsif num < small
    small = num
    res+=1
  end
end
puts res

n = gets.to_i
as = gets.split.map(&:to_i)

lowest = as[0]
highest = as[0]

ans = 0
(1..n-1).each do |i|
  if as[i] < lowest
    ans += 1
    lowest = as[i]
  elsif as[i] > highest
    ans += 1
    highest = as[i]
  end
end

puts ans

n = gets.strip.to_i
scores = gets.strip.split.map(&:to_i)
min_score = max_score = scores[0]
ans = 0
(1...n).each do |i|
    if scores[i] < min_score
        min_score = scores[i]
        ans += 1
    end
    if scores[i] > max_score
        max_score = scores[i]
        ans += 1
    end
end
puts ans

gets
x=gets.split.map{|e| e.to_i}
ans=0
min1=x[0]
max1=x[0]
x.shift
while !x.empty?
	t=x[0]
	if min1>t then
		min1=t
		ans=ans+1
	end
	if max1<t then
		max1=t
		ans=ans+1
	end
	x.shift
end
puts ans

a=gets.chomp.to_i
b=gets.chomp.split(' ')
b.length.times {|x| b[x]=b[x].to_i}
c=0;min=0;max=0
b.length.times { |x|
  c+=1 if x!=0&&(b[x]>max||b[x]<min)
  min=b[x] if b[x]<min
  max=b[x] if b[x]>max
  if x==0
    min=b[x];max=b[x]
  end
}
puts c

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

m = a[0]
pr = a[0]
c = 0

a.each do |e|
  if e > pr
    c += 1
    pr = e
  elsif e < m
    c += 1
    m = e
  end
end

p c

n = gets.to_i
a = gets.split.map(&:to_i)
m,l,c = a[0],a[0],0
for i in a
	if i > m
		c += 1
		m = i
	elsif i < l
		c += 1
		l = i
	end
end
puts c

ans=0
n=gets.to_i
a=gets.split.collect {|i|i.to_i}
min=max=a[0]
1.upto(n-1){|i|
	if (a[i] > max) then
		max=a[i]
		ans+=1
	elsif (a[i] < min) then
		min=a[i]
		ans+=1
	end}
p ans

n = gets.to_i
q = gets.chomp.split.map { |x| x.to_i }

min = q[0]
max = q[0]
wow = 0

for i in 1...n
  if q[i] > max
    max = q[i]
    wow +=1
  elsif q[i] < min
    min = q[i]
    wow +=1
  end
end
p wow

n = gets.to_i

a = gets.split.map(&:to_i)
b=[a[0]]
ans = a[1...a.size].count do |x|
  ret = (x > b.max or x < b.min)
  b << x
  ret
end

puts ans

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

count = gets.chomp.to_i
scores = gets.chomp.split.map { |e| e.to_i }

tmp_scores = []
first = true

amazing = 0

scores.each do |score|
  if first
    first = false
    tmp_scores << score
  else
    if score > tmp_scores.max or score < tmp_scores.min
      amazing += 1
      tmp_scores << score
    end
  end
end

puts "#{amazing}"

n = gets.to_i
a = gets.split(' ').map(&:to_i)
max, min = a[0], a[0]
k = 0
for i in 1...n
  if a[i] > max
    k += 1
    max = a[i]
  end
  if a[i] < min
    k += 1
    min = a[i]
  end
end
puts k

number = gets.chomp.to_i
n = gets.chomp
contests = n.split

maxm = contests[0].to_i
minm = contests[0].to_i
count = 0
for i in (1..number-1) # i = subject
	x = i
	while x != 0 # x = compare to
		if contests[i].to_i > maxm
			maxm = contests[i].to_i
			count += 1
		elsif contests[i].to_i < minm
			minm = contests[i].to_i
			count += 1
		end
		x -= 1
	end
end

print count

contests = gets.to_i
points = gets.chomp.split(' ').map { |e| e.to_i }
amazing, max, min = 0, points[0], points[0]
(0...contests).each do |i|
  if points[i] > max
    amazing += 1
    max = points[i]
  end
  if points[i] < min
    amazing += 1
    min = points[i]
  end
end
puts amazing

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

past = []
past << points[0]
c = 0
(1..n-1).each do |i|
  if points[i] > past.max
    c += 1
  elsif points[i] < past.min
    c += 1
  end
end

puts c

def Floodico(n,a)

  counter = 0
  min,max = a[0],a[0]
  for i in 1..n-1
    if a[i]>max
      max = a[i]
      counter+=1
    elsif a[i] < min
      min = a[i]
      counter+=1
    end
  end
  return counter

end
Floodico(gets.to_i,gets.split.map(&:to_i))

gets
x=gets.split.map{|e| e.to_i}
ans=0
s=x[0]
x.shift
while !x.empty?
	ans=ans+1 if x[0]>s
	s=x[0]
	x.shift
end
puts ans

a=gets.chomp.to_i
b=gets.chomp.split(' ')
b.length.times {|x| b[x]=b[x].to_i}
c=0;min=0;max=0
b.length.times { |x|
  c+=1 if x!=0&&(b[x]>max||b[x]<min)
  min=b[x];max=b[x] if x==0
}
puts c

n = gets.to_i
m = gets.split.collect &:to_i

min_rec = m[0]
max_rec = m[0]
asr = 0
i = 0
if(n == 1)
  puts 1
else
  while i < n do
    if (min_rec > m[i])
      begin
        min_rec = m[i]
        asr += 1
      end
    end
    if (max_rec < m[i])
      begin
        max_rec = m[i]
        asr += 1
      end
    end
    i += 1
  end
  puts asr
end


# Here your code !

N, P_ = gets.split.map(&:to_i)
P__ = P_-1
str = gets.chomp
if P__>= N/2
    str.reverse!
    P = N - (P__+1)
else
    P = P__
end

def orddiff(c1, c2)
    if(c1.ord > c2.ord)
        c1, c2 = c2, c1
    end
    d = c2.ord - c1.ord
    if d>13
        d = 26 - d
    end
    return d
end

count = 0
rightmax = 0
(P...N/2).each{|p|
    if str[p] != str[N-p-1] then
        rightmax = p - P
        count += orddiff(str[p], str[N-p-1])
    end
}
leftmax = 0
(P-1).downto(0).each{|p|
    if str[p] != str[N-p-1] then
        leftmax = P-p
        count += orddiff(str[p], str[N-p-1])
    end
}
# puts "P=#{P} leftmax=#{leftmax}, rightmax=#{rightmax}, count=#{count}"

if leftmax == 0
    count += rightmax
elsif rightmax == 0
    count += leftmax
elsif leftmax < rightmax
    count += leftmax*2 + rightmax
else
    count += rightmax*2 + leftmax
end
puts count

cost = {}
('a'..'z').each {|x| cost[x] = {} }
('a'..'z').each do |x|
	diff = -1
	(x..'z').each do |y|
		diff += 1
		cost[x][y] = cost[y][x] = [diff, 26-diff].min
	end
end

n, p = STDIN.readline.split.map {|s| s.to_i }
s = ' '+STDIN.readline.strip
center = (n+1)/2
if p > center
	p = n-p+1
end
q = n-p+1

left_correction, left_span = 0, 0
(p-1).downto(1) do |i|
	a, b = s[i], s[n-i+1]
	if a != b
		left_correction += cost[a][b]
		left_span = p-i
	end
end
right_correction, right_span = 0, 0
(p+1).upto(center) do |i|
	a, b = s[i], s[n-i+1]
	if a != b
		right_correction += cost[a][b]
		right_span = i-p
	end
end

total = cost[s[p]][s[q]]
#puts 'total so far = %d' % total
#puts 'left_correction = %d, left_span = %d' % [left_correction, left_span]
#puts 'right_correction = %d, right_span = %d' % [right_correction, right_span]
total += left_correction + right_correction
total += left_span + right_span
total += [left_span, right_span].min
puts total

n,pos = gets.split(" ").map(&:to_i)
arr = gets.chomp
mid = (n+1) / 2
unless pos <= mid
	pos = n - pos + 1
	arr.reverse!
end
c = 0
last_ind = pos - 1
((pos - 1)...mid).each do |i|
	if arr[i] != arr[n - i - 1]
		a = arr[i].ord
		b = arr[n - i - 1].ord
		val = []
		if a < b
			val << b - a
			val << a - b + 26
		else
			val << a - b
			val << b - a + 26
		end
		c += val.min
		last_ind = i
	end
end

first_ind = nil
(0...(pos-1)).each do |i|
	if arr[i] != arr[n - i - 1]
		a = arr[i].ord
		b = arr[n - i - 1].ord
		val = []
		if a < b
			val << b - a
			val << a - b + 26
		else
			val << a - b
			val << b - a + 26
		end
		c += val.min
		first_ind = i unless first_ind
	end
end
# puts "#{first_ind} #{pos-1} #{last_ind} #{c}"
unless first_ind
	c += last_ind - (pos - 1)
else
	first_dist = pos - 1 - first_ind
	last_dist = last_ind - (pos - 1)
	c += first_dist + last_dist
	c += [first_dist,last_dist].min
end

puts c

# Author : Fuad Ashraful Mehmet
#Date: 18th April

n,pos = gets.split(" ").map(&:to_i)
arr = gets.chomp
mid = (n+1) / 2
unless pos <= mid
	pos = n - pos + 1
	arr.reverse!
end
c = 0
last_ind = pos - 1
((pos - 1)...mid).each do |i|
	if arr[i] != arr[n - i - 1]
		a = arr[i].ord
		b = arr[n - i - 1].ord
		val = []
		if a < b
			val << b - a
			val << a - b + 26
		else
			val << a - b
			val << b - a + 26
		end
		c += val.min
		last_ind = i
	end
end

first_ind = nil
(0...(pos-1)).each do |i|
	if arr[i] != arr[n - i - 1]
		a = arr[i].ord
		b = arr[n - i - 1].ord
		val = []
		if a < b
			val << b - a
			val << a - b + 26
		else
			val << a - b
			val << b - a + 26
		end
		c += val.min
		first_ind = i unless first_ind
	end
end

unless first_ind
	c += last_ind - (pos - 1)
else
	first_dist = pos - 1 - first_ind
	last_dist = last_ind - (pos - 1)
	c += first_dist + last_dist
	c += [first_dist,last_dist].min
end

puts c

# Here your code !

N, P_ = gets.split.map(&:to_i)
P = P_-1
str = gets.chomp
if P>= N/2
    str.reverse!
    P = N - (P+1)
end

count = 0
rightmax = 0
(P...N/2).each{|p|
    if str[p] != str[N-p-1] then
        rightmax = p - P
        count +=1
    end
}
leftmax = 0
(P-1).downto(0).each{|p|
    if str[p] != str[N-p-1] then
        leftmax = P-p
        count +=1
    end
}
# puts "P=#{P} leftmax=#{leftmax}, rightmax=#{rightmax}, count=#{count}"

if leftmax < rightmax
    count += leftmax*2 + rightmax
else
    count += rightmax*2 + leftmax
end
puts count

# Here your code !

N, P_ = gets.split.map(&:to_i)
P__ = P_-1
str = gets.chomp
if P__>= N/2
    str.reverse!
    P = N - (P__+1)
else
    P = P__
end

count = 0
rightmax = 0
(P...N/2).each{|p|
    if str[p] != str[N-p-1] then
        rightmax = p - P
        count +=1
    end
}
leftmax = 0
(P-1).downto(0).each{|p|
    if str[p] != str[N-p-1] then
        leftmax = P-p
        count +=1
    end
}
# puts "P=#{P} leftmax=#{leftmax}, rightmax=#{rightmax}, count=#{count}"

if leftmax == 0
    count += rightmax
elsif rightmax == 0
    count += leftmax
elsif leftmax < rightmax
    count += leftmax*2 + rightmax
else
    count += rightmax*2 + leftmax
end
puts count

# Here your code !

N, P_ = gets.split.map(&:to_i)
P__ = P_-1
str = gets.chomp
if P__>= N/2
    str.reverse!
    P = N - (P__+1)
else
    P = P__
end

count = 0
rightmax = 0
(P...N/2).each{|p|
    if str[p] != str[N-p-1] then
        rightmax = p - P
        count +=1
    end
}
leftmax = 0
(P-1).downto(0).each{|p|
    if str[p] != str[N-p-1] then
        leftmax = P-p
        count +=1
    end
}
# puts "P=#{P} leftmax=#{leftmax}, rightmax=#{rightmax}, count=#{count}"

if leftmax < rightmax
    count += leftmax*2 + rightmax
else
    count += rightmax*2 + leftmax
end
puts count

n,pos = gets.split(" ").map(&:to_i)
arr = gets.chomp
mid = (n+1) / 2
unless pos <= mid
	pos = n - pos + 1
	arr.reverse!
end
c = 0
last_ind = pos - 1
((pos - 1)...mid).each do |i|
	if arr[i] != arr[n - i - 1]
		a = arr[i].ord
		b = arr[n - i - 1].ord
		val = []
		if a < b
			val << b - a
			val << a - b + 26
		else
			val << a - b
			val << b - a + 26
		end
		c += val.min
		last_ind = i
	end
end

first_ind = nil
(0...(pos-1)).each do |i|
	if arr[i] != arr[n - i - 1]
		a = arr[i].ord
		b = arr[n - i - 1].ord
		val = []
		if a < b
			val << b - a
			val << a - b + 26
		else
			val << a - b
			val << b - a + 26
		end
		c += val.min
		first_ind = i unless first_ind
	end
end
puts "#{first_ind} #{pos-1} #{last_ind} #{c}"
unless first_ind
	c += last_ind - (pos - 1)
else
	first_dist = pos - 1 - first_ind
	last_dist = last_ind - (pos - 1)
	c += first_dist + last_dist
	c += [first_dist,last_dist].min
end

puts c

n,pos = gets.split(" ").map(&:to_i)
arr = gets.chomp
mid = (n+1) / 2
unless pos <= mid
	pos = n - pos + 1
	arr.reverse!
end
c = 0
last_ind = pos
((pos - 1)...mid).each do |i|
	if arr[i] != arr[n - i - 1]
		a = arr[i].ord
		b = arr[n - i - 1].ord
		val = []
		if a < b
			val << b - a
			val << a - b + 26
		else
			val << a - b
			val << b - a + 26
		end
		c += val.min
		last_ind = i
	end
end

first_ind = nil
(0...(pos-1)).each do |i|
	if arr[i] != arr[n - i - 1]
		a = arr[i].ord
		b = arr[n - i - 1].ord
		val = []
		if a < b
			val << b - a
			val << a - b + 26
		else
			val << a - b
			val << b - a + 26
		end
		c += val.min
		first_ind = i unless first_ind
	end
end
# puts "#{first_ind} #{pos} #{last_ind} #{c}"
unless first_ind
	c += last_ind - pos - 1
else
	first_dist = pos - 1 - first_ind
	last_dist = last_ind - (pos - 1)
	c += first_dist + last_dist
	c += [first_dist,last_dist].min
end

puts c


n = gets.to_i
light = gets.chomp
param = []
rest = []
n.times do |i|
  param << gets.split.map(&:to_i)
  rest[i] = param[i][1]
end

ans = light.count("1")
200.times do |i|
  n.times do |i|
    rest[i] -= 1
    if rest[i] == 0
      rest[i] = param[i][0]
      light[i] = light[i] == "1" ? "0" : "1"
    end
  end
  cnt = light.count("1")
  ans = cnt if cnt > ans
end
p ans

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

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

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

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

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

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

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

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

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

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

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

require 'prime'

n = inp[0]
m = gets.chomp.split("")
t = []
n.times do
  t << inp
end
m.size.times do |i|
  if(m[i] == "1")
    m[i] = true
  else
    m[i] = false
  end
end
ans = m.count(true)
(0..1000).each do |turn|
  t.size().times do |i|
    t[i][1] -= 1
    if(t[i][1] == 0)
      t[i][1] += t[i][0]
      m[i] = !m[i]
    end
  end
  ans = [ans,m.count(true)].max
end
p ans

n = gets.to_i
lights = gets.chomp.each_char.map(&:to_i)
a = []
b = []
for i in 0...n do
  a[i], b[i] = gets.split.map(&:to_i)
end

ons = 0
lights.each do |x|
  ons += x
end

max_ons = ons
for t in 1..125 do
  for i in 0...n do
    if t >= b[i] && (t - b[i]) % a[i] == 0
      if lights[i] == 0
        lights[i] = 1
        ons += 1
      else
        lights[i] = 0
        ons -= 1
      end
    end
  end
  max_ons = ons if max_ons < ons
end
puts max_ons

n = gets.to_i
lights = gets.chomp.each_char.map(&:to_i)
a = []
b = []
for i in 0...n do
  a[i], b[i] = gets.split.map(&:to_i)
end

ons = 0
lights.each do |x|
  ons += x
end

max_ons = ons
for t in 1..125 do
  for i in 0...n do
    if t >= b[i] && (t - b[i]) % a[i] == 0
      if lights[i] == 0
        lights[i] = 1
        ons += 1
      else
        lights[i] = 0
        ons -= 1
      end
    end
  end
  p ons
  max_ons = ons if max_ons < ons
end
puts max_ons

n = gets.to_i
lights = gets.chomp.each_char.map(&:to_i)
a = []
b = []
for i in 0...n do
  a[i], b[i] = gets.split.map(&:to_i)
end

ons = 0
lights.each do |x|
  ons += x
end

max_ons = ons
for t in 1..120 do
  for i in 0...n do
    if (t - b[i]) % a[i] == 0
      if lights[i] == 0
        lights[i] = 1
        ons += 1
      else
        lights[i] = 0
        ons -= 1
      end
    end
  end
  max_ons = ons if max_ons < ons
end
puts max_ons

n = gets.to_i
lights = gets.chomp.each_char.map(&:to_i)
a = []
b = []
for i in 0...n do
  a[i], b[i] = gets.split.map(&:to_i)
end

ons = 0
lights.each do |x|
  ons += x
end

max_ons = ons
for t in 1..(5 + 3 * 4 * 5) do
  for i in 0...n do
    if (t - b[i]) % a[i] == 0
      if lights[i] == 0
        lights[i] = 1
        ons += 1
      else
        lights[i] = 0
        ons -= 1
      end
    end
  end
  max_ons = ons if max_ons < ons
end
puts max_ons

n = gets.to_i
lights = gets.chomp.each_char.map(&:to_i)
a = []
b = []
for i in 0...n do
  a[i], b[i] = gets.split.map(&:to_i)
end

ons = 0
lights.each do |x|
  ons += x
end

max_ons = ons
for t in 1..120 do
  for i in 0...n do
    if t >= b[i] && (t - b[i]) % a[i] == 0
      if lights[i] == 0
        lights[i] = 1
        ons += 1
      else
        lights[i] = 0
        ons -= 1
      end
    end
  end
  max_ons = ons if max_ons < ons
end
puts max_ons


#!/usr/bin/ruby
require 'prime'
STDOUT.sync=true
M=100
r=0
Prime.each(M/2){|e|
	p e
	if gets.chomp=='yes'
		r+=1
		if e*e<=M
			p e*e
			r+=1 if gets.chomp=='yes'
		end
	end
}
puts r>1 ? :composite : :prime

require 'prime'

ns = (2..100).to_a
ms = [4, 9, 25, 49]
(2..50).each do |m|
  ms << m if m.prime?
end

ms.each do |m|
  puts m
  STDOUT.flush
  s = gets.chomp
  if s == 'yes'
    ns.delete_if { |n| n % m != 0 }
  else
    ns.delete_if { |n| n % m == 0 }
  end
end
if ns[0].prime?
  puts 'prime'
else
  puts 'composite'
end
STDOUT.flush

def convert ans
	if ans == 'yes'
		true
	elsif ans == 'no'
		false
	end
end

STDOUT.flush
list = []

primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 4, 9, 25, 49]
primes.each do |p|
	puts p
	STDOUT.flush

	isYes = convert gets.chomp
	if isYes
		list << p
	end
end

if list.length > 1
	puts 'composite'
	STDOUT.flush
else
	puts 'prime'
	STDOUT.flush
end

primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
squares = [4, 9, 25, 49]
cnt = 0
primes.each do |prime|
	puts prime
	STDOUT.flush
	cnt += (gets.chomp == "yes") ? 1 : 0
end
squares.each do |square|
	puts square
	STDOUT.flush
	cnt += (gets.chomp == "yes") ? 2 : 0
end

puts cnt >= 2 ? "composite" : "prime"

def convert ans
	if ans == 'yes'
		true
	elsif ans == 'no'
		false
	end
end

primes = [97, 89, 83, 79, 73, 71, 67, 61, 59, 53]

primes.each do |p|
	puts p
	STDOUT.flush
	isYes = convert gets.chomp
	if isYes
		puts 'prime'
		STDOUT.flush
		exit
	end
end

puts 2

STDOUT.flush
isYes = convert gets.chomp

if isYes
	divisor = [4, 3, 5, 7, 11, 13, 17, 19, 23]
	list = []

	divisor.each do |d|
		puts d

		STDOUT.flush
		isYes = convert gets.chomp

		if isYes
			list << d
		end

		if list.length > 0
			puts 'composite'
			STDOUT.flush
			exit
		end
	end
else
	divisor = [3, 5, 7, 9, 11, 13]
	list = []

	divisor.each do |d|
		puts d

		STDOUT.flush
		isYes = convert gets.chomp

		if isYes
			list << d
		end

		if list.length > 1
			puts 'composite'
			STDOUT.flush
			exit
		end
	end
end

puts 'prime'
STDOUT.flush

def convert ans
	if ans == 'yes'
		true
	elsif ans == 'no'
		false
	end
end

STDOUT.flush
primes = [97, 89, 83, 79, 73, 71, 67, 61, 59, 53]

primes.each do |p|
	puts p
	STDOUT.flush
	isYes = convert gets.chomp
	if isYes
		puts 'prime'
		STDOUT.flush
		exit
	end
end

puts 2

STDOUT.flush
isYes = convert gets.chomp

if isYes
	divisor = [4, 3, 5, 7, 11, 13, 17, 19, 23]
	list = []

	divisor.each do |d|
		puts d

		STDOUT.flush
		isYes = convert gets.chomp

		if isYes
			list << d
		end

		if list.length > 0
			puts 'composite'
			STDOUT.flush
			exit
		end
	end
else
	divisor = [3, 5, 7, 9, 11, 13, 17, 25, 49]
	list = []

	divisor.each do |d|
		puts d

		STDOUT.flush
		isYes = convert gets.chomp

		if isYes
			list << d
		end

		if list.length > 1
			puts 'composite'
			STDOUT.flush
			exit
		end
	end
end

puts 'prime'
STDOUT.flush

def convert ans
	if ans == 'yes'
		true
	elsif ans == 'no'
		false
	end
end

STDOUT.flush
primes = [97, 89, 83, 79, 73, 71, 67, 61, 59, 53]

primes.each do |p|
	puts p
	STDOUT.flush
	isYes = convert gets.chomp
	if isYes
		puts 'prime'
		STDOUT.flush
		exit
	end
end

puts 2

STDOUT.flush
isYes = convert gets.chomp

if isYes
	divisor = [4, 3, 5, 7, 11, 13, 17, 19, 23]
	list = []

	divisor.each do |d|
		puts d

		STDOUT.flush
		isYes = convert gets.chomp

		if isYes
			list << d
		end

		if list.length > 0
			puts 'composite'
			STDOUT.flush
			exit
		end
	end
else
	divisor = [3, 5, 7, 9, 11, 13, 25, 49]
	list = []

	divisor.each do |d|
		puts d

		STDOUT.flush
		isYes = convert gets.chomp

		if isYes
			list << d
		end

		if list.length > 1
			puts 'composite'
			STDOUT.flush
			exit
		end
	end
end

puts 'prime'
STDOUT.flush