n, m = STDIN.gets.split(' ').map{|x| x.to_i}
a = []

m.times do |i|
  a.push(STDIN.gets.split(' ').map{|y| y.to_i - 1});
end

=begin
n, m = 5, 6
a = ['1 2',
'1 3',
'2 3',
'2 4',
'3 4',
'4 5'].map{|x| x.split(' ').map{|y| y.to_i - 1}}
=end
musketeers = Array.new(n){|x| {'known'=>{}, 'knowncount'=> 0}}
a.map do |elem|
  musketeers[elem[0]]['knowncount'] +=1;
  musketeers[elem[0]]['known'][elem[1]]=true;
  musketeers[elem[1]]['knowncount'] +=1;
  musketeers[elem[1]]['known'][elem[0]]=true;
end

# получить тройки знающих
troikas = [];
a.map do |x|
  unite = musketeers[x[0]]['known'].keys & musketeers[x[1]]['known'].keys

  unite.map{|y| troikas.push([y, x[0],x[1] ].sort) }

end

troikas.uniq!

res = troikas.map{|x|  -6 + x.inject(0){|result, y| result+= musketeers[y]['knowncount']}}.min
res = -1 if res == nil
puts res

=begin
      ____________
     /            \
    /  /\      /\  \
   /  /  \    /  \  \
   \                /
    \     \___/    /
     \____________/
=end

class Solve
  def run()
    str = gets.split
    n , m = Integer(str[0]), Integer(str[1])
    graph = Array.new(n) {Array.new(n,false)}
    graph2 = Array.new(n) {Array.new}
    degree = Array.new(n,0)
    for i in 1..m
      str = gets.split
      u , v = Integer(str[0]),Integer(str[1])
      if v < u
        u, v = v , u
      end
      u -= 1
      v -= 1
      graph[u][v] = graph[v][u] = true
      graph2[u].push(v)
      degree[u] += 1
      degree[v] += 1
    end
    mn = 4000 * 4000 * 4000 * 2
    for i in 0..n-1
      for j in 0..graph2[i].length-2
        for k in j+1..graph2[i].length-1
          if graph[graph2[i][j]][graph2[i][k]] == true and degree[i] + degree[graph2[i][j]] + degree[graph2[i][k]] < mn
            mn = degree[i] + degree[graph2[i][j]] + degree[graph2[i][k]]
          end
        end
      end
    end
    if mn == 4000 * 4000 * 4000 * 2
      puts -1
    else
      puts (mn - 6)
    end
  end
end

Solve.new.run

q = Hash.new([])
n, m = gets.split.map(&:to_i)
glory = 0
out = -1

m.times do
  a, b = gets.split.map(&:to_i)
  q[a] += [b]
  q[b] += [a]
end

q.delete_if{ |key, value| value.size < 2 }

q.each do |key, value|

  for i in 0...value.size-1 do
    next unless q.key?(value[i])

    for j in i+1..value.size-1 do
      next unless q.key?(value[j])
      next unless q[value[j]].include?(value[i])

      glory = -6
      glory += q[value[i]].size
      glory += q[value[j]].size
      glory += q[key].size
      out = glory if out > glory || out == -1

    end
  end
end

puts out

require 'set'

n, m = gets.split.map &:to_i
neighbour = (1..n).map{0}
degree = (1..n).map{0}

edges = []
m.times {
	i, j = gets.split.map(&:to_i)
	i -= 1
	j -= 1
	neighbour[i] |= (1 << j)
	neighbour[j] |= (1 << i)
	degree[i] += 1
	degree[j] += 1
	edges << [i, j]
}

min = Float::INFINITY

edges.each{|i, j|
	d0 = degree[i] + degree[j]
	x = neighbour[i] & neighbour[j]
	(0..n-1).each{|k|
		if x[k] == 1
			d = d0 + degree[k]
			min = d if d < min
		end
	}
}

#(0..n-1).sort_by{|i| degree[i]}.each{|i|
#	d1 = degree[i]
#	break if d1 * 3 >= min
#
#	edges.reject!{|j, k|
#		if j == i || k == i
#			true
#		else
#			if neighbour[i].include?(j) && neighbour[i].include?(k)
#				d2, d3 = degree[j], degree[k]
#				d = d1 + d2 + d3
#				min = d if d < min
#			end
#			false
#		end
#	}
#}
#

p min == Float::INFINITY ? -1 : min - 6

n, m = gets.chomp.split(' ').map(&:to_i)
as = []
bs = []
m.times do
  a, b = gets.chomp.split(' ').map(&:to_i)
  as << a
  bs << b
end

rs = [[]]
n.times do
  rs << []
end

hs = Hash.new(0)
for i in 0..m-1
  hs[as[i]] += 1
  hs[bs[i]] += 1
  rs[as[i]] << bs[i]
  rs[bs[i]] << as[i]
end

rtn = -1
for m1 in 1..n-2
  r = rs[m1]
  if 1 < r.size
    for j in 0..r.size-2
      m2 = r[j]
      for k in j+1..r.size-1
        m3 = r[k]
        if rs[m2].include?(m3)
          if rtn < 0 || hs[m1] + hs[m2] + hs[m3] - 6 < rtn
            rtn = hs[m1] + hs[m2] + hs[m3] - 6
          end
        end
      end
    end
  end
end

puts rtn

=begin
      ____________
     /            \
    /  /\      /\  \
   /  /  \    /  \  \
   \                /
    \     \___/    /
     \____________/
=end

class Solve
  def run()
    str = gets.split
    n , m = Integer(str[0]), Integer(str[1])
    graph = Array.new(n) {Array.new(n,false)}
    graph2 = Array.new(n) {Array.new}
    degree = Array.new(n,0)
    for i in 1..m
      str = gets.split
      u , v = Integer(str[0]),Integer(str[1])
      if v < u
        u, v = v , u
      end
      u -= 1
      v -= 1
      graph[u][v] = graph[v][u] = true
      graph2[u].push(v)
      degree[u] += 1
      degree[v] += 1
    end
    mn = 4000 * 4000 * 4000 * 2
    for i in 0..n-1
      for j in 0..graph2[i].length-2
        for k in j+1..graph2[i].length-1
          if graph[graph2[i][j]][graph2[i][k]] == true and degree[i] + degree[graph2[i][j]] + degree[graph2[i][k]] < mn
            mn = degree[i] + degree[graph2[i][j]] + degree[graph2[i][k]]
          end
        end
      end
    end
    puts (mn - 6)
  end
end

Solve.new.run

q = Hash.new([])
n, m = gets.split.map(&:to_i)
glory = 0
out = -1

m.times do
  a, b = gets.split.map(&:to_i)
  q[a] += [b]
  q[b] += [a]
end

q.delete_if{ |key, value| value.size < 2 }

q.each do |key, value|
  for i in 0...value.size-1 do
    unless q.key?(value[i])
      glory = 0
      break
    end
    for j in i+1..value.size-1 do
      if q.key?(value[j])

        if q[value[j]].include?(value[i])
          glory += q[value[i]].size
          glory += q[value[j]].size
          glory += q[key].size
          glory -= 6
          out = glory if out > glory || out == -1
        else
          glory = 0
          break
        end
      else
        glory = 0
        break
      end

    end
  end
end

puts out

q = Hash.new([])
n, m = gets.split.map(&:to_i)
glory = 0
out = -1

m.times do
  a, b = gets.split.map(&:to_i)
  q[a] += [b]
  q[b] += [a]
end

q.delete_if{ |key, value| value.size < 2 }

q.each do |key, value|

  for i in 0...value.size-1 do
    break unless q.key?(value[i])

    for j in i+1..value.size-1 do
      break unless q.key?(value[j])
      break unless q[value[j]].include?(value[i])

      glory = -6
      glory += q[value[i]].size
      glory += q[value[j]].size
      glory += q[key].size
      out = glory if out > glory || out == -1

    end
  end
end

puts out


gets.to_i.times do
  n = gets.to_i
  a = gets.split.map &:to_i
  i = 0
  (0..100).each do |x|
    if j = a.index(x)
      a[i], a[j] = a[j], a[i]
    else
      break
    end
    i += 1
  end
  puts a.join ' '
end

gets.to_i.times {
  gets
  arr = gets.split(' ').map(&:to_i).sort
  res = []
  res_tail = []
  arr.each { |el|
    if el == res[-1]
      res_tail.push(el)
    else
      res.push(el)
    end
  }
  puts [*res, *res_tail].join(' ')
}

def solve(n, a)
    mex = 0
    b = []
    n.times {
        if (i = a.index(mex))
            b << a.delete_at(i)
            mex += 1
        else
            break
        end
    }
    b += a
    b
end

def main
    t = int
    t.times do
        n = int
        a = ints
        puts solve(n, a) * " "
    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 = gets.to_i
  a = gets.split.map &:to_i
  a.sort!
  res = []
  (0...n).each do |i|
    res << a[i] if i == 0 || a[i] != a[i - 1]
  end
  (0...n).each do |i|
    res << a[i] if i > 0 && a[i] == a[i - 1]
  end
  puts res.join ' '
end

t = gets.chomp.to_i
for test in (1..t)
  n = gets.chomp.to_i
  a = gets.chomp.split(' ').map { |x| x.to_i }
  c = Array.new(101).fill(0)
  for i in a
    c[i] += 1
  end
  j = 0
  for i in (0..100)
    if c[i] > 0
      c[i] -= 1
      a[j] = i
      j += 1
    end
  end
  for i in (0..100)
    while c[i] > 0
      c[i] -= 1
      a[j] = i
      j += 1
    end
  end
  a.each do |x|
    print x, ' '
  end
  puts
end

gets.to_i.times do
  n = gets.to_i
  a = gets.split.map &:to_i
  res = []
  (0...n).each do |i|
    res << a[i] if i == 0 || a[i] != a[i - 1]
  end
  (0...n).each do |i|
    res << a[i] if i > 0 && a[i] == a[i - 1]
  end
  puts res.join ' '
end


n = gets.to_i
arr = gets.split(" ").map(&:to_i).sort.reverse
ans = nil
if arr.include?(0)
	sum = arr.inject(0,:+)
	if sum % 3 == 0
		ans = arr.join("")
	elsif sum % 3 == 1

		one = [1,4,7]
		two = [2,5,8]
		l = nil
		one.each do |o|
			l = arr.rindex(o)
			if l
				arr.delete_at(l)
				break
			end
		end

		unless l
			deleted = 0
			two.each do |t|
				l = arr.rindex(t)
				if l
					if deleted == 0
						l1 = arr.index(t)
						if l == l1
							arr.delete_at(l)
							deleted = 1
							next
						else
							arr.delete_at(l)
							arr.delete_at(l1)
							break
						end
					end

					if deleted == 1
						arr.delete_at(l)
					end

				end
			end
		end

		# j = arr.length - 1
		# while j >= 0
		# 	a = arr[j]

		# 	if a % 3 == 1 && one.length < 1
		# 		one << j
		# 		break
		# 	end

		# 	if a % 3 == 2  && two.length < 2
		# 		two << j
		# 	end
		# 	j -= 1
		# end
		# if one.empty?
		# 	arr.delete_at(two[0])
		# 	arr.delete_at(two[1])
		# else
		# 	arr.delete_at(one[0])
		# end

		# puts "here"
		# l = arr.rindex{|a| a % 3 == 1}
		# if l
		# 	arr.delete_at(l)
		# else
		# 	l = arr.rindex{|a| a % 3 == 2}
		# 	arr.delete_at(l)
		# 	l = arr.rindex{|a| a % 3 == 2}
		# 	arr.delete_at(l)
		# end
	else

		one = [1,4,7]
		two = [2,5,8]
		l = nil
		two.each do |o|
			l = arr.rindex(o)
			if l
				arr.delete_at(l)
				break
			end
		end

		unless l
			deleted = 0
			one.each do |t|
				l = arr.rindex(t)
				if l
					if deleted == 0
						l1 = arr.index(t)
						if l == l1
							arr.delete_at(l)
							deleted = 1
							next
						else
							arr.delete_at(l)
							arr.delete_at(l1)
							break
						end
					end

					if deleted == 1
						arr.delete_at(l)
					end

				end
			end
		end

		# one = [1,4,7]
		# two = [2,5,8]
		# j = arr.length - 1
		# while j >= 0
		# 	a = arr[j]

		# 	if a % 3 == 2 && two.length < 1
		# 		two << j
		# 		break
		# 	end

		# 	if a % 3 == 1  && one.length < 2
		# 		one << j
		# 	end
		# 	j -= 1
		# end
		# if two.empty?
		# 	arr.delete_at(one[0])
		# 	arr.delete_at(one[1])
		# else
		# 	arr.delete_at(two[0])
		# end

		# l = arr.rindex{|a| a % 3 == 2}
		# if l
		# 	arr.delete_at(l)
		# else
		# 	l = arr.rindex{|a| a % 3 == 1}
		# 	arr.delete_at(l)
		# 	l = arr.rindex{|a| a % 3 == 1}
		# 	arr.delete_at(l)
		# end
	end
	ans = arr.join("")
	unless /[^0]/ =~ ans
		puts "0"
	else
		puts ans
	end
else
	puts "-1"
end

n = gets.to_i
digits = gets.split.map(&:to_i).sort_by {|el| -el}

unless digits.last==0
  puts -1
  exit
end

sum = digits.inject{|sum,el| sum+=el}
ans = 0
size = digits.size

if sum%3 == 0
  ans =  digits.join unless digits[0] == 0
elsif sum%3 == 1
  (size-1).downto(0) do |i|
    if digits[i]%3==1
      digits.delete_at i
      break
    end
  end
  if digits.size == size
    (size-1).downto(0) do |i|
      if digits[i]%3==2 && ( size - digits.size < 2 )
        digits.delete_at i
      end
    end
  end
  ans =  digits.join unless digits[0] == 0
elsif sum%3 == 2
  (size-1).downto(0) do |i|
    if digits[i]%3==2
      digits.delete_at i
      break
    end
  end
  if digits.size == size
    (size-1).downto(0) do |i|
      if digits[i]%3==1 && ( size - digits.size < 2 )
        digits.delete_at i
      end
    end
  end
  ans =  digits.join unless digits[0] == 0
end

puts (ans[0] == '0' ? 0 : ans)

n = gets.to_i
arr = gets.split(" ").map(&:to_i).sort.reverse
ans = nil
if arr.include?(0)
	sum = arr.inject(0,:+)
	if sum % 3 == 0
		ans = arr.join("")
	elsif sum % 3 == 1

		one = [1,4,7]
		two = [2,5,8]
		l = nil
		one.each do |o|
			l = arr.rindex(o)
			if l
				arr.delete_at(l)
				break
			end
		end

		unless l
			deleted = 0
			two.each do |t|
				l = arr.rindex(t)
				if l
					if deleted == 0
						l1 = arr.index(t)
						if l == l1
							arr.delete_at(l)
							deleted = 1
							next
						else
							arr.delete_at(l)
							arr.delete_at(l1)
							break
						end
					end

					if deleted == 1
						arr.delete_at(l)
					end

				end
			end
		end

		# j = arr.length - 1
		# while j >= 0
		# 	a = arr[j]

		# 	if a % 3 == 1 && one.length < 1
		# 		one << j
		# 		break
		# 	end

		# 	if a % 3 == 2  && two.length < 2
		# 		two << j
		# 	end
		# 	j -= 1
		# end
		# if one.empty?
		# 	arr.delete_at(two[0])
		# 	arr.delete_at(two[1])
		# else
		# 	arr.delete_at(one[0])
		# end

		# puts "here"
		# l = arr.rindex{|a| a % 3 == 1}
		# if l
		# 	arr.delete_at(l)
		# else
		# 	l = arr.rindex{|a| a % 3 == 2}
		# 	arr.delete_at(l)
		# 	l = arr.rindex{|a| a % 3 == 2}
		# 	arr.delete_at(l)
		# end
	else

		one = [1,4,7]
		two = [2,5,8]
		l = nil
		two.each do |o|
			l = arr.rindex(o)
			if l
				arr.delete_at(l)
				break
			end
		end

		unless l
			deleted = 0
			one.each do |t|
				l = arr.rindex(t)
				if l
					if deleted == 0
						l1 = arr.index(t)
						if l == l1
							arr.delete_at(l)
							deleted = 1
							next
						else
							arr.delete_at(l)
							arr.delete_at(l1)
							break
						end
					end

					if deleted == 1
						arr.delete_at(l)
					end

				end
			end
		end

		# one = [1,4,7]
		# two = [2,5,8]
		# j = arr.length - 1
		# while j >= 0
		# 	a = arr[j]

		# 	if a % 3 == 2 && two.length < 1
		# 		two << j
		# 		break
		# 	end

		# 	if a % 3 == 1  && one.length < 2
		# 		one << j
		# 	end
		# 	j -= 1
		# end
		# if two.empty?
		# 	arr.delete_at(one[0])
		# 	arr.delete_at(one[1])
		# else
		# 	arr.delete_at(two[0])
		# end

		# l = arr.rindex{|a| a % 3 == 2}
		# if l
		# 	arr.delete_at(l)
		# else
		# 	l = arr.rindex{|a| a % 3 == 1}
		# 	arr.delete_at(l)
		# 	l = arr.rindex{|a| a % 3 == 1}
		# 	arr.delete_at(l)
		# end
	end
	ans = arr.join("")
	# if ans.to_i == 0
	# 	puts "0"
	# else
		puts ans
	# end
else
	puts "-1"
end


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

if n == 2
	puts "-1"
	exit 0
end

mn = x.min
k = x.index(mn)
lmx = x[0..k-1].max
rmx = x[k+1..-1].max
if 0 < k && k + 1 < n && lmx > mn && rmx > mn
	if lmx != rmx
		puts "#{x[0..k-1].index(lmx)+1} #{x[k+1..-1].index(rmx)+k+2}"
	else
		1.upto(k-1) do |i|
			if x[i] != mn
				puts "#{i+1} #{k+1}"
				exit 0
			end
		end
		(k+1).upto(n-2) do |i|
			if x[i] != mn
				puts "#{k+1} #{i+1}"
				exit 0
			end
		end
		if n == 3
			puts -1
			exit 0
		end
		puts "1 2"
	end
	exit 0
end

mx = x.max
k = x.index(mx)
lmn = x[0..k-1].min
rmn = x[k+1..-1].min
if 0 < k && k + 1 < n && lmn < mx && rmn < mx
	if lmn != rmn
		puts "#{x[0..k-1].index(lmn)+1} #{x[k+1..-1].index(rmn)+k+2}"
	else
		1.upto(k-1) do |i|
			if x[i] != mx
				puts "#{i+1} #{k+1}"
				exit 0
			end
		end
		(k+1).upto(n-2) do |i|
			if x[i] != mx
				puts "#{k+1} #{i+1}"
				exit 0
			end
		end
		if n == 3
			puts -1
			exit 0
		end
		puts "1 2"
	end
	exit 0
end

if mn == mx
	puts -1
	exit 0
end

x[1..-2].each_with_index do |v, i|
	if v != x[0]
		puts "1 #{i+2}"
		exit 0
	end
	if v != x[-1]
		puts "#{i+2} #{n}"
		exit 0
	end
end

puts -1

t = gets.to_i

a = gets.split.collect{|x| x.to_i}

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

i = 0
finish = false

1.upto(a.size-1) do |i|
	if a[i-1] != a[i]
		a[i], a[i-1] = a[i-1], a[i]

		finish = a != up && a != dn

		if finish
			print i,' ', i+1
			break
		end

		a[i], a[i-1] = a[i-1], a[i]
	end
end

if not finish or a == Array.new(a.size, a[0])
	print -1
end

n = gets.to_i
a = gets.split(' ').map(&:to_i)
if n < 3
  puts "-1"
  exit
end

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

i = 0
finish = false

1.upto(a.size-1) do |i|
  if a[i] != a[i-1]
    a[i],a[i-1] = a[i-1],a[i]

    finish = (a != incr) && (a != decr)
    if finish
      puts "#{i} #{i+1}"
      break
    end
    a[i],a[i-1] = a[i-1],a[i]
  end
end

if !finish
  puts "-1"
end

n = gets.to_i
a = gets.split(' ').map(&:to_i)
if n < 3
  puts "-1"
  exit
end

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

i = 0
finish = false

1.upto(a.size-1) do |i|
  if a[i] != a[i-1]
    a[i],a[i-1] = a[i-1],a[i]

    finish = (a != incr) && (a != decr)
    if finish
      puts "#{i} #{i+1}"
      break
    end
    a[i],a[i-1] = a[i-1],a[i]
  end
end

if !finish
  puts "-1 "
end

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

if n == 2
	puts "-1"
	exit 0
end

mn = x.min
k = x.index(mn)
lmx = x[0..k-1].max
rmx = x[k+1..-1].max
if 0 < k && k + 1 < n && lmx > mn && rmx > mn
	puts "#{x[0..k-1].index(lmx)+1} #{x[k+1..-1].index(rmx)+1}"
	exit 0
end

mx = x.max
k = x.index(mx)
lmn = x[0..k-1].min
rmn = x[k+1..-1].min
if 0 < k && k + 1 < n && lmn < mx && rmn < mx
	puts "#{x[0..k-1].index(lmn)+1} #{x[k+1..-1].index(rmn)+1}"
	exit 0
end

if mn == mx
	puts -1
	exit 0
end

x[1..-2].each_with_index do |v, i|
	if v != x[0]
		puts "1 #{i+2}"
		exit 0
	end
	if v != x[-1]
		puts "#{i+2} #{n}"
		exit 0
	end
end

puts -1

def gao(x, y)
	return [-1] if x.size == 2
	a, b = [], []
	x.each_index { |i| x[i] == y[i] ? a << x[i] : b << x[i] }
	a.uniq!
	ub = b.uniq
	if a.size >= 2
		[x.index(a[0]) + 1, x.index(a[1]) + 1]
	else
		if ub.size >= 2 && b.size >= 3
			[x.index(ub[0]) + 1, x.index(ub[1]) + 1]
		else
			[-1]
		end
	end
end

n = gets.to_i
x = gets.split.map(&:to_i)
r = gao(x, x.sort)
puts r.size == 1 ? gao(x, x.sort.reverse) : r.join(" ")

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

if n == 2
	puts "-1"
	exit 0
end

mn = x.min
k = x.index(mn)
lmx = x[0..k-1].max
rmx = x[k+1..-1].max
if 0 < k && k + 1 < n && lmx > mn && rmx > mn
	if lmx != rmx
		puts "#{x[0..k-1].index(lmx)+1} #{x[k+1..-1].index(rmx)+k+2}"
	else
		1.upto(k-1) do |i|
			if x[i] != mn
				puts "#{i+1} #{k+1}"
				exit 0
			end
		end
		(k+1).upto(n-1) do |i|
			if x[i] != mn
				puts "#{k+1} #{i+1}"
				exit 0
			end
		end
		if n == 3
			puts -1
			exit 0
		end
		puts "1 2"
	end
	exit 0
end

mx = x.max
k = x.index(mx)
lmn = x[0..k-1].min
rmn = x[k+1..-1].min
if 0 < k && k + 1 < n && lmn < mx && rmn < mx
	if lmx != rmx
		puts "#{x[0..k-1].index(lmn)+1} #{x[k+1..-1].index(rmn)+k+2}"
	else
		1.upto(k-1) do |i|
			if x[i] != mx
				puts "#{i+1} #{k+1}"
				exit 0
			end
		end
		(k+1).upto(n-1) do |i|
			if x[i] != mx
				puts "#{k+1} #{i+1}"
				exit 0
			end
		end
		if n == 3
			puts -1
			exit 0
		end
		puts "1 2"
	end
	exit 0
end

if mn == mx
	puts -1
	exit 0
end

x[1..-2].each_with_index do |v, i|
	if v != x[0]
		puts "1 #{i+2}"
		exit 0
	end
	if v != x[-1]
		puts "#{i+2} #{n}"
		exit 0
	end
end

puts -1


# first steps

n, n1, n2 = gets.split(' ')
a = gets.split(' ')

n = n.to_i
i = 0
while i < n
	a[i] = a[i].to_i
	i += 1
end

n1 = n1.to_i
n2 = n2.to_i

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

if n1 > n2
	temp = n2
	n2 = n1
	n1 = temp
end

cnt1, cnt2 = [0, 0]

i = 0
n1.times do
	cnt1 += a[i].to_i
	i += 1
end
i = n1
n2.times do
	cnt2 += a[i].to_i
	i += 1
end
#puts a.join(', ')
#puts cnt1.to_s + ' ' + cnt2.to_s
puts cnt1.to_f / n1.to_f + cnt2.to_f / n2.to_f

n, n1, n2 = gets.split.map(&:to_i)
data = gets.split.map(&:to_i)

data.sort! { |x, y| y <=> x }
n1, n2 = [n1,n2].minmax

ans = data[0,n1].reduce(0,:+).to_f / n1.to_f + data[n1,n2].reduce(0,:+).to_f / n2.to_f
p ans


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

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n,k=gsmi
s=gs
c=gets.chomp.split

i=0
cnt=0
while i<n do
  if c.include?(s[i])
    cnt+=1
  else
    h[cnt]+=1
    cnt=0
  end
  i+=1
end
h[cnt]+=1

# substringなん文字が何個あるか
h.each do |key,val|
  cnt = key*(key+1)/2*val
  sum+=cnt
end
puts sum

gets
s = gets.chomp
c = gets.split
p s.chars.chunk { c.include? _1 }.select { _1[0] }.sum {
		_2.size * (_2.size + 1) / 2
  }


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

class Player
  attr_reader :time, :team, :b_num, :card

  def initialize(l)
    @time  = l[0].to_i
    @team  = l[1]
    @b_num = l[2].to_i
    @card  = l[3]
  end

  def update(p)
    if @card != 'r'
      @time = p.time
      @card = 'r'
    end
  end

end

class Players
  def initialize
    @faul_receivers = []
  end

  def <<(p)
    if @faul_receivers.length < 1
      @faul_receivers << p
    else
      update = false
      @faul_receivers.each do |r|
        update= true if r.team == p.team and r.b_num == p.b_num
        if update
          r.update(p)
          break
        end
      end
      @faul_receivers << p unless update
    end
  end

  def red_card_list
    reds = []
    @faul_receivers.each do |p|
      reds << p if p.card == 'r'
    end

    reds.sort_by! { |p| p.time }
    return reds
  end

  def each(&block)
    @faul_receivers.each &block
  end
end

h, a, n = gets.chomp, gets.chomp, gets.chomp.to_i

p_l = Players.new
n.times do
  l = gets.chomp.split(' ')
  p = Player.new(l)
  p_l << p
end

p_l.red_card_list.each do |p|
  t = p.team == "a" ? a : h
  puts "#{t} #{p.b_num} #{p.time}"
end

team_a = STDIN.readline.strip
team_b = STDIN.readline.strip
n = STDIN.readline.to_i
yellow, red = {}, {}
n.times do
  tokens = STDIN.readline.split
  time, player, color = tokens[0].to_i, tokens[2].to_i, tokens[3]
  team = tokens[1] == 'h' ? team_a : team_b
  key = [player, team]
  first_red = false
  if color == 'y'
    if yellow.include?(key) and not red.include?(key)
      red[key] = first_red = true
    end
    yellow[key] = true
  else
    if not red.include?(key)
      red[key] = first_red = true
    end
  end
  if first_red
    puts '%s %d %d' % [team, player, time]
  end
end

require 'pp'

teama = STDIN.gets.chomp
teamb = STDIN.gets.chomp

h ={teama => {}, teamb => {}}

n = STDIN.gets.chomp.to_i

n.times do
  t, ha, num, yr = STDIN.gets.chomp.split(/ /)
  team = ha == 'h' ? teama : teamb

  if h[team].has_key?(num) && h[team][num] == 2
    # nothing
  elsif h[team].has_key?(num) && h[team][num] == 1
    print "#{team} #{num} #{t}\n"
      h[team][num] = 2
  elsif !h[team].has_key?(num)
    if yr == 'r'
      print "#{team} #{num} #{t}\n"
      h[team][num] = 2
    else
      h[team][num] = 1
    end
  end
end

name=[gets.chomp,gets.chomp]
foul=[{},{}]
done=[{},{}]
gets.to_i.times{
  time,team,n,type=gets.split
  team_n=team==?h?0:1
  if foul[team_n][n] || type==?r
    unless done[team_n][n]
      puts [name[team_n],n,time]*" "
      done[team_n][n]=true
    end
  else
    foul[team_n][n]=true
  end
}

home_team = gets.chomp
away_team = gets.chomp
N = gets.to_i
used = {}
red = {}
while $_ = gets do
    t_, team, m_, type = $_.split
    t = t_.to_i
    m = m_.to_i
    if red["#{team}:#{m}"]
        next
    end
    if type == "r" || used["#{team}:#{m}"] then
        if team == "h"
            print home_team
        else
            print away_team
        end
        print " #{m} #{t}\n"
        red["#{team}:#{m}"] = true
    end
    used["#{team}:#{m}"] = true
end

#!/usr/bin/ruby
home = STDIN.gets.chomp
away = STDIN.gets.chomp
n = STDIN.gets.chomp.to_i
marked = {'a' => [], 'h' => []}
teams = {'a' => away, 'h' => home}
n.times do
    tokens = STDIN.gets.chomp.split(' ')
    minute = tokens[0].to_i
    team = tokens[1]
    player = tokens[2].to_i
    card = tokens[3]
    marked[team][player] = 0 if not marked[team][player]
    next if marked[team][player] > 1
    if card == 'r' or marked[team][player] == 1
        marked[team][player] = 2
        puts "#{teams[team]} #{player} #{minute}"
    else
        marked[team][player] += 1
    end
end

a=Array.new(105,0)
b=Array.new(105,0)
sz=Array.new
sta=gets.to_s
stb=gets.to_s
n=gets.to_i
for i in 1..n
  stc=gets.to_s
  sz=stc.split
  if sz[3]=='y'
    tr=1
  elsif sz[3]=="r"
    tr=2
  end
  if sz[1]=="h"
    t=sz[2].to_i
    if a[t]>=2
      next
    end
    a[t]+=tr
    if a[t]>=2
      print sta.chomp
      print " "
      print t
      print " "
      puts sz[0]
    end
  elsif sz[1]=="a"
    t=sz[2].to_i
    if b[t]>=2
      next
    end
    b[t]+=tr
    if b[t]>=2
      print stb.chomp
      print " "
      print t
      print " "
      puts sz[0]
    end
  end
end

# 493A

class Foul
  include Comparable
  attr :time

  def initialize(player, time, team)
    @player = player
    @time = time.to_i
    @team = team
  end

  def <=>(another)
    time <=> another.time
  end

  def to_s
    [@team, @player, @time].join(' ')
  end
end

names = {h: gets.chomp, a: gets.chomp}
cards = {h: {y: {}, r: {}}, a: {y: {}, r: {}}}
gets.to_i.times do
  time, _team, player, card_colour = gets.chomp.split
  team = _team.to_sym
  unless cards[team][:r].include?(player)
    if card_colour == 'r'
      cards[team][:r][player] = time
    else
      if cards[team][:y].include?(player)
        cards[team][:r][player] = time
      else
        cards[team][:y][player] = time
      end
    end
  end
end

fouls = []
[:h, :a].each { |c| cards[c][:r].each { |k, v| fouls << Foul.new(k, v, names[c]) } }
fouls.sort.each { |foul| puts foul }

home = gets.chomp
away = gets.chomp
a = {}
arry = []
n = Integer(gets)
for j in 1..n
  arry[j] = gets.split(" ")
  arry[j].each { |arr| arr.chomp }
end
for i in 1..n
  if (((a[arry[i][1]]==nil || a[arry[i][1]][arry[i][2]]!= 'r') && arry[i][3] == 'r') || ( a[arry[i][1]]  &&  a[arry[i][1]][arry[i][2]] == 'y' && arry[i][3] == 'y'))
    if arry[i][1] == 'a'
      puts "#{away} #{arry[i][2]} #{arry[i][0]}"
    else
      puts "#{home} #{arry[i][2]} #{arry[i][0]}"
    end

    if a[arry[i][1]] ==nil
      a.merge!( arry[i][1] => {} )
    end

    if a[arry[i][1]][arry[i][2]] == 'y'
      a[arry[i][1]][arry[i][2]] = 'r'
    end

    if a[arry[i][1]][arry[i][2]] == nil
      a[arry[i][1]].merge!(  arry[i][2] => arry[i][3] )
    end

  end

  if a[arry[i][1]] ==nil
    a.merge!( arry[i][1] => {} )
  end
  if a[arry[i][1]][arry[i][2]] == nil
    a[arry[i][1]].merge!(  arry[i][2] => arry[i][3] )
  end
end

h = gets.chomp
a = gets.chomp
n = gets.to_i
hash = {}
processed = {}
result = []
n.times do
  m,team,player,card = gets.chomp.split
  if card == 'r'
    if !processed[[team,player]]
      result << [team,player,m.to_i]
      processed[[team,player]] = true
    end
  else
    if hash[[team,player]]
      if !processed[[team,player]]
        result << [team,player,m.to_i]
        processed[[team,player]] = true
      end
    else
      hash[[team,player]] = true
    end
  end
end
result = result.sort_by {|x| x[2]}
result.each do |team,player,minute|
  puts "#{team == 'h' ? h : a} #{player} #{minute}"
end

h = gets.chomp
a = gets.chomp
n = gets.to_i
hash = {}
result = []
n.times do
  m,team,player,card = gets.chomp.split
  if card == 'r'
    result << [team,player,m.to_i]
  else
    if hash[[team,player]]
      result << [team,player,m.to_i]
    else
      hash[[team,player]] = true
    end
  end
end
result = result.sort_by {|x| x[2]}
result.each do |team,player,minute|
  puts "#{team == 'h' ? h : a} #{player} #{minute}"
end

h = gets.chomp
a = gets.chomp
n = gets.to_i
hash = {}
result = []
n.times do
  m,team,player,card = gets.chomp.split
  if card == 'r'
    result << [team,player,m.to_i]
    hash.delete([team,player]) if hash[[team,player]]
  else
    if hash[[team,player]]
      result << [team,player,m.to_i]
      hash.delete([team,player])
    else
      hash[[team,player]] = true
    end
  end
end
result = result.sort_by {|x| x[2]}
result.each do |team,player,minute|
  puts "#{team == 'h' ? h : a} #{player} #{minute}"
end

h = gets.chomp
a = gets.chomp
n = gets.to_i
hash = {}
result = []
n.times do
  m,team,player,card = gets.chomp.split
  if card == 'r'
    result << [team,player,m]
  else
    if hash[[team,player]]
      result << [team,player,m]
    else
      hash[[team,player]] = true
    end
  end
end
result = result.sort_by {|x| x[2]}
result.each do |team,player,minute|
  puts "#{team == 'h' ? h : a} #{player} #{minute}"
end

h = gets.chomp
a = gets.chomp
n = gets.to_i
hash = {}
result = []
n.times do
  m,team,player,card = gets.chomp.split
  if card == 'r'
    result << [team,player,m.to_i]
  else
    if hash[[team,player]]
      result << [team,player,[m.to_i,hash[[team,player]]].max]
    else
      hash[[team,player]] = m.to_i
    end
  end
end
result = result.sort_by {|x| x[2]}
result.each do |team,player,minute|
  puts "#{team == 'h' ? h : a} #{player} #{minute}"
end

team_a = STDIN.readline.strip
team_b = STDIN.readline.strip
n = STDIN.readline.to_i
foul = {}
n.times do
  tokens = STDIN.readline.split
  time, player, color = tokens[0].to_i, tokens[2].to_i, tokens[3]
  team = tokens[1] == 'h' ? team_a : team_b
  key = [player, team]
  if color == 'y'
    if foul[key] == 1
      puts '%s %d %d' % [team, player, time]
      foul[key] += 1
    else
      foul[key] = 1
    end
  else
    if not foul.include? key
      puts '%s %d %d' % [team, player, time]
      foul[key] = 2
    else
      if foul[key] == 1
        puts '%s %d %d' % [team, player, time]
      end
      foul[key] += 1
    end
  end
end

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

class Player
  attr_reader :time, :team, :b_num, :card

  def initialize(l)
    @time  = l[0].to_i
    @team  = l[1]
    @b_num = l[2].to_i
    @card  = l[3]
  end

  def update(p)
    @time = p.time
    @card = 'r'
  end

end

class Players
  def initialize
    @faul_receivers = []
  end

  def <<(p)
    if @faul_receivers.length < 1
      @faul_receivers << p
    else
      update = false
      @faul_receivers.each do |r|
        update= true if r.team == p.team and r.b_num == p.b_num
        if update
          r.update(p)
          break
        end
      end
      @faul_receivers << p unless update
    end
  end

  def red_card_list
    reds = []
    @faul_receivers.each do |p|
      reds << p if p.card == 'r'
    end
    reds.sort_by! { |p| p.time }
    return reds
  end

  def each(&block)
    @faul_receivers.each &block
  end
end

h, a, n = gets.chomp, gets.chomp, gets.chomp.to_i

p_l = Players.new
n.times do
  l = gets.chomp.split(' ')
  p = Player.new(l)
  p_l << p
end

p_l.each do |p|
  if p.card == "r"
    t = p.team == "a" ? a : h
    puts "#{t} #{p.b_num} #{p.time}"
  end
end

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

class Player
  attr_reader :time, :team, :b_num, :card

  def initialize(l)
    @time  = l[0].to_i
    @team  = l[1]
    @b_num = l[2].to_i
    @card  = l[3]
  end

  def update(p)
    @time = p.time
    @card = 'r'
  end

end

class Players
  def initialize
    @faul_receivers = []
  end

  def <<(p)
    if @faul_receivers.length < 1
      @faul_receivers << p
    else
      update = false
      @faul_receivers.each do |r|
        update= true if r.team == p.team and r.b_num == p.b_num
        if update
          r.update(p)
          break
        end
      end
      @faul_receivers << p unless update
    end
  end

  def red_card_list
    reds = []
    @faul_receivers.each do |p|
      reds << p if p.card == 'r'
    end

    reds.sort_by! { |p| p.time }
    return reds
  end

  def each(&block)
    @faul_receivers.each &block
  end
end

h, a, n = gets.chomp, gets.chomp, gets.chomp.to_i

p_l = Players.new
n.times do
  l = gets.chomp.split(' ')
  p = Player.new(l)
  p_l << p
end

p_l.red_card_list.each do |p|
  t = p.team == "a" ? a : h
  puts "#{t} #{p.b_num} #{p.time}"
end

home_team = gets.chomp
away_team = gets.chomp
N = gets.to_i
used = {}
while $_ = gets do
    t_, team, m_, type = $_.split
    t = t_.to_i
    m = m_.to_i
    if type == "r" || used["#{team}:#{m}"] then
        if team == "h"
            print home_team
        else
            print away_team
        end
        print " #{m} #{t}\n"
    end
    used["#{team}:#{m}"] = true
end

a=Array.new(105,0)
b=Array.new(105,0)
sz=Array.new
sta=gets.to_s
stb=gets.to_s
n=gets.to_i
for i in 1..n
  stc=gets.to_s
  sz=stc.split
  if sz[3]=='y'
    tr=1
  elsif sz[3]=="r"
    tr=2
  end
  if sz[1]=="h"
    t=sz[2].to_i
    a[t]+=tr
    if a[t]>=2
      print sta.chomp
      print " "
      print t
      print " "
      puts sz[0]
    end
  elsif sz[1]=="a"
    t=sz[2].to_i
    b[t]+=tr
    if b[t]>=2
      print stb.chomp
      print " "
      print t
      print " "
      puts sz[0]
    end
  end
end

# 493A

class Foul
  include Comparable
  attr :time

  def initialize(player, time, team)
    @player = player
    @time = time
    @team = team
  end

  def <=>(another)
    time <=> another.time
  end

  def to_s
    [@team, @player, @time].join(' ')
  end
end

names = {h: gets.chomp, a: gets.chomp}
cards = {h: {y: {}, r: {}}, a: {y: {}, r: {}}}
gets.to_i.times do
  time, _team, player, card_colour = gets.chomp.split
  team = _team.to_sym
  unless cards[team][:r].include?(player)
    if card_colour == 'r'
      cards[team][:r][player] = time
    else
      if cards[team][:y].include?(player)
        cards[team][:r][player] = time
      else
        cards[team][:y][player] = time
      end
    end
  end
end

fouls = []
[:h, :a].each { |c| cards[c][:r].each { |k, v| fouls << Foul.new(k, v, names[c]) } }
fouls.sort.each { |foul| puts foul }

home = gets.chomp
away = gets.chomp
a = {}
arry = []
n = Integer(gets)
for j in 1..n
  arry[j] = gets.split(" ")
  arry[j].each { |arr| arr.chomp }
end
for i in 1..n
  if (((a[arry[i][1]]==nil || a[arry[i][1]][arry[i][2]]!= 'r') && arry[i][3] == 'r') || ( a[arry[i][1]]  &&  a[arry[i][1]][arry[i][2]] == 'y' && arry[i][3] == 'y'))
    if arry[i][1] == 'a'
      puts "#{away} #{arry[i][2]} #{arry[i][0]}"
    else
      puts "#{home} #{arry[i][2]} #{arry[i][0]}"
    end
    if a[arry[i][1]] ==nil
      a.merge!( arry[i][1] => {} )
    end
    if a[arry[i][1]][arry[i][2]] == nil || a[arry[i][1]][arry[i][2]] == 'y'
      a[arry[i][1]][arry[i][2]] = 'r'
    end
  end

  if a[arry[i][1]] ==nil
    a.merge!( arry[i][1] => {} )
  end
  a[arry[i][1]].merge!(  arry[i][2] => arry[i][3] )
end

home = gets.chomp
away = gets.chomp
a = {}
arry = []
n = Integer(gets)
for j in 1..n
  arry[j] = gets.split(" ")
  arry[j].each { |arr| arr.chomp }
end
for i in 1..n
  if (((a[arry[i][1]]==nil || a[arry[i][1]][arry[i][2]]==nil) && arry[i][3] == 'r') || ( a[arry[i][1]]  &&  a[arry[i][1]][arry[i][2]] == 'y' && arry[i][3] == 'y'))
    if arry[i][1] == 'a'
      puts "#{away} #{arry[i][2]} #{arry[i][0]}"
    else
      puts "#{home} #{arry[i][2]} #{arry[i][0]}"
    end
  end

  if a[arry[i][1]] ==nil
    a.merge!( arry[i][1] => {} )
  end
  a[arry[i][1]].merge!(  arry[i][2] => arry[i][3] )
end

home = gets.chomp
away = gets.chomp
a = {}
arry = []
n = Integer(gets)
for j in 1..n
  arry[j] = gets.split(" ")
  arry[j].each { |arr| arr.chomp }
end
for i in 1..n
  if ((a[arry[i][1]]==nil && arry[i][3] == 'r') || ( a[arry[i][1]]  &&  a[arry[i][1]][arry[i][2]] == 'y' && arry[i][3] == 'y'))
    if arry[i][1] == 'a'
      puts "#{away} #{arry[i][2]} #{arry[i][0]}"
    else
      puts "#{home} #{arry[i][2]} #{arry[i][0]}"
    end
  end

  if a[arry[i][1]] ==nil
    a.merge!( arry[i][1] => {} )
  end
  a[arry[i][1]].merge!(  arry[i][2] => arry[i][3] )
end

home = gets.chomp
away = gets.chomp
a = {}
arry = []
n = Integer(gets)
for j in 1..n
  arry[j] = gets.split(" ")
  arry[j].each { |arr| arr.chomp }
end
for i in 1..n
  if (a[arry[i][1]] && a[arry[i][1]][arry[i][2]] == 'y' && arry[i][3] == 'y') || arry[i][3] == 'r'
    if arry[i][1] == 'a'
      puts "#{away} #{arry[i][2]} #{arry[i][0]}"
    else
      puts "#{home} #{arry[i][2]} #{arry[i][0]}"
    end
  end

  if a[arry[i][1]] ==nil
    a.merge!( arry[i][1] => {} )
  end
  a[arry[i][1]].merge!(  arry[i][2] => arry[i][3] )
end

home = gets.chomp
away = gets.chomp
a = {}
arry = []
n = Integer(gets)
for j in 1..n
  arry[j] = gets.split(" ")
  arry[j].each { |arr| arr.chomp }
end
for i in 1..n
  if (((a[arry[i][1]]==nil || a[arry[i][1]][arry[i][2]]!= 'r') && arry[i][3] == 'r') || ( a[arry[i][1]]  &&  a[arry[i][1]][arry[i][2]] == 'y' && arry[i][3] == 'y'))
    if arry[i][1] == 'a'
      puts "#{away} #{arry[i][2]} #{arry[i][0]}"
    else
      puts "#{home} #{arry[i][2]} #{arry[i][0]}"
    end

    if a[arry[i][1]] ==nil
      a.merge!( arry[i][1] => {} )
    end

    if a[arry[i][1]][arry[i][2]] == 'y'
      a[arry[i][1]][arry[i][2]] = 'r'
    end

    if a[arry[i][1]][arry[i][2]] == nil
      a[arry[i][1]].merge!(  arry[i][2] => arry[i][3] )
    end

  end

  if a[arry[i][1]] ==nil
    a.merge!( arry[i][1] => {} )
  end
  a[arry[i][1]].merge!(  arry[i][2] => arry[i][3] )
end

home = gets.chomp
away = gets.chomp
a = {}
arry = []
n = Integer(gets)
for j in 1..n
  arry[j] = gets.split(" ")
  arry[j].each { |arr| arr.chomp }
end
for i in 1..n
  if (((a[arry[i][1]]==nil || a[arry[i][1]][arry[i][2]]!= 'r') && arry[i][3] == 'r') || ( a[arry[i][1]]  &&  a[arry[i][1]][arry[i][2]] == 'y' && arry[i][3] == 'y'))
    if arry[i][1] == 'a'
      puts "#{away} #{arry[i][2]} #{arry[i][0]}"
    else
      puts "#{home} #{arry[i][2]} #{arry[i][0]}"
    end
    if a[arry[i][1]] ==nil
      a.merge!( arry[i][1] => {} )
    end
    a[arry[i][1]].merge!(  arry[i][2] => 'r' )
  end

  if a[arry[i][1]] ==nil
    a.merge!( arry[i][1] => {} )
  end
  a[arry[i][1]].merge!(  arry[i][2] => arry[i][3] )
end

home = gets.chomp
away = gets.chomp
a = {}
arry = []
n = Integer(gets)
for j in 1..n
  arry[j] = gets.split(" ")
  arry[j].each { |arr| arr.chomp }
end
for i in 1..n
  if (((a[arry[i][1]]==nil || a[arry[i][1]][arry[i][2]]!= 'r') && arry[i][3] == 'r') || ( a[arry[i][1]]  &&  a[arry[i][1]][arry[i][2]] == 'y' && arry[i][3] == 'y'))
    if arry[i][1] == 'a'
      puts "#{away} #{arry[i][2]} #{arry[i][0]}"
    else
      puts "#{home} #{arry[i][2]} #{arry[i][0]}"
    end
  end

  if a[arry[i][1]] ==nil
    a.merge!( arry[i][1] => {} )
  end
  a[arry[i][1]].merge!(  arry[i][2] => arry[i][3] )
end


n, k = gets.split.map(&:to_i)
xs = gets.split.map(&:to_i)
def get_result k, xs
  diffs=(0..xs.size-2).map do |i| xs[i+1]-xs[i]; end
  if diffs.any?{|d| d>k}
    return -1
  end

  diffs.inject([0]) do |memo,d|
    last = memo.pop
    if(last+d<=k)
      memo<<last+d
    else
      memo<<last
      memo<<d
    end
    memo
  end.length
end
puts get_result k, xs


def powmod(a, k, m)
  return 1 if k == 0
  t = powmod(a, k / 2, m)
  t = t * t % m
  t = t * a % m if k % 2 == 1
  return t
end

m = gets.chomp.to_i
ps = gets.chomp.split.map(&:to_i)
mod = 10**9 + 7
n = 1

hs = Hash.new(1)
ps.each do |p|
  hs[p] += 1
  n = n * p % mod
end

cnt = 1
hs.each do |_, v|
  cnt = cnt * v % (2 * (mod - 1))
end

r = 1
if cnt % 2 == 1
  hs.each do |k, v|
    r = r * powmod(k, (v - 1) / 2, mod) % mod
  end
end

puts r * powmod(n, cnt / 2, mod) % mod

MOD = 1000000000 + 7

def f(n, p)
  if p == 0 then
    return 1
  end
  m = f(n, p / 2)
  if p % 2 == 1 then
    return m * m * n % MOD
  else
    return m * m % MOD
  end
end

while s = $stdin.gets() do
  s = $stdin.gets()
  ps = s.split(" ")
  cnt = {}
  ps.each do |p|
    key = p.to_i()
    if cnt[key] then
      cnt[key] = cnt[key] + 1
    else
      cnt[key] = 1
    end
  end

  d = 1
  cnt.each do |key, val|
    d *= val + 1
  end

  ret = 1
  cnt.each do |key, val|
    x = f(key, (val * (val + 1) / 2) % (MOD - 1))
    y = f(x, (d / (val + 1)) % (MOD - 1))
    ret = ret * y % MOD
  end
  puts(ret)
end

def powmod(a, k, m)
  return 1 if k == 0
  t = powmod(a, k / 2, m)
  t = t * t % m
  t = t * a % m if k % 2 == 1
  return t
end

m = gets.chomp.to_i
ps = gets.chomp.split.map(&:to_i)
mod = 10**9 + 7
n = 1

hs = Hash.new(1)
ps.each do |p|
  hs[p] += 1
  n = n * p % mod
end

cnt = 1
hs.each do |_, v|
  cnt *= v
end

puts powmod(n, cnt / 2, mod)


def check(y,x)
  return 0<=y && y<$n && 0<=x && x<$m && $room[y][x,1]==$c
end

$n,$m,$c=STDIN.gets.chomp.split
$n=$n.to_i
$m=$m.to_i
$room=[]
$n.times {$room<<STDIN.gets.chomp}
desks={}
$n.times {|i|
  $m.times {|j|
    if $room[i][j,1]==$c || $room[i][j,1]=="." then next end
    if check(i,j-1) || check(i,j+1) || check(i-1,j) || check(i+1,j) then
      desks[$room[i][j,1]]=1
    end
  }
}
print(desks.length,"\n")

tmp=gets.chomp.split
n=tmp[0].to_i
m=tmp[1].to_i
c=tmp[2]
memo=Array.new(n)
n.times do |j|
  memo[j]= gets.chomp!.each_char.map{|i| i}
end
ti=0
tj=0
h={}
n.times do |i|
  m.times do |j|
    if memo[i][j]==c
      ti=i
      tj=j
      if ti!=0
        h[memo[ti-1][tj]]=true
      end
      if ti!=n-1
        h[memo[ti+1][tj]]=true
      end
      if tj!=0
        h[memo[ti][tj-1]]=true
      end
      if tj!=m-1
        h[memo[ti][tj+1]]=true
      end
    end
  end
end
h.delete(c)
h.delete(".")
puts h.size

require 'Set'
height,width,color = gets.split
width = width.to_i
height = height.to_i
#p width
#p height
#p color
dh = [-1, 0, 0, 1]
dw = [0, -1, 1, 0]
data = Array.new()
for h in 0...height do
  data[h] = gets
end
ans = Set.new()
ans.add?(color)
for h in 0...height do
  for w in 0...width do
    if data[h][w,1] == color then
      #print h, w
      #puts
      for d in 0...4 do
        nh = h + dh[d]
        nw = w + dw[d]
        if nh >= 0 && nw >= 0 && nh < height && nw < width && data[nh][nw,1] != "." then
          ans.add?(data[nh][nw,1])
        end
      end
    end
  end
end
p ans.size()-1

fst = gets.split
N=fst[0].to_i
M=fst[1].to_i
PresidentsColor=fst[2][0]
matrix = Array.new(N)
N.times do |i|
  line = gets.chomp
  matrix[i] = Array.new(M)
  M.times do |j|
    matrix[i][j] = line[j]
  end
end
deputies = []
matrix.each_index do |i|
  matrix[i].each_with_index do |c,j|
    if c==PresidentsColor
      deputies << matrix[i-1][j] if i!=0
      deputies << matrix[i+1][j] if i!=N-1
      deputies << matrix[i][j-1] if j!=0
      deputies << matrix[i][j+1] if j!=M-1
    end
  end
end
deputies.uniq!
deputies.delete "."[0]
deputies.delete PresidentsColor
puts deputies.size

require 'set'

n, m, p_desk = gets.split
n = n.to_i
m = m.to_i

grid = []
n.times do |index|
	row = gets.chomp.split('')
	grid << row
end

desks = Set.new
0.upto(n - 1) do |x|
	0.upto(m - 1) do |y|
		next if grid[x][y] == ?. or grid[x][y] == p_desk
		desks << grid[x][y] if (x > 0 and grid[x - 1][y] == p_desk) || (y > 0 and grid[x][y - 1] == p_desk) ||
							             (x < n - 1 and grid[x + 1][y] == p_desk) || (y < m - 1 and grid[x][y + 1] == p_desk)
  end
end

puts desks.size

n,m,c = gets.split(/\s+/)
n = n.to_i
m = m.to_i
c = c[0]
a = Array.new(n)
n.times do |i|
  a[i] = gets.strip
end

h = []

0.upto(n-1) do |i|
  0.upto(m-1) do |j|
    next if a[i][j] == ?. or a[i][j] == c
    h << a[i][j] if (i > 0 and a[i-1][j] == c) || (j > 0 and a[i][j-1] == c) ||
                    (i < n-1 and a[i+1][j] == c) || (j < m-1 and a[i][j+1] == c)
  end
end

puts h.uniq.size

def extractIndices(office, color)
  startingCol, endingCol, startingRow, endingRow = -1, -1, -1, -1
  office.each_with_index do |row, rIdx|
    if row.include? color
      if startingRow == -1 #we do this just for the first row
        startingCol = row.find_index(color)
        (startingCol..row.length-1).each do |idx|
          if row[idx] != color
            endingCol = idx-1
            break
          end
        end
        if endingCol == -1
          endingCol = row.length-1
        end
      end
      startingRow = rIdx if startingRow == -1
      endingRow = rIdx if rIdx >= endingRow
    end
  end
  return startingCol, endingCol, startingRow, endingRow
end

n, m, color = nil, nil, nil
office = []
# File.open("input1", "r") do |file|
#   n, m, color = file.readline.split(" ")
#   n = n.to_i
#   m = m.to_i
#   n.times do
#     office << file.readline.chomp.split("")
#   end
# end

n, m, color = gets.chomp.split(" ")
n = n.to_i
m = m.to_i
n.times do
  office << gets.chomp.split("")
end

startingCol, endingCol, startingRow, endingRow = extractIndices(office, color)
topRow = startingRow - 1
bottomRow = endingRow + 1
leftCol = startingCol - 1
rightCol = endingCol + 1
found = []

if topRow >= 0
  topRow = office[topRow][startingCol..endingCol]
  lastFound = "."
  (startingCol..endingCol).each do |idx|
    next if topRow[idx-startingCol] == "." or topRow[idx-startingCol] == lastFound
    lastFound = topRow[idx-startingCol]
    found << lastFound
  end
end

if bottomRow < n
  bottomRow = office[bottomRow][startingCol..endingCol]
  lastFound = "."
  (startingCol..endingCol).each do |idx|
    next if bottomRow[idx-startingCol] == "." or bottomRow[idx-startingCol] == lastFound
    lastFound = bottomRow[idx-startingCol]
    found << lastFound
  end
end

if leftCol >= 0
  leftCol = office[startingRow..endingRow].map{|r| r[leftCol]}
  lastFound = "."
  (startingRow..endingRow).each do |idx|
    next if leftCol[idx-startingRow] == "." or leftCol[idx-startingRow] == lastFound
    lastFound = leftCol[idx-startingRow]
    found << lastFound
  end
end

if rightCol < m
  rightCol = office[startingRow..endingRow].map{|r| r[rightCol]}
  lastFound = "."
  (startingRow..endingRow).each do |idx|
    next if rightCol[idx-startingRow] == "." or rightCol[idx-startingRow] == lastFound
    lastFound = rightCol[idx-startingRow]
    found << lastFound
  end
end

puts "#{found.count}"

n, m, c = gets.chomp.split
n = n.to_i
m = m.to_i
room = Array.new
n.times { room << gets.chomp }
ret = 0
x = Hash.new
dy = [0, -1, 0, 1]
dx = [-1, 0, 1, 0]
x[c] = true
x["."] = true
(0...n).each do |i|
  (0...m).each do |j|
    if room[i][j] == c
      (0...(dy.length)).each do |k|
        ii, jj = i + dy[k], j + dx[k]
        next unless ii >= 0 && ii < n && jj >= 0 && jj < m
        unless x.has_key? room[ii][jj]
          x[room[ii][jj]] = true
          ret += 1
        end
      end
    end
  end
end

puts ret

s = gets.split

n = s[0].to_i
m = s[1].to_i

col = s[2]

dots = []
matrix = []
n.times do |x|
    matrix << gets.chomp
    k = -1
    while k = matrix[x].index(col, k+1) do
        dots << [x, k]
    end
end

t = {}

dots.size.times do |i|
    dot = dots[i]
    if dot[1]+1 < m then
        if matrix[dot[0]][dot[1]+1] != col then
            if t[matrix[dot[0]][dot[1]+1]] then
                t[matrix[dot[0]][dot[1]+1]] += 1
            else
                t[matrix[dot[0]][dot[1]+1]] = 1
            end
        end
    end
    if dot[1] > 0 then
        if matrix[dot[0]][dot[1]-1] != col then
            if t[matrix[dot[0]][dot[1]-1]] then
                t[matrix[dot[0]][dot[1]-1]] += 1
            else
                t[matrix[dot[0]][dot[1]-1]] = 1
            end
        end
    end
    if dot[0]+1 < n then
        if matrix[dot[0]+1][dot[1]] != col then
            if t[matrix[dot[0]+1][dot[1]]] then
                t[matrix[dot[0]+1][dot[1]]] += 1
            else
                t[matrix[dot[0]+1][dot[1]]] = 1
            end
        end
    end
    if dot[0] > 0 then
        if matrix[dot[0]-1][dot[1]] != col
            if t[matrix[dot[0]-1][dot[1]]] then
                t[matrix[dot[0]-1][dot[1]]] += 1
            else
                t[matrix[dot[0]-1][dot[1]]] = 1
            end
        end
    end
end

t.delete(".")

puts t.size

ns,ms,c = gets.chomp.split(/ /)
n = ns.to_i
m = ms.to_i
ar = Array.new
for i in 0..n-1
	ar[i] = gets.chomp.split(//)
end

s = Hash.new

for i in 0..n-1
	for j in 0..m-1
		if ar[i][j] == c
			s[ar[i-1][j]] = 1 if i > 0
			s[ar[i+1][j]] = 1 if i < n-1
			s[ar[i][j-1]] = 1 if j > 0
			s[ar[i][j+1]] = 1 if j < m-1
		end
	end
end

s.delete(c)
s.delete(".")
puts s.length

n, m, c = gets.chomp!.split
n = n.to_i
m = m.to_i
ary = []
hash = {}
n.times {ary << gets.chomp!}
n.times do |i|
	m.times do |j|
		if ary[i][j] == c
			hash[ary[i][j]] = 1
			hash[ary[i - 1][j]] = 1 if i - 1 >= 0
			hash[ary[i + 1][j]] = 1 if i + 1 < n
			hash[ary[i][j - 1]] = 1 if j - 1 >= 0
			hash[ary[i][j + 1]] = 1 if j + 1 < m
		end
	end
end
hash.delete c
hash.delete '.'
puts hash.size

n,m,r=gets.split()
r=r[0]
n=n.to_i
m=m.to_i

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

res=[]
dx=[1,0,-1,0]
for i in 0..n-1
        for j in 0..m-1
                next if map[i][j]!=r
                for k in 0..3
                        nx=i+dx[k]
                        ny=j+dx[k^1]
                        if nx>=0&&nx<n&&ny>=0&&ny<m then
                                res.push(map[nx][ny]) unless map[nx][ny]==r
                        end
                end
        end
end
ans=0

for i in 0..res.length-1
        ok=1
        for j in 0..i-1
                ok=0 if res[i]==res[j]
        end
        next if ok==0||res[i]=="."
        ans+=1
end

p ans

y,x,p = gets.split
y = y.to_i
x = x.to_i

arr = []

y.times do |i|
    line = gets.chomp
    line = line.split(//).join(' ');
    arr[i] = line.split
end
count = 0
exists = []

y.times do |i|
    x.times do |j|
        if arr[i][j] == p
            if  i != 0 && arr[i-1][j] != '.' && arr[i-1][j] != p
                if exists.index(arr[i-1][j]) == nil
                    count = count+1
                    exists << arr[i-1][j]
                end
            end
            if j != 0 && arr[i][j-1] != '.' && arr[i][j-1] != p
                if exists.index(arr[i][j-1]) == nil
                    count = count+1
                    exists << arr[i][j-1]
                end
            end
            if  i != y-1 && arr[i+1][j] != '.' && arr[i+1][j] != p
                if exists.index(arr[i+1][j]) == nil
                    count = count+1
                    exists << arr[i+1][j]
                end
            end
            if j != x-1 && arr[i][j+1] != '.' && arr[i][j+1] != p
                if exists.index(arr[i][j+1]) == nil
                    count = count+1
                    exists << arr[i][j+1]
                end
            end
        end
    end
end
puts count

s = gets.split

n = s[0].to_i
m = s[1].to_i

col = s[2]

i = []
j = []

matrix = []
n.times do |x|
    matrix << gets.chomp
    k = -1
    while k = matrix[x].index(col, k+1) do
        i << x
        j << k
    end
end

i = i.uniq
j = j.uniq

t = {}

i.size.times do |x|
    m.times do |y|
        if matrix[i[x]][y] != col then
            if t[matrix[i[x]][y]] then
                t[matrix[i[x]][y]] += 1
            else
                t[matrix[i[x]][y]] = 1
            end
        end
    end
end

j.size.times do |x|
    n.times do |y|
        if matrix[y][j[x]] != col then
            if t[(matrix[y][j[x]])] then
                t[(matrix[y][j[x]])] += 1
            else
                t[(matrix[y][j[x]])] = 1
            end
        end
    end
end

puts t.size-1

s = gets.split

n = s[0].to_i
m = s[1].to_i

col = s[2]

i = []
j = []

matrix = []
n.times do |x|
    matrix << gets.chomp
    k = -1
    while k = matrix[x].index(col, k+1) do
        i << x
        j << k
    end
end

i = i.uniq
j = j.uniq

t = {}

i.size.times do |x|
    m.times do |y|
        if matrix[i[x]][y] != col then
            if t[matrix[i[x]][y]] then
                t[matrix[i[x]][y]] += 1
            else
                t[matrix[i[x]][y]] = 1
            end
        end
    end
end

j.size.times do |x|
    n.times do |y|
        if matrix[y][j[x]] != col then
            if t[(matrix[y][j[x]])] then
                t[(matrix[y][j[x]])] += 1
            else
                t[(matrix[y][j[x]])] = 1
            end
        end
    end
end

t.delete(".")

puts t.size

s = gets.split

n = s[0].to_i
m = s[1].to_i

col = s[2]

dots = []
matrix = []
n.times do |x|
    matrix << gets.chomp
    k = -1
    while k = matrix[x].index(col, k+1) do
        dots << [x, k]
    end
end

t = {}

dots.size.times do |i|
    dot = dots[i]
    if matrix[dot[0]][dot[1]+1] then
        if matrix[dot[0]][dot[1]+1] != col then
            if t[matrix[dot[0]][dot[1]+1]] then
                t[matrix[dot[0]][dot[1]+1]] += 1
            else
                t[matrix[dot[0]][dot[1]+1]] = 1
            end
        end
    end
    if matrix[dot[0]][dot[1]-1] then
        if matrix[dot[0]][dot[1]-1] != col then
            if t[matrix[dot[0]][dot[1]-1]] then
                t[matrix[dot[0]][dot[1]-1]] += 1
            else
                t[matrix[dot[0]][dot[1]-1]] = 1
            end
        end
    end
    if matrix[dot[0]+1] then
        if matrix[dot[0]+1][dot[1]] != col then
            if t[matrix[dot[0]+1][dot[1]]] then
                t[matrix[dot[0]+1][dot[1]]] += 1
            else
                t[matrix[dot[0]+1][dot[1]]] = 1
            end
        end
    end
    if matrix[dot[0]-1] then
        if matrix[dot[0]-1][dot[1]] != col
            if t[matrix[dot[0]-1][dot[1]]] then
                t[matrix[dot[0]-1][dot[1]]] += 1
            else
                t[matrix[dot[0]-1][dot[1]]] = 1
            end
        end
    end
end

t.delete(".")

puts t.size

n, m, c = gets.chomp!.split
n = n.to_i
m = m.to_i
ary = []
hash = {}
n.times {ary << gets.chomp!}
n.times do |i|
	m.times do |j|
		if ary[i][j] == c
			hash[ary[i][j]] = 1
			hash[ary[i - 1][j]] = 1 if i - 1 >= 0
			hash[ary[i + 1][j]] = 1 if i + 1 < n
			hash[ary[i][j - 1]] = 1 if j - 1 >= 0
			hash[ary[i][j + 1]] = 1 if j + 1 < m
		end
	end
end
puts hash

n,m,r=gets.split()
r=r[0]
n=n.to_i
m=m.to_i

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

res=[]
dx=[1,0,-1,0]
for i in 0..n-1
        for j in 0..m-1
                next if map[i][j]!=r
                for k in 0..3
                        nx=i+dx[k]
                        ny=j+dx[k^1]
                        if nx>=0&&nx<n&&ny>=0&&ny<m then
                                res.push(map[nx][ny]) unless map[nx][ny]==r
                        end
                end
        end
end
ans=0

for i in 0..res.length-1
        ok=1
        for j in 0..i-1
                ok=0 if res[i]==res[j]
        end
        next if ok==0||res[i]=="."
        p res[i]
        ans+=1
end

p ans

tmp=gets.chomp.split
n=tmp[0].to_i
m=tmp[1].to_i
c=tmp[2]
memo=Array.new(n)
n.times do |j|
  memo[j]= gets.chomp!.each_char.map{|i| i}
end
ti=0
tj=0
h={}
n.times do |i|
  m.times do |j|
    if memo[i][j]==c
      ti=i
      tj=j
      if ti!=0 &&memo[ti-1][tj]!="."
        h[memo[ti-1][tj]]=true
      end
      if ti!=n-1&&memo[ti+1][tj]!="."
        h[memo[ti+1][tj]]=true
      end
      if tj!=0 && memo[ti][tj-1]!="."
        h[memo[ti][tj-1]]=true
      end
    end
  end
end
h.delete(c)
puts h.size

require 'Set'
height,width,color = gets.split
width = width.to_i
height = height.to_i
#p width
#p height
#p color
dh = [-1, 0, 0, 1]
dw = [0, -1, 1, 0]
data = Array.new()
for h in 0...height do
  data[h] = gets
end
ans = Set.new()
ans.add?(color)
for h in 0...height do
  for w in 0...width do
    if data[h][w,1] == color then
      #print h, w
      #puts
      for d in 0...4 do
        nh = h + dh[d]
        nw = w + dw[d]
        if nh >= 0 && nw >= 0 && nh < height && nw < width && data[nh][nw,1] != "." then
          ans.add?(data[h-1][w-1,1])
        end
      end
    end
  end
end
p ans.size()-1

def extractIndices(office, color)
  startingCol, endingCol, startingRow, endingRow = -1, -1, -1, -1
  office.each_with_index do |row, rIdx|
    if row.include? color
      if startingRow == -1 #we do this just for the first row
        startingCol = row.find_index(color)
        (startingCol..row.length-1).each do |idx|
          if row[idx] != color
            endingCol = idx-1
            break
          end
        end
        if endingCol == -1
          endingCol = row.length-1
        end
      end
      startingRow = rIdx if startingRow == -1
      endingRow = rIdx if rIdx >= endingRow
    end
  end
  return startingCol, endingCol, startingRow, endingRow
end

n, m, color = nil, nil, nil
office = []
# File.open("input1", "r") do |file|
#   n, m, color = file.readline.split(" ")
#   n = n.to_i
#   m = m.to_i
#   n.times do
#     office << file.readline.chomp.split("")
#   end
# end

n, m, color = gets.chomp.split(" ")
n = n.to_i
m = m.to_i
n.times do
  office << gets.chomp.split("")
end

startingCol, endingCol, startingRow, endingRow = extractIndices(office, color)
topRow = startingRow - 1
bottomRow = endingRow + 1
leftCol = startingCol - 1
rightCol = endingCol + 1
found = []

puts "#{topRow}, #{bottomRow}, #{leftCol}, #{rightCol}"

if topRow >= 0
  topRow = office[topRow][startingCol..endingCol]
  lastFound = "."
  (startingCol..endingCol).each do |idx|
    next if topRow[idx-startingCol] == "." or topRow[idx-startingCol] == lastFound
    lastFound = topRow[idx-startingCol]
    found << lastFound
  end
end

if bottomRow < n
  bottomRow = office[bottomRow][startingCol..endingCol]
  lastFound = "."
  (startingCol..endingCol).each do |idx|
    next if bottomRow[idx-startingCol] == "." or bottomRow[idx-startingCol] == lastFound
    lastFound = bottomRow[idx-startingCol]
    found << lastFound
  end
end

if leftCol >= 0
  leftCol = office[startingRow..endingRow].map{|r| r[leftCol]}
  lastFound = "."
  (startingRow..endingRow).each do |idx|
    next if leftCol[idx-startingRow] == "." or leftCol[idx-startingRow] == lastFound
    lastFound = leftCol[idx-startingRow]
    found << lastFound
  end
end

if rightCol < m
  rightCol = office[startingRow..endingRow].map{|r| r[rightCol]}
  lastFound = "."
  (startingRow..endingRow).each do |idx|
    next if rightCol[idx-startingRow] == "." or rightCol[idx-startingRow] == lastFound
    lastFound = rightCol[idx-startingRow]
    found << lastFound
  end
end

puts "#{found.count}"

def extractIndices(office, color)
  startingCol, endingCol, startingRow, endingRow = -1, -1, -1, -1
  office.each_with_index do |row, rIdx|
    if row.include? color
      if startingRow == -1 #we do this just for the first row
        startingCol = row.find_index(color)
        (startingCol..row.length-1).each do |idx|
          if row[idx] != color
            endingCol = idx-1
          end
        end
        if endingCol == -1
          endingCol = row.length-1
        end
      end
      startingRow = rIdx if startingRow == -1
      endingRow = rIdx if rIdx >= endingRow
    end
  end
  return startingCol, endingCol, startingRow, endingRow
end

n, m, color = nil, nil, nil
office = []
# File.open("input1", "r") do |file|
#   n, m, color = file.readline.split(" ")
#   n = n.to_i
#   m = m.to_i
#   n.times do
#     office << file.readline.chomp.split("")
#   end
# end

n, m, color = gets.chomp.split(" ")
n = n.to_i
m = m.to_i
n.times do
  office << gets.chomp.split("")
end

startingCol, endingCol, startingRow, endingRow = extractIndices(office, color)
topRow = startingRow - 1
bottomRow = endingRow + 1
leftCol = startingCol - 1
rightCol = endingCol + 1
found = []

if topRow >= 0
  topRow = office[topRow][startingCol..endingCol]
  lastFound = "."
  (startingCol..endingCol).each do |idx|
    next if topRow[idx-startingCol] == "." or topRow[idx-startingCol] == lastFound
    lastFound = topRow[idx-startingCol]
    found << lastFound
  end
end

if bottomRow < n
  bottomRow = office[bottomRow][startingCol..endingCol]
  lastFound = "."
  (startingCol..endingCol).each do |idx|
    next if bottomRow[idx-startingCol] == "." or bottomRow[idx-startingCol] == lastFound
    lastFound = bottomRow[idx-startingCol]
    found << lastFound
  end
end

if leftCol >= 0
  leftCol = office[startingRow..endingRow].map{|r| r[leftCol]}
  lastFound = "."
  (startingRow..endingRow).each do |idx|
    next if leftCol[idx-startingRow] == "." or leftCol[idx-startingRow] == lastFound
    lastFound = leftCol[idx-startingRow]
    found << lastFound
  end
end

if rightCol < m
  rightCol = office[startingRow..endingRow].map{|r| r[rightCol]}
  lastFound = "."
  (startingRow..endingRow).each do |idx|
    next if rightCol[idx-startingRow] == "." or rightCol[idx-startingRow] == lastFound
    lastFound = rightCol[idx-startingRow]
    found << lastFound
  end
end

puts "#{found.count}"

def extractIndices(office, color)
  startingCol, endingCol, startingRow, endingRow = -1, -1, -1, -1
  office.each_with_index do |row, rIdx|
    if row.include? color
      if startingRow == -1 #we do this just for the first row
        startingCol = row.find_index(color)
        (startingCol..row.length-1).each do |idx|
          if row[idx] != color
            endingCol = idx-1
          end
        end
        if endingCol == -1
          endingCol = row.length-1
        end
      end
      startingRow = rIdx if startingRow == -1
      endingRow = rIdx if rIdx >= endingRow
    end
  end
  return startingCol, endingCol, startingRow, endingRow
end

n, m, color = nil, nil, nil
office = []
# File.open("input2", "r") do |file|
#   n, m, color = file.readline.split(" ")
#   n = n.to_i
#   m = m.to_i
#   n.times do
#     office << file.readline.chomp.split("")
#   end
# end

n, m, color = gets.chomp.split(" ")
n = n.to_i
m = m.to_i
n.times do
  office << gets.chomp.split("")
end

startingCol, endingCol, startingRow, endingRow = extractIndices(office, color)
topRow = startingRow - 1
bottomRow = endingRow + 1
leftCol = startingCol - 1
rightCol = endingCol + 1
found = []

if topRow >= 0
  topRow = office[topRow][startingCol..endingCol]
  lastFound = "."
  (startingCol..endingCol).each do |idx|
    next if topRow[idx-startingCol] == "." or topRow[idx-startingCol] == lastFound
    lastFound = topRow[idx-startingCol]
    found << lastFound
  end
end

if bottomRow < n
  bottomRow = office[bottomRow][startingCol..endingCol]
  lastFound = "."
  (startingCol..endingCol).each do |idx|
    next if bottomRow[idx-startingCol] == "." or bottomRow[idx-startingCol] == lastFound
    lastFound = bottomRow[idx-startingCol]
    found << lastFound
  end
end

if leftCol >= 0
  leftCol = office[startingRow..endingRow].map{|r| r[leftCol]}
  lastFound = "."
  (startingRow..endingRow).each do |idx|
    next if leftCol[idx-startingRow] == "." or leftCol[startingRow] == lastFound
    lastFound = leftCol[idx]
    found << lastFound
  end
end

if rightCol < m
  rightCol = office[startingRow..endingRow].map{|r| r[rightCol]}
  lastFound = "."
  (startingRow..endingRow).each do |idx|
    next if rightCol[idx-startingRow] == "." or rightCol[startingRow] == lastFound
    lastFound = rightCol[idx]
    found << lastFound
  end
end

puts "#{found.length}"


gets.to_i.times do
  gets
  a = gets.split(" ").map(&:to_i)
  a.sort!

  a[5...a.size-5] = nil
  a.compact!

  best = -999999999999999999999999999999999999999999999999999999999

  (0...a.size).each do |i|
  ((i+1)...a.size).each do |j|
  ((j+1)...a.size).each do |k|
  ((k+1)...a.size).each do |l|
  ((l+1)...a.size).each do |t|
    x = a[i]*a[j]*a[k]*a[l]*a[t]
    best = x if x > best
  end
  end
  end
  end
  end
  p best
end

gets.to_i.times do
  gets
  a = gets.split(" ").map(&:to_i)
  a.sort!

  a[5...a.size-5] = nil
  a.compact!

  best = -9999999999999

  (0...a.size).each do |i|
  ((i+1)...a.size).each do |j|
  ((j+1)...a.size).each do |k|
  ((k+1)...a.size).each do |l|
  ((l+1)...a.size).each do |t|
    x = a[i]*a[j]*a[k]*a[l]*a[t]
    best = x if x > best
  end
  end
  end
  end
  end
  p best
end


la,lb = gets.split(" ").map(&:to_i)
k,m = gets.split(" ").map(&:to_i)

arr = gets.split(" ").map(&:to_i)
brr = gets.split(" ").map(&:to_i)
puts arr[k-1]<brr[-m] ? "YES" : "NO"

la,lb = gets.split(" ").map(&:to_i)
k,m = gets.split(" ").map(&:to_i)

arr = gets.split(" ").map(&:to_i)
brr = gets.split(" ").map(&:to_i)
for i in 0...lb
    if arr[k-1]<brr[i]
        break
    else
        i = lb
    end
end
if (lb-i)>=m
    puts "YES"
else
    puts "NO"
end

n = gets.chomp.split(" ").map!{|val| val=val.to_i}
na=n[0]
nb=n[1]

km = gets.chomp.split(" ").map!{|val| val=val.to_i}
k = km[0]
m = km[1]

Aarray = gets.chomp.split(" ").map! {|val| val=val.to_i}
Barray = gets.chomp.split(" ").map! {|val| val=val.to_i}

puts "YES" if Aarray[k-1] < Barray[nb-m]
puts "NO" unless Aarray[k-1] < Barray[nb-m]

# http://codeforces.com/contest/572/problem/A
x, y = gets.chomp.split.map(&:to_i)
n, m = gets.chomp.split.map(&:to_i)

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

puts a[n - 1] < b[y - m] ? 'YES' : 'NO'

class TaskA
  def initialize
    @nA, @nB = gets.split.map(&:to_i)
    @k, @m = gets.split.map(&:to_i)
    @a = gets.split.map(&:to_i)
    @b = gets.split.map(&:to_i)
  end

  def solve
    if @a[@k-1] < @b[-@m] then
      puts "YES"
    else
      puts "NO"
    end
  end
end

TaskA.new.solve

na, nb = gets.split.map(&:to_i)
k, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)[0..-1]
b = gets.split.map(&:to_i)[0..-1]
if(a[k-1] < b[nb - m])
    puts "YES"
else
    puts "NO"
end

gets
n,m=gets.split.map{|e| e.to_i}
a=gets.split.map{|e| e.to_i}
b=gets.split.map{|e| e.to_i}

puts (a[n-1]<b[b.size-m])?"YES":"NO"

gets
(k, m), a, b = 3.times.map { gets.split(' ').map(&:to_i) }

res = if k <= a.size && m <= b.size && a[k-1] < b[b.size-m]
  "YES"
else
  "NO"
end

puts res

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

q1 = gets.split.map(&:to_i)
q2 = gets.split.map(&:to_i)

puts q1[k-1] < q2[-m] ? "YES" : "NO"

na,nb = gets.split(' ').map(&:to_i)

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

a1 = gets.split(' ').map(&:to_i)
a2 = gets.split(' ').map(&:to_i)

if a1[k-1] < a2[-m]
  puts "YES"
else
   puts "NO"
 end

# coding: utf-8
C = Struct.new(:num, :tag)
na, nb = gets.split.map(&:to_i)
k, m = gets.split.map(&:to_i)
nar = gets.split.map(&:to_i) # non-desc order
nbr = gets.split.map(&:to_i) # non-desc order

if nar[k-1] < nbr[nb - m] # 이미 정렬되어있으므로 마지막에서 세번째 숫자만 비교하면 OK
    puts "YES"
else
    puts "NO"
end

na, nb = gets.chomp.split(' ').map(&:to_i)
k, m = gets.chomp.split(' ').map(&:to_i)
as = gets.chomp.split(' ').map(&:to_i)
bs = gets.chomp.split(' ').map(&:to_i)

puts as[k-1] < bs[nb-m] ? 'YES' : 'NO'

#!/usr/bin/ruby
z,(k,m),A,B=$<.map{|e|e.split.map &:to_i}
puts A.sort[k-1]<B.sort[-m] ? :YES : :NO

na, nb = gets.split.map(&:to_i)
k, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
puts a[k - 1] < b[-m] ? 'YES' : 'NO'

na, nb = gets.split.map(&:to_i)
k, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
bb = b.find_index{|x| x > a[k - 1]}
puts bb && b[bb..-1].size >= m ? 'YES' : 'NO'

na, nb = gets.split.map(&:to_i)
k, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
bb = b.find_index{|x| x > a[k - 1]}
c = []
c = b[bb..-1] if bb
puts c.size >= m ? 'YES' : 'NO'

nA,nB = gets.split.map(&:to_i)
k,m = gets.split.map(&:to_i)
x = gets.split.map(&:to_i)
y = gets.split.map(&:to_i)
puts x[(k-1)] < y[(nB - m)] ? "YES" : "NO"

n1, n2 = gets.split.map(&:to_i)
k, m = gets.split.map(&:to_i)
array1 = gets.split.map(&:to_i)
array2 = gets.split.map(&:to_i)
puts array1[k-1 ] < array2[n2 - m] ? 'YES' : 'NO'

# Ý tưởng:
# Để có khả năng k số trong array a luôn nhỏ hơn m số trong mảng b
# thì ta phải luôn chọn k số nhỏ nhất trong mảng a và m số lớn nhất trong b.
# Nói cách khác, ta phải luôn chọn k số đầu tiên ở a và m số cuối cùng ở b.
# Sau đó ta so sánh số lớn nhất được chọn trong k số ở a và số nhỏ nhất được chọn trong m số ở b.
# Nếu số lớn nhất trong k số đó nhỏ hơn số nhỏ nhất trong m số kia thì kết quả luôn là “YES”, ngược lại là “NO”

size_a, size_b = gets.chomp.split.map(&:to_i)
k, m = gets.chomp.split.map(&:to_i)

array_a = gets.chomp.split.map(&:to_i)
array_b = gets.chomp.split.map(&:to_i)

puts array_a[k - 1] < array_b[-m] ? "YES" : "NO"

def checks(sizes, selections, array_1, array_2)
  selections = selections.split.map(&:to_i)
  array_1 = array_1.split.map(&:to_i)
  array_2 = array_2.split.map(&:to_i)
  puts array_1.sort.first(selections[0]).max < array_2.sort.last(selections[1]).min ? 'YES' : 'NO'
end
checks(gets, gets, gets, gets)

# Array1: Find min elements base on selection after that find max element
# Array2: Find max elements base on selection after that find min element
# Condition value of 2 array if array 1 < array 2 then print 'Yes' otherwise print 'No'

#!/usr/bin/ruby

# def qselect(a, b, k, m)
#   def qloc(a, b)
#     l = a.length
#     return -1 if b <= a[0]
#     return l if b > a[-1]
#     i = 0
#     loop do
#       break -1 if i < 0 or i >= l
#       break i if a[i+1] and b > a[i] and b <= a[i+1]
#       break i if not a[i+1] and b > a[i]
#       i = b > a[i] ? (l + i + 1) / 2 : i / 2
#     end
#   end
#   return false if k > a.length or m > b.length
#   p = qloc(a, b[-m])
#   k <= p + 1
# end

def algo
  gets
  k, m = gets.split(' ').map { |e| e.to_i }
  a = gets.split(' ').map { |e| e.to_i }
  b = gets.split(' ').map { |e| e.to_i }
  # puts qselect(a, b, k, m) ? "YES" : "NO"
  puts b[-m] > a[k-1] ? "YES" : "NO"
end

algo

def checks(sizes, selections, array_1, array_2)
  selections = selections.split(' ').map(&:to_i)
  array_1 = array_1.split(' ').map(&:to_i)
  array_2 = array_2.split(' ').map(&:to_i)

  max_1 = array_1.sort.first(selections[0]).max
  max_2 = array_2.sort.last(selections[1]).min

  if max_1 < max_2
    r = 'YES'
  else
    r = 'NO'
  end
  puts r
end
checks(gets.chomp, gets.chomp, gets.chomp, gets.chomp)

def checks(sizes, selections, array_1, array_2)
  selections = selections
  array_1 = array_1.split
  array_2 = array_2.split
  puts 1 < 2 ? 'YES' : 'NO'
end
checks(gets.chomp, gets.chomp, gets.chomp, gets.chomp)

la,lb = gets.split(" ").map(&:to_i)
k,m = gets.split(" ").map(&:to_i)

arr = gets.split(" ").map(&:to_i)
brr = gets.split(" ").map(&:to_i)
for i in 0...lb
    if arr[k-1]<brr[i]
        break
    end
end
if (lb-(i+1))>=m
    puts "YES"
else
    puts "NO"
end

la,lb = gets.split(" ").map(&:to_i)
k,m = gets.split(" ").map(&:to_i)

arr = gets.split(" ").map(&:to_i)
brr = gets.split(" ").map(&:to_i)
if k<=la && m<=lb && arr[k-1]<brr[0]
    puts "YES"
else
    puts "NO"
end

la,lb = gets.split(" ").map(&:to_i)
k,m = gets.split(" ").map(&:to_i)

arr = gets.split(" ").map(&:to_i)
brr = gets.split(" ").map(&:to_i)
for i in 0...lb
    if arr[k-1]<brr[i]
        break
    end
end
if (lb-i)>=m
    puts "YES"
else
    puts "NO"
end

na,nb = gets.split(' ').map(&:to_i)

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

a1 = gets.split(' ').map(&:to_i)
a2 = gets.split(' ').map(&:to_i)

if a1[k-1] < a2[0]
  puts "YES"
else
   puts "NO"
 end

na, nb = gets.split.map(&:to_i)
k, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
bb = b.find_index{|x| x > a[k - 1]}
puts b[(bb || 0)..-1].size >= m ? 'YES' : 'NO'

skip = gets.chomp.to_i
number_choose = gets.split.map(&:to_i)
arrayA = gets.split.map(&:to_i)
arrayB = gets.split.map(&:to_i)
choosenA = arrayA.last(number_choose[0])
minB = arrayB.first(number_choose[1]).min
puts choosenA.all?{|x| x < minB}  ? 'YES' : 'NO'

skip = gets.chomp
select_numbers = gets.split.map(&:to_i)
array1 = gets.split.map(&:to_i)
array2 = gets.split.map(&:to_i)
count = 0
array = array1 + array2
(array1.length...array.length).each do|index|
  if array[index] <= array[index-1]
    count = index
    break
  end
end

puts ( count > select_numbers.max) ? 'YES' : 'NO'

skip = gets.chomp
select_numbers = gets.split.map(&:to_i)
array1 = gets.split.map(&:to_i)
array2 = gets.split.map(&:to_i)
count = 0
array = array1 + array2
(1...array.length).each do|index|
  if array[index] <= array[index-1]
    count = index
    break
  end
end
puts ( count > select_numbers.max) ? 'YES' : 'NO'

skip = gets.chomp.to_i
number_choosens = gets.split.map(&:to_i)
arrayA = gets.split.map(&:to_i)
arrayB = gets.split.map(&:to_i)
possile_of_a = arrayA.select{|x| x < arrayB.min}
possile_of_b = arrayB.select{|x| x > arrayA.max}
puts (possile_of_a.size >= number_choosens[0] && possile_of_b.size >= number_choosens[1]) ? 'YES' : 'NO'

#!/usr/bin/ruby

def qselect(a, b, k, m)
  def qloc(a, b)
    l = a.length
    i = 0
    loop do
      break -1 if i < 0 or i >= l
      break i if a[i+1] and b > a[i] and b <= a[i+1]
      break i if not a[i+1] and b > a[i]
      i = b >= a[i] ? (l + i + 1) / 2 : (i - 1) / 2
    end
  end

  p = qloc(a, b[0])
  return false if p < 0
  k <= p + 1 && m <= b.length
end

def algo
  gets
  k, m = gets.split(' ').map { |e| e.to_i }
  a = gets.split(' ').map { |e| e.to_i }
  b = gets.split(' ').map { |e| e.to_i }
  puts qselect(a, b, k, m) ? "YES" : "NO"
end

algo

#!/usr/bin/ruby

# def qselect(a, b, k, m)
#   def qloc(a, b)
#     l = a.length
#     return -1 if b <= a[0]
#     return l if b > a[-1]
#     i = 0
#     loop do
#       break -1 if i < 0 or i >= l
#       break i if a[i+1] and b > a[i] and b <= a[i+1]
#       break i if not a[i+1] and b > a[i]
#       i = b > a[i] ? (l + i + 1) / 2 : i / 2
#     end
#   end
#   return false if k > a.length or m > b.length
#   p = qloc(a, b[-m])
#   k <= p + 1
# end

def algo
  gets
  k, m = gets.split(' ').map { |e| e.to_i }
  a = gets.split(' ').map { |e| e.to_i }
  b = gets.split(' ').map { |e| e.to_i }
  # puts qselect(a, b, k, m) ? "YES" : "NO"
  puts b[-m] > a[-k] ? "YES" : "NO"
end

algo

#!/usr/bin/ruby

def qselect(a, b, k, m)
  def qloc(a, b)
    l = a.length
    return -1 if b <= a[0]
    return l if b > a[-1]
    i = 0
    loop do
      break -1 if i < 0 or i >= l
      break i if a[i+1] and b > a[i] and b <= a[i+1]
      break i if not a[i+1] and b > a[i]
      i = b > a[i] ? (l + i + 1) / 2 : i / 2
    end
  end

  p = qloc(a, b[0])
  return false if p < 0
  k <= p + 1 && m <= b.length
end

def algo
  gets
  k, m = gets.split(' ').map { |e| e.to_i }
  a = gets.split(' ').map { |e| e.to_i }
  b = gets.split(' ').map { |e| e.to_i }
  puts qselect(a, b, k, m) ? "YES" : "NO"
end

algo

def checks(sizes, selections, array_1, array_2)
  selections = selections
  puts 1 < 2 ? 'YES' : 'NO'
end
checks(gets.chomp, gets.chomp, gets.chomp, gets.chomp)

def checks(sizes, selections, array_1, array_2)

  puts 'YES'
end
checks(gets.chomp, gets.chomp, gets.chomp, gets.chomp)


gets.to_i.times{
    a,b=gets.split
    puts a.to_i*b.to_i
}

t = gets.chomp.to_i
t.times do
	a,b = gets.split()
	p a.to_i*b.to_i
end


t = gets.chomp.to_i
t.times do
    n = gets.chomp.to_i
    a = gets.chomp.split(" ")
    number_zero = a.count("0")
    number_ichi = n - number_zero
    if number_zero >= number_ichi
        a.delete("1")
        puts a.size
        puts a.join(" ")
    else
        a.delete("0")
        ookisa = a.size
        if ookisa % 2 == 0
            puts a.size
            puts a.join(" ")
        else
            a.pop
            puts a.size
            puts a.join(" ")
        end
    end
end

T = gets.to_i

T.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  rui_e = [0]
  rui_o = [0]

  a.each_with_index do |x, i|
    if i.even?
      rui_e << rui_e.last + x
      rui_o << rui_o.last
    else
      rui_e << rui_e.last
      rui_o << rui_o.last + x
    end
  end

  idx = -1

  n.times do |i|
    v1 = (rui_e[i] - rui_e[0]) + (rui_o[n] - rui_o[i + 1])
    v2 = (rui_o[i] - rui_o[0]) + (rui_e[n] - rui_e[i + 1])

    if v1 == v2
      idx = i
      break
    end
  end

  if idx != -1
    a.delete_at(idx)
  end

  puts a.size
  puts a.join(' ')
end

T = gets.to_i

T.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  s = a.sum
  t = s / 2
  ans = []
  sum = [0, 0]

  if n <= 2
    puts 1
    puts 0
    next
  end

  until a.empty?
    x = a.shift

    if ans.size.even?
      next if x + sum[0] > t

      sum[0] += x
      ans << x
    else
      next if x + sum[1] > t

      sum[1] += x
      ans << x
    end
  end

  puts ans.size
  puts ans.join(' ')
end

t = gets.chomp.to_i
t.times do
    n = gets.chomp.to_i
    a = gets.chomp.split(" ")
    number_zero = a.count("0")
    number_ichi = n - number_zero
    if number_zero >= number_ichi
        a.delete("1")
        puts a.join(" ")
    else
        a.delete("0")
        ookisa = a.size
        if ookisa % 2 == 0
            puts a.join(" ")
        else
            a.pop
            puts a.join(" ")
        end
    end
end

T = gets.to_i

T.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  s = a.sum
  t = s / 2
  ans = []
  sum = [0, 0]

  until a.empty?
    x = a.shift

    if ans.size.even?
      next if x + sum[0] > t

      sum[0] += x
      ans << x
    else
      next if x + sum[1] > t

      sum[1] += x
      ans << x
    end
  end

  puts ans.size
  puts ans.join(' ')
end

T = gets.to_i

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

  counter = a.tally
  counter.default = 0

  if counter[0] >= 1
    puts 1
    puts 0
  elsif counter[1] >= 2
    puts 2
    puts "1 1"
  end
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]
a = inp
b = inp
table = na(n)
encoded = na(n)
n.times do |i|
  encoded[a[i]-1] = i
end

pl = 0
ans = 0
i = 0
while i < n
  if(table[i] == 1)
    pl -= 1
    i += 1
    next
  end
  if(a[i] != b[i+pl])
    ans += 1
    table[encoded[b[i+pl]-1]] = 1
    pl +=1
  else
    i += 1
  end
end
p ans

n = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
out = [false]*(n+1)

ans = 0
j = 0
n.times do |i|
  if !out[a[i]]
    while b[j] != a[i]
      out[b[j]] = true
      j += 1
      ans += 1
    end
    out[b[j]] = true
    j += 1
  end
end
p ans


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

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
q=gi
q.times do
  bat,turn,a,b=gsmi

  if bat <= turn*b
    puts -1
    next
  end

  b_bat = bat - turn*b
  puts [(b_bat-1)/(a-b),turn,((bat-a).to_f/a).ceil].min
end

q = gets.chomp.to_i

for ii in 1..q
  (k, n, a, b) = gets.chomp.split(" ").map {|aaa| aaa.to_i}
  _min = n*b
  k -= 1
  d = a-b
  if _min > k
    print -1
  else
    _max = (k -_min)/d
    print _max > n ? n : _max
  end
  print "\n"
end

q = gets.to_i
(1..q).each do
  res = 0
  read = gets.split(" ").map{|c| c.to_i}
  k = read[0]
  n = read[1]
  a = read[2]
  b = read[3]
  if n * b >= k
    res = -1
  else
    l = 0
    r = n
    while l < r
      m = (l + r + 1)/2
      if m * a + (n - m) * b < k
        l = m
      else
        r = m - 1
      end
    end
    res = l
  end
  puts res
end

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

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
q=gi
q.times do
  bat,turn,a,b=gsmi

  if bat <= turn*b
    puts -1
    next
  end

  b_bat = bat - turn*b
  puts [b_bat/(a-b),turn,((bat-a).to_f/a).ceil].min
end


#!/usr/bin/env ruby

n=gets.chomp.to_i
str=[]
n.times{str.push(gets.chomp)}

str.sort!{|l, r| l.size<=>r.size}

(n-1).downto 1 do |i|
  s, t=str[i-1], str[i]
  if t.index(s).nil?
    puts 'NO'
    exit 0
  end
end

puts 'YES'
puts str.join("\n")

n = gets.to_i
s = (1..n).map { gets.chomp }.sort_by(&:size)
if s.each_cons(2).all? { |s, t| (0...t.size).any? { |i| s == t[i, s.size] } }
	puts 'YES', s.join("\n")
else
	puts 'NO'
end

n = gets.to_i
ar = []
n.times {ar << gets.chomp}
ar.sort!{|a,b| a.size <=> b.size}
n.times do |i|
  next if i == 0
  s = ar[i]
  s0 = ar[i-1]
  if !s.include? s0
    puts "NO"
    exit 0
  end
end
puts "YES"
puts ar

n = gets.to_i
a = []
for i in 0..n-1
      x = gets.chomp
      a.push(x)
      end
y = a.sort_by(&:length)
v = 1
for i in 0..n-2
      if y[i+1].include?y[i] or y[i+1] == y[i]
       v += 1
     end
  end
if v != a.length
   puts "NO"
else
   puts "YES"
   for i in 0..a.length-1
      puts "#{y[i]}"
      end
  end


n, p = gets.split(/\s+/).map(&:to_i)
s = gets.strip

def get_next(s, n, p)
  if n == 1
    if s[0].ord == p.ord
      nil
    else
      s[0].succ
    end
  else
    q = s[-1] == 'z' ? '{' : s[-1].succ
    x = s[0...-1]
    begin
      while q.ord <= p.ord && (q == x[-1] || q == x[-2])
        q = q == 'z' ? '{' : q.succ
      end

      if q.ord <= p.ord
        return "#{x}#{q}"
      else
        x = get_next(x, n-1, p)
        q = 'a'
      end
    end while x

    nil
  end
end

p = ('a'.ord + p.ord-1).chr

if (s = get_next(s, n, p))
  puts s
else
  puts "NO"
end

def fill_string(string, i, max_ord)
  (i...string.size).each do |i|
    ('a'.ord..max_ord).each { |j|
      if (i-1<0 || j.chr != string[i-1]) && (i-2<0 || j.chr != string[i-2])
        string[i] = j.chr
        break
      end
    }
  end
  string
end

p = gets.split[1].to_i + 'a'.ord - 1
string = gets[0..-2]
no = true
(0...string.size).reverse_each do |i|
  (string[i].ord+1..p).each do |j|
    if (i-1<0 || j.chr != string[i-1]) && (i-2<0 || j.chr != string[i-2])
      string[i] = j.chr
      puts fill_string string, i+1, p
      no = false
      break
    end
  end
  break unless no
end

puts "NO" if no


a=gets.chomp.split(" ").map{|i| i.to_i}
b=gets.chomp.split(" ")

maxind=0
z=0
max=0
p=0
sq=0

if a[1]>0
0.upto(a[0]-1) do |i|

	if i>0
	sq=sq-1
	if b[i-1]=="0"
	z=z-1
	else
	z=z
	end
	end

  loop do
    break if p>=a[0]
    if b[p]=="0"
        z+=1
    end
	break if z>a[1]
        sq+=1
		p+=1
    end
     z-=1
    if sq>max
        max=sq
        maxind=i
    end

	break if p==a[0]
end
   k=0
loop do
	break if maxind==a[0]
	break if k==a[1]
    if b[maxind]=="0"
        b[maxind]="1"
        k+=1
    end
	 maxind +=1
end
puts "#{max}"
puts b.join(" ")

else

sq=0
b.each do |i|
if i== "0"
if sq>max
max=sq
end
sq=0
else
sq+=1
end
end
if sq>max
max=sq
end
puts "#{max}"
puts b.join(" ")

end

buf=gets.split(' ')
n,k=buf[0].to_i, buf[1].to_i
t=k
a=gets.split(' ')
r=ma=st=0
for l in 0..n-1
	k+=1 if l>0 && a[l-1]=='0'
	while r<n && (a[r]=='1' || k>0)
		k-=1 if a[r]=='0'
		r+=1
	end
	ma,st=r-l,l if r-l>ma
end
puts ma
while st<n && t>=0
	break if t<1 && a[st]==?0
	t-=1 if a[st]==?0
	a[st]=?1
	st+=1
end
puts a*" "

a=gets.chomp.split(" ").map{|i| i.to_i}
b=gets.chomp.split(" ")
maxind=0
max=0
0.upto(a[0]-2) do |i|
	p=0
    p=i
    sq=0
    z=0
    loop do
    if b[p]=="0"
        z+=1
    end
       p+=1
	break if p==a[0]
    break if z>a[1]
        sq+=1
    end
    if sq>max
        max=sq
        maxind=i
    end
end

k=0
loop do
    if b[maxind]=="0"
        b[maxind]="1"
        k+=1
    end
	 maxind +=1

    break if k==a[1]
end
puts "#{max}"
puts b.join(" ")


k = gets.to_i
k.times do
  n = gets.to_i
  as = gets.split.map(&:to_i).sort.reverse
  ans = 0
  as.each_with_index do |a, i|
    if a > ans
      ans += 1
    end
  end
  puts ans
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 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

q = inp[0]
q.times do
  n = inp[0]
  t = inp
  t.sort!.reverse!
  ans = 0
  n.times do |i|
    ans = [ans,[t[i],(i+1)].min].max
  end
  p ans
end

g = gets.chomp.to_i
g.times{
n = gets.to_i
max = 0
doski = gets.split(" ").map{|x|x.to_i}
jj = (1...1001).to_a
jj.map{|w|
q=0
doski.map{|e| if e >= w then q+=1 end}
if q >= w and max < w then max =  w end
}
puts max
}

g = gets.chomp.to_i
g.times{
n = gets.to_i
max = 0
doski = gets.split(" ").map{|x|x.to_i}
jj = (1...1000).to_a
jj.map{|w|
q=0
doski.map{|e| if e >= w then q+=1 end}
if q >= w and max < w then max =  w end
}
puts max
}


ans,a=0,Array.new(100,0)
gets.to_i.times do |i|
	l,r=gets.chomp.split.map(&:to_i)
	for j in l...r
		a[j]=i==0
	end
end
puts a.count(true)

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

# (n-1).times do
# 	l,r = gets.split(" ").map(&:to_i)
# 	x,y = l+1,r-1
# 	# x,y = y,x if x > y
# 	if l + 1 == r
# 		# puts "here"
# 		alex -= [l]
# 	else
# 		alex -= (x..y).to_a
# 	end
# end
# length = 0
# (1..alex.length-1).each do |i|
# 	if (alex[i-1] + 1 == alex[i]) || (alex[i+1] && alex[i]+1 != alex[i+1])
# 		puts alex[i]
# 		length += 1
# 	end
# end
# puts "#{alex}"
# puts length
used = Array.new(100,true)

(n-1).times do
	l,r = gets.split(" ").map(&:to_i)
	(l..r-1).each do |i|
		used[i] = false
	end
end
puts "#{used[alex_l..alex_r-1].count(true)}"

class Array
	def f x
		self[0] - 1 < x && x < self[1]
	end
end

n = gets.to_i
l, r = gets.split.map(&:to_i)
seg = []
(n-1).times{seg<<gets.split.map(&:to_i)}
tot = 0
l.upto(r-1){|i| tot+=1 if !seg.any?{|s|s.f(i)}}
p tot

n = gets.to_i
l,r = gets.split(" ").map(&:to_i)
alex = (l..r).to_a
(n-1).times do
	l,r = gets.split(" ").map(&:to_i)
	alex -= (l+1..r-1).to_a
end
length = 0
(1..alex.length-1).each do |i|
	length += 1 if alex[i-1] + 1 == alex[i]
end

puts length

n = gets.to_i
l,r = gets.split(" ").map(&:to_i)
alex = (l..r).to_a
(n-1).times do
	l,r = gets.split(" ").map(&:to_i)
	x,y = l+1,r-1
	# x,y = y,x if x > y
	if l + 1 == r
		# puts "here"
		alex -= [l]
	else
		alex -= (x..y).to_a
	end
end
length = 0
(1..alex.length-1).each do |i|
	length += 1 if alex[i-1] + 1 == alex[i]
end
# puts "#{alex}"
puts length


shokti = {"purple"=>"Power", "green"=> "Time" , "blue"=>"Space" ,"orange"=> "Soul" , "red"=> "Reality" , "yellow"=> "Mind"}
shoktiray = ["purple","green","blue","orange","red","yellow"]

s = gets.to_i
a = []

for i in 0..s-1
    b = gets.chomp
    a.push(b)
end
notun = shoktiray - a
puts notun.length

notun.each{|k|
   puts shokti[k]
}

gems = {}
gems['purple'] = 'Power'
gems['green'] = 'Time'
gems['blue'] = 'Space'
gems['orange'] = 'Soul'
gems['red'] = 'Reality'
gems['yellow'] = 'Mind'

len = gets.to_i
0.upto(len-1) do
  word = gets.chomp
  gems.delete(word)
end

puts gems.values.count
gems.values.each{|val|
  if val != nil
    puts val
  end
}

n = gets.to_i
c = []
n.times{c << gets.strip}
h = {
  'purple' => 'Power',
  'green'  => 'Time',
  'blue'   => 'Space',
  'orange' => 'Soul',
  'red'    => 'Reality',
  'yellow' => 'Mind'
}
ans = []
h.each{|k, v| ans << v unless c.any?{|x| x == k}}
p ans.size
ans.each{|x| puts x}

#purple, green, blue,  orange, red,     yellow
#Power , Time,  Space, Soul,   Reality, Mind

arr = ["Power" , "Time",  "Space", "Soul",   "Reality", "Mind"]

a = gets.to_i

size = 6

for i in 0..a-1
	tmp = gets.chomp

	if(tmp == "purple")
		arr[0] = ""
		size -=1
	elsif (tmp == "green")
		arr[1] = ""
		size -=1
	elsif (tmp == "blue")
		arr[2] = ""
		size -=1
	elsif (tmp == "orange")
		arr[3] = ""
		size -=1
	elsif (tmp == "red")
		arr[4] = ""
		size -=1
	elsif (tmp == "yellow")
		arr[5] = ""
		size -=1

	end
end

puts (size)

for i in 0..6
	if(arr[i] == "")
		next
	else
		puts arr[i]
	end
end

h={}
h['purple']='Power'
h['green']='Time'
h['blue']='Space'
h['orange']='Soul'
h['red']='Reality'
h['yellow']='Mind'

n=gets.chomp.to_i
n.times do
  s=gets.chomp
  h.delete(s)
end

puts h.size
h.values.each do |s|
  puts s
end

g = Hash.new
g['red'] = "Reality"
g['purple'] = "Power"
g['orange'] = "Soul"
g['yellow'] = "Mind"
g['blue'] = "Space"
g['green'] = "Time"

number = gets.to_i
number.times{
	s = gets.chomp
	g.delete(s)
}

puts g.length
g.each{
	|k, v|
	puts v
}

N = gets.to_i
hash = {
    'purple' => 'Power',
    'green' => 'Time',
    'blue' => 'Space',
    'orange' => 'Soul',
    'red' => 'Reality',
    'yellow' => 'Mind'
}

N.times do
    str = gets.chomp
    hash.delete(str)
end
puts hash.length, hash.values

n = gets.to_i
as = []

gems = Hash.new
gems['purple'] = 'Power'
gems['green'] = 'Time'
gems['blue'] = 'Space'
gems['orange'] = 'Soul'
gems['red'] = 'Reality'
gems['yellow'] = 'Mind'

n.times do
  as << gets.chomp
end

gems.reject! { |k, v| as.include?(k) }
puts gems.size
puts gems.values

s = %w(the Power Gem of purple color,
the Time Gem of green color,
the Space Gem of blue color,
the Soul Gem of orange color,
the Reality Gem of red color,
the Mind Gem of yellow color.)

t = (0...6).map { |i| [s[6 * i + 4], s[6 * i + 1]] }

n = gets.to_i
cols = (0...n).map { gets.strip }
cnt = {}
cols.each do |c|
  cnt[c] = 1
end
a = []
(0...6).each do |i|
  a << t[i][1] if cnt[t[i][0]].nil?
end
p a.size
puts a.join ?\n

gems = {}
gems['purple'] = 'Power'
gems['green'] = 'Time'
gems['blue'] = 'Space'
gems['orange'] = 'Soul'
gems['red'] = 'Reality'
gems['yellow'] = 'Mind'

len = gets.to_i
0.upto(len-1) do
  word = gets.chomp
  gems[word] = nil
end

puts gems.values.count
gems.values.each{|val|
  if val != nil
    puts val
  end
}
puts ''


_,a,b=$<.map{|s|s.split.map(&:to_i).sort.reverse}
puts a.zip(b).any?{|c,d|d.nil?||c>d}?:YES: :NO

a,b,c = gets.chomp.split(" ").map{|v| v.to_i}
khanh = gets.chomp.split(" ").map{|v| v.to_i}
huy= gets.chomp.split(" ").map{|a| a.to_i}

khanh = khanh.sort.reverse!
huy = huy.sort.reverse!

result = "NO"
if khanh.length > huy.length
  result = "YES"
else
  stop = false
  i = 0
  while i < khanh.length && !stop do
    if khanh[i] > huy[i]
      result = "YES"
      stop = true
    elsif
      i = i + 1
    end
 end
end

puts result

n,m=gets.split.map(&:to_i)
a=gets.split.map(&:to_i).sort!
b=gets.split.map(&:to_i).sort!
p=0
n.times{ |i|
	while p<m&&b[p]<a[i]
		p+=1
	end
	if n-i>m-p
		puts 'YES'
		exit
	end
}
puts 'NO'

_,a,b=$<.map{|s|s.split.map(&:to_i).sort.reverse}
puts a.size>b.size||a.zip(b).any?{|c,d|c>d}?:YES: :NO

_,a,b=(1..3).map{gets.split.map(&:to_i).sort.reverse}
puts a.size>b.size||a.zip(b).any?{|c,d|c>d}?:YES: :NO

gets
a=[0]+gets.split.map(&:to_i).sort
b=[0]+gets.split.map(&:to_i).sort
(1..[a.size,b.size].min).each{|i|exit !(puts"YES")if a[-i]>b[-i]}
puts"NO"

gets
a=gets.split.map(&:to_i).sort
b=gets.split.map(&:to_i).sort
(1..[a.size,b.size].min).each{|i|exit !(puts"YES")if a[-i]>b[-i]}
puts"NO"

gets
a=gets.split.map(&:to_i).sort.reverse
b=gets.split.map(&:to_i).sort.reverse
(0...[a.size,b.size].min).each{|i|exit !(puts"YES")if a[i]>b[i]}
puts"NO"

a,b,c = gets.chomp.split(" ").map{|v| v.to_i}
khanh = gets.chomp.split(" ").map{|v| v.to_i}
huy= gets.chomp.split(" ").map{|a| a.to_i}

khanh = khanh.reverse!
huy = huy.reverse!

result = "NO"
if khanh.length > huy.length
  result = "YES"
else
  stop = false
  i = 0
  while i < khanh.length && !stop do
    if khanh[i] > huy[i]
      result = "YES"
      stop = true
    elsif
      i = i + 1
    end
 end
end

puts result


n, m = gets.split.map(&:to_i)
a = []
m.times do
	a << gets.split.map(&:to_i)
end
s = 0
1.upto(n) do |i|
	b = 0
	d = -1
	a.each do |l, r, t, c|
		next if i < l || i > r
		if d == -1 || t < d
			d = t
			b = c
		end
	end
	s += b
end
p s

n, m = gets.split.map(&:to_i)
arr = Array.new(n) { [] }
m.times do |j|
  l, r, t, c = gets.split.map(&:to_i)
  (l..r).each { |i| arr[i - 1] << [j, t, c] }
end

max_profit = 0
arr.each do |t|
  if !t.empty?
    t.sort! { |a, b| (a[1] == b[1]) ? a[0] <=> b[0] : a[1] <=> b[1] }
    max_profit += t[0][2]
  end
end

puts max_profit

n,m=gets.split.map(&:to_i)
comp=[]
time=Array.new(n){[9999999,0]}
m.times{
        l,r,t,c=gets.split.map(&:to_i)
        for k in (l-1)..(r-1)
                if time[k][0]>t then
                        time[k][0]=t
                        time[k][1]=c
                end
        end
}
ans=0
n.times{|i|
        ans+=time[i][1]
}
p ans

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

sections = []

n.times do
	sections << []
end

time = {}
cost = {}

m.times do |i|
	l,r,t,c = gets.split(" ").map(&:to_i)

	(l..r).each do |j|
		sections[j-1] << i + 1
	end

	time[i+1] = t
	cost[i+1] = c
end

winner = []

# puts "#{sections}"
sections.each do |a|

	min_time = time[a[0]]
	min_ind = a[0]

	a.each_with_index do |x,i|
		# puts "x #{x} #{min_time}"
		if time[x] < min_time
			# puts "mitim #{min_time}"
			min_time = time[x]
			min_ind = x
		end
	end

	winner << min_ind
end

# puts "#{time}"
# puts "#{cost}"
# puts "#{winner}"
puts winner.compact.inject(0){|s,a| s += cost[a] }

n, m = gets.split.map(&:to_i)
a = [0]*(n+1)
tt = []
m.times do
  l, r, t, c = gets.split.map(&:to_i)
  l.upto(r) do |i|
    if !tt[i] || t < tt[i]
      tt[i] = t
      a[i] = c
    end
  end
  #p a, tt
end
p a.inject(0){|r,j| r+j}

n, m = gets.split.map(&:to_i)
a = [0]*(n+1)
tt = [2000]*(n+1)
m.times do
  l, r, t, c = gets.split.map(&:to_i)
  #p [l,r,t,c]
  l.upto(r) do |i|
    #p [i, tt[i], a[i]]
    if t < tt[i] || (t == tt[i] && a[i] < c)
      tt[i] = t
      a[i] = c
    end
  end
end
p a.inject(0){|r,j| r+j}


t = gets.to_i
ans = []
t.times do
  x1,y1,x2,y2 = gets.chomp.split(" ").map(&:to_i)
  x = (x2-x1).abs + (y2-y1).abs
  if x1 != x2 && y1 != y2
    x += 2
  end
  ans << x
end
ans.each do |v|
  puts v
end

T = gets.to_i

T.times do
  x1, y1, x2, y2 = gets.split.map(&:to_i)

  dx = (x2 - x1).abs
  dy = (y2 - y1).abs

  if dx == 0 && dy == 0
    puts 0
  elsif dx == 0
    puts dy
  elsif dy == 0
    puts dx
  else
    puts dx + dy + 2
  end
end

t = gets.chomp.to_i
sa = 0
t.times do
    a, b, c, d = gets.chomp.split(" ").map(&:to_i)
    sa = 0
    if a == c || b == d
        puts (c-a).abs + (d-b).abs
    else
        sa = (c-a).abs + (d-b).abs + 2
        puts sa
    end
end

gets.to_i.times do
    x1, y1, x2, y2 = gets.split.map &:to_i
    puts (x2 - x1).abs + (y2 - y1).abs + (x1 == x2 || y1 == y2 ? 0 : 2)
end

t = gets.chomp.to_i
sa = 0
t.times do
    a, b, c, d = gets.chomp.split(" ").map(&:to_i)
    sa = (a-c).abs + (b-d).abs
    puts sa
end

t = gets.chomp.to_i
sa = 0
t.times do
    a, b, c, d = gets.chomp.split(" ").map(&:to_i)
    sa = 0
    if a == c || b == d
        puts (c-a).abs + (d-b).abs
    else
        sa = (c-a).abs + (d-b).abs + 3
        puts sa
    end
end

gets.to_i.times do
    x1, y1, x2, y2 = gets.split.map &:to_i
    puts (x2 - x1).abs - (y2 - y1).abs + x1 == x2 || y1 == y2 ? 0 : 2
end


t = gets.chomp.to_i

t.times do |i|
  n, x = gets.chomp.split.map(&:to_i)
  max_d, max_diff = 0, 0
  n.times do |j|
    d, h = gets.chomp.split.map(&:to_i)
    max_d = [max_d, d].max
    max_diff = [max_diff, d-h].max
  end
  if max_d >= x
    puts 1
  elsif max_diff == 0
    puts -1
  else
    puts ((x-max_d).to_f/max_diff).ceil + 1
  end
end

tt = gets.chomp.to_i
tt.times.map do
  nn, xx = gets.split.map(&:to_i)
  # 差分が大きい順
  dh = nn.times.map{gets.split.map(&:to_i)}.sort{|a,b|(b[0]-b[1])<=>(a[0]-a[1])}
  last = dh.sort{|a,b|b[0]<=>a[0]}[0][0]
  diff = dh[0][0]-dh[0][1]
  if last>=xx
    puts 1
    next
  elsif diff<=0
    puts -1
    next
  end
  cnt = 1 + ((xx-last)/diff.to_f).ceil
  puts cnt
end