# coding: utf-8
n = gets.to_i
map = n.times.map {|i|
  gets.chomp.chars.map{|c|
    c == "."
  }.each_with_index.map{|c, j|
    [i.next, j.next, c]
  }
}
check  = proc {|line| line.any?(&:last) }
answer = proc {|line| puts line.find(&:last).first(2).join " " }
if map.all?(&check)
  map.each(&answer)
elsif map.transpose.all?(&check)
  map.transpose.each(&answer)
else
  puts -1
end

n=gets.to_i
m=[]
f=false
n.times do
  m << gets.chomp.split('')
  f=true if !m.last.include?('.')
end
m=m.transpose if f
f2=false
m.each {|x| f2=true if !x.include?('.')}
if f and f2
  puts -1
  exit
end
m.each_with_index do |x,i|
  a=x.index('.')+1
  b=i+1
  if f
    puts "#{a} #{b}"
  else
    puts "#{b} #{a}"
  end
end

#!/usr/bin/env ruby
def cal_purify(pos, vis, n)
  num = 0
  num += 1 if !vis[pos[0]][pos[1]]
  for i in 1..n
    num += 1 if pos[0] - i >= 0 && !vis[pos[0] - i][pos[1]]
    num += 1 if pos[0] + i < n && !vis[pos[0] + i][pos[1]]
    num += 1 if pos[1] - i >= 0 && !vis[pos[0]][pos[1] - i]
    num += 1 if pos[1] + i < n && !vis[pos[0]][pos[1] + i]
  end
  return num
end

def purify(pos, vis, n)
  vis[pos[0]][pos[1]] = true
  for i in 1..n
    vis[pos[0] - i][pos[1]] = true if pos[0] - i >= 0
    vis[pos[0] + i][pos[1]] = true if pos[0] + i < n
    vis[pos[0]][pos[1] - i] = true if pos[1] - i >= 0
    vis[pos[0]][pos[1] + i] = true if pos[1] + i < n
  end
end
n = gets.to_i
map = []
n.times do
  map << gets.chomp!
end
can_purify = []
for i in 0...map.size
  for j in 0...map[i].size
    if map[i][j] != 'E'
      can_purify << [i, j]
    end
  end
end
rowvis = Array.new(n + 1, false)
colvis = Array.new(n + 1, false)
rowcnt = colcnt = 0
can_purify.each do |pos|
  if !rowvis[pos[0]]
    rowcnt += 1
    rowvis[pos[0]] = true
  end
  if !colvis[pos[1]]
    colcnt += 1
    colvis[pos[1]] = true
  end
end
result = []
vis = Array.new(n + 1, false)
if rowcnt == n
  can_purify.each do |pos|
    if !vis[pos[0]]
      result << pos
      vis[pos[0]] = true
    end
  end
elsif colcnt == n
  can_purify.each do |pos|
    if !vis[pos[1]]
      result << pos
      vis[pos[1]] = true
    end
  end
end
if result.size != n
  puts "-1"
else
  result.each do |step|
    step[0] += 1
    step[1] += 1
    puts step.join(' ')
  end
end

#!/usr/bin/env ruby
n = gets.to_i
map, can_purify = [], []
n.times do
  map << gets.chomp!
end
for i in 0...map.size
  for j in 0...map[i].size
    can_purify << [i, j] if map[i][j] != 'E'
  end
end
rowvis, colvis = Array.new(n + 1, false), Array.new(n + 1, false)
rowcnt = colcnt = 0
can_purify.each do |pos|
  rowvis[pos[0]] = true if !rowvis[pos[0]]
  colvis[pos[1]] = true if !colvis[pos[1]]
end
result = []
vis = Array.new(n + 1, false)
if rowvis.count(true) == n
  can_purify.each do |pos|
    next if result.include? pos[0]
    puts "#{pos[0] + 1} #{pos[1] + 1}"
    result << pos[0]
  end
elsif colvis.count(true) == n
  can_purify.each do |pos|
    next if result.include? pos[1]
    puts "#{pos[0] + 1} #{pos[1] + 1}"
    result << pos[1]
  end
else
  puts "-1"
end

#!/usr/bin/env ruby
n = gets.to_i
map = []
n.times do
  map << gets.chomp!
end
can_purify = []
for i in 0...map.size
  for j in 0...map[i].size
    if map[i][j] != 'E'
      can_purify << [i, j]
    end
  end
end
rowvis = Array.new(n + 1, false)
colvis = Array.new(n + 1, false)
rowcnt = colcnt = 0
can_purify.each do |pos|
  if !rowvis[pos[0]]
    rowcnt += 1
    rowvis[pos[0]] = true
  end
  if !colvis[pos[1]]
    colcnt += 1
    colvis[pos[1]] = true
  end
end
result = []
vis = Array.new(n + 1, false)
if rowcnt == n
  can_purify.each do |pos|
    if !vis[pos[0]]
      result << pos
      vis[pos[0]] = true
    end
  end
elsif colcnt == n
  can_purify.each do |pos|
    if !vis[pos[1]]
      result << pos
      vis[pos[1]] = true
    end
  end
end
if result.size != n
  puts "-1"
else
  result.each do |step|
    step[0] += 1
    step[1] += 1
    puts step.join(' ')
  end
end

n=gets.to_i
s=[]
n.times { s<<gets.chomp.each_char.map{ |v| v==?E ? 1 : 0 } }
rows=[]
s.each_with_index { |v, i|
    k=v.index(0)
    rows<<[i+1, k+1] if k
}

cols=[]
0.upto(n-1) { |j|
    0.upto(n-1) { |i|
        if s[i][j]==0
            cols<<[i+1, j+1]
            break
        end
    }
}

if rows.size==n
    rows.each { |v| puts v*' ' }
elsif cols.size==n
    cols.each { |v| puts v*' ' }
else
    p -1
end

n = gets.to_i
s = Array.new(n)
n.times{|i| s[i] = gets.chomp.split("")}
ans = Array.new
n.times do |i|
    ans.push(s[i].index(".")) if s[i].index(".")
end
if ans.size >= n
    n.times{|i| puts [i+1, ans[i]+1].join(" ")}
    exit
end
ans.clear
s = s.transpose
n.times do |i|
    ans.push(s[i].index(".")) if s[i].index(".")
end
if ans.size >= n
    n.times{|i| puts [ans[i]+1, i+1].join(" ")}
    exit
end
puts "-1"

n = gets.to_i
a = Array.new(n).map! { gets.chomp.split(//) }
b = a.transpose

def can(a)
    a.each do |e|
        return false if e.count('.') == 0
    end
    true
end

if can(a)
    a.each_with_index do |e, i|
        puts "#{i+1} #{e.index('.')+1}"
    end
elsif can(b)
    b.each_with_index do |e, i|
        puts "#{e.index('.')+1} #{i+1}"
    end
else
    puts -1
end

n = gets.to_i
a = Array.new(n).map! { gets.chomp.split(//) }
b = a.transpose
# puts a.inspect

def can(a)
    a.each do |e|
        return false if e.count('.') == 0
    end
    true
end

if can(a)
    a.each_index do |i|
        puts "#{i+1} #{a[i].index('.')+1}"
    end
elsif can(b)
    b.each_index do |i|
        puts "#{b[i].index('.')+1} #{i+1}"
    end
else
    puts -1
end

n = gets.to_i
a = Array.new(n).map! { gets.chomp.split(//) }
b = a.transpose
# puts a.inspect

def can(a)
    a.each do |e|
        return false if e.count('.') == 0
    end
    true
end

if can(a)
    a.each_index do |i|
        puts "#{i+1} #{a[i]}.index('.')+1}"
    end
elsif can(b)
    b.each_index do |i|
        puts "#{b[i].index('.')+1} #{i+1}"
    end
else
    puts -1
end

n = gets.to_i
a = Array.new(n).map! { gets.chomp.split(//) }
b = a.transpose
# puts a.inspect

def can(a)
    a.each do |e|
        return false if e.count('.') == 0
    end
    true
end

if can(a)
    a.each_index do |i|
        puts "#{i} #{a[i].index('.')}"
    end
elsif can(b)
    b.each_index do |i|
        puts "#{b[i].index('.')} #{i}"
    end
else
    puts -1
end

n = gets.to_i
s = Array.new(n)
n.times{|i| s[i] = gets.chomp.split("")}
ans = Array.new
n.times do |i|
    ans.push(s[i].index(".")) if s[i].index(".")
end
if ans.size >= n
    n.times{|i| puts [i+1, ans[i]+1].join(" ")}
    exit
end
ans.clear
s = s.transpose
n.times do |i|
    ans.push(s[i].index(".")) if s[i].index(".")
end
if ans.size >= n
    n.times{|i| puts [i+1, ans[i]+1].join(" ")}
    exit
end
puts "-1"

n = gets.to_i
s = Array.new(n)
n.times{|i| s[i] = gets.chomp.split("")}
ans = Array.new
n.times do |i|
    ans.push(s[i].index(".")) if s[i].index(".")
end
if ans.size >= n
    n.times{|i| puts [i+1, ans[i]+1].join(" ")}
    exit
end
ans.clear
s.transpose
n.times do |i|
    ans.push(s[i].index(".")) if s[i].index(".")
end
if ans.size >= n
    n.times{|i| puts [i+1, ans[i]+1].join(" ")}
    exit
end
puts "-1"

n=gets.to_i
ok=true
res=[]
1.upto(n) {|i|
    s=gets.chomp
    k=s.index(?.)
    if k
        res<<[i, k+1]
    else
        ok=false
    end
}
if ok
    res.each {|v|
        puts v*' '
    }
else
    p -1
end

n = gets.to_i
map = n.times.map {|i| gets.chomp.chars.to_a }
check = proc {|line| line.include? "." }
write = proc {|line, i|
  safe = line.each_with_index.find{|cell| cell.first == "." }
  puts [i.next, safe.last.next].join ' '
}
puts map.inspect,map.transpose.inspect
if map.all?(&check)
  map.each_with_index(&write)
elsif map.transpose.all?(&check)
  map.transpose.each_with_index(&write)
else
  puts -1
end

n = gets.to_i
map = n.times.map {|i| gets.chomp.chars.to_a }
check = proc {|line| line.include? "." }
write = proc {|line, i|
  safe = line.each_with_index.find{|cell| cell.first == "." }
  puts [i.next, safe.last.next].join ' '
}
if map.all?(&check)
  map.each_with_index(&write)
elsif map.transpose.all?(&check)
  map.transpose.each_with_index(&write)
else
  puts -1
end


steps = gets.chomp.to_i
movement = gets.chomp

coordinate_movements = [[0, 0]]

for i in 0...steps
  if movement[i] == 'U'
    coordinate_movements << [coordinate_movements[coordinate_movements.count - 1][0], coordinate_movements[coordinate_movements.count - 1][1] + 1]
  else
    coordinate_movements << [coordinate_movements[coordinate_movements.count - 1][0] + 1, coordinate_movements[coordinate_movements.count - 1][1]]
  end
end

payment = 0

if coordinate_movements.count > 2
  for i in 2...coordinate_movements.count
    if coordinate_movements[i-1][0] == coordinate_movements[i-1][1]
      payment += 1 if ((coordinate_movements[i - 2][0] == coordinate_movements[i][0]) && (coordinate_movements[i][1] - coordinate_movements[i - 2][1] == 2)) || ((coordinate_movements[i - 2][1] == coordinate_movements[i][1]) && (coordinate_movements[i][0] - coordinate_movements[i - 2][0] == 2))
    end
  end
end

puts payment


gets
a = gets.split.map(&:to_i)
b = a.min
p a.map{|i| i % b}.max == 0 ? b : -1

N = gets.chomp.to_i
A = gets.chomp.split(' ').map{|c| c.to_i}
m = A.min
# puts m
A.each do |c|
	if c%m != 0
		puts "-1"
		exit
	end
end
puts m

n = gets.to_i
a = gets.split(' ').map { |i| i.to_i }.sort
can = true
for i in 1...a.size
    can = false if a[i] % a[0] != 0
end
puts can ? a[0] : -1

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

  f = true
  a.each do |x|
    f = false if x % a.first != 0
  end

  puts f ? a.first : -1
end

run if $0 == __FILE__

class A
  def initialize
    n = $stdin.gets.chomp.to_i
    array = $stdin.gets.chomp.split(' ').map(&:to_i)

    ans = array[0]

    array.each do |num|
      ans = ans.gcd(num)
    end

    if ans == 1 && !array.include?(1)
      puts -1
    elsif array.include?(ans)
      puts ans
    else
      puts -1
    end
  end
end

a = A.new

def main()
	n=gets.chomp.to_i
	ar=gets.chomp.split(" ")
	ar=ar.map{|i| i.to_i}
	if n==1
		puts ar[0]
		return
	end
	gcd=getGcd(ar[0],ar[1])
	for i in 2...n
		gcd=getGcd(gcd,ar[i])
	end
	if ar.include?(gcd)
		puts gcd
	else
		puts "-1"
	end
end
def getGcd(a,b)
	if(a==0 || b==0)
		return a+b
	end
	return getGcd(b,a%b)
end
main()

def ksuha(input)
  min_ele = input.min
  if min_ele == 1
    return min_ele
  else
    return min_ele if check(input, min_ele)
    -1
  end
end

def check(input, min_elem)
  input.all? { |i| i%min_elem == 0 }
end

_ = STDIN.gets
input = STDIN.readline.split(" ").map(&:to_i)

puts ksuha(input)

n = gets.to_i
as = gets.split.map(&:to_i)
g = as.inject(0) { |g, a| g.gcd(a) }
as.each do |a|
  if g % a == 0
    puts a
    exit 0
  end
end
puts -1

def gcd(a, b)
  if b == 0
    a
  else
    gcd(b, a % b)
  end
end

n = gets[0..-2].to_i
a = gets[0..-2].split(' ').collect{|x| x.to_i}
if n == 1
  print a[0]
else
  uc = a[0]
  a.each{|x| uc = gcd(uc, x)}
  ok = false
  a.each do |x|
    if uc % x == 0
      ok = true
      print x
      break
    end
  end
  print -1 unless ok
end

gets
a = gets.split.map(&:to_i)
m = a.min
a.each do |i|
	if i % m != 0
		puts -1
		exit 0
	end
end
puts m

at_exit do
  n = get_numbers_from_line[0]
  as = get_numbers_from_line[0...n]
  num = as.min
  if as.all?{|x| x % num == 0}
    puts num
  else
    puts '-1'
  end

end

def get_numbers_from_line
  gets.strip.split.map(&:to_i)
end

n = gets().to_i
a = gets().split(' ').map { |p| p.to_i}
num = a.min
div = true
for x in a
        if x%num != 0
                div = false
                break
        end
end

if div
        puts num
else
        puts -1
end

class A
  def initialize
    n = $stdin.gets.chomp.to_i
    array = $stdin.gets.chomp.split(' ').map(&:to_i)

    ans = array[0]

    array.each do |num|
      ans = ans.gcd(num)
    end

    if ans == 1 && !array.include?(1)
      puts -1
    else
      puts ans
    end
  end
end

a = A.new

def main()
	n=gets.chomp.to_i
	ar=gets.chomp.split(" ")
	ar=ar.map{|i| i.to_i}
	gcd=getGcd(ar[0],ar[1])
	for i in 2...n
		gcd=getGcd(gcd,ar[i])
	end
	puts gcd
end
def getGcd(a,b)
	if(a==0 || b==0)
		return a+b
	end
	return getGcd(b,a%b)
end
main()

def gcd(a, b)
  if b == 0
    a
  else
    gcd(b, a % b)
  end
end

n = gets[1..-1].to_i
a = gets[1..-1].split(' ').collect{|x| x.to_i}
if n == 1
  print a[0]
else
  uc = a[0]
  a.each{|x| uc = gcd(uc, x)}
  ok = false
  a.each do |x|
    if uc % x == 0
      ok = true
      print x
      break
    end
  end
  print -1 unless ok
end

n = gets().to_i
a = gets().split(' ').map { |p| p.to_i}
num = a.min
div = true
for x in a
        if x%num != 0
                puts " #{x} #{num}"
                div = false
                break
        end
end

if div
        puts num
else
        puts -1
end


n = gets.to_i
home_games = (n-1)
total_games = (n-1) * 2
home = []
away = []
home_count = Hash.new(0)
n.times do
	h,a = gets.split(" ").map(&:to_i)
	home << h
	home_count[h] += 1
	away << a
end
ans_count = []
n.times do |i|
	ans_count << home_games + home_count[away[i]]
end

ans_count.each do |a|
	puts "#{a} #{total_games - a}"
end

n=gets.to_i
a,b,xu=[],[],Array.new(100001,0)
n.times do |i|
	x,y=gets.chomp.split.map(&:to_i)
	a<<x
	b<<y
	xu[x]+=1
end
n.times { |i| puts "#{n-1+xu[b[i]]} #{n-1-xu[b[i]]}" }

n = gets.to_i
h = [0] * 100001
a = Array.new(n + 1)
for i in 1..n
  y = gets.split(" ").collect {|x| x.to_i}
  h[y[0]] += 1
  a[i] = y[1]
end
for i in 1..n
  printf("%d %d\n", n - 1 + h[a[i]], n - 1 - h[a[i]])
end


n, m = gets.split.map(&:to_i)
aa = []
not_zero = false
n.times do|_x|
   arr = gets.split
   aa << arr
   unless not_zero
     not_zero=true if arr.include?("1")
   end
end

unless not_zero
  puts 0
  exit
end

changed = Array.new(n,"0").map{Array.new(m,"0")}
ans = []

0.upto(n-1-1) do |i|
  0.upto(m-1-1) do |j|
    if aa[i][j]=="1" && aa[i][j+1]=="1" && aa[i+1][j]=="1" && aa[i+1][j+1]=="1"
      ans << "#{i+1} #{j+1}"
      changed[i][j]="1"
      changed[i][j+1]="1"
      changed[i+1][j]="1"
      changed[i+1][j+1]="1"
    end
    #d
    #puts changed.to_s
  end

  unless aa[i] == changed[i]
    # できない
    puts -1
    exit
  end
  if i==n-2 && aa[n-1] != changed[n-1]
    # できない
    puts -1
    exit
  end
end

puts("#{ans.size}\n" + ans.join("\n"))

n,m = gets.split.map(&:to_i)
grid = []
n.times do
  grid << gets.split.map(&:to_i)
end
target = Array.new(n){[0]*m}
ans = []
(n-1).times do |i|
  (m-1).times do |j|
    if grid[i][j] == 1 && grid[i+1][j] == 1 && grid[i][j+1] == 1 && grid[i+1][j+1] == 1
      2.times do |x|
        2.times do |y|
          target[i+x][j+y] = 1
        end
      end
      ans << [i+1,j+1]
    end
  end
end
flg = true
n.times do |i|
  m.times do |j|
    flg = false if grid[i][j] != target[i][j]
  end
end
if flg
  p ans.length
  ans.each do |a|
    puts a.join(" ")
  end
else
  p -1
end

# http://codeforces.com/contest/1207/problem/B

def board
  nm = get_each gets.chomp
  n, m = nm[0], nm[1]
  a = Array.new
  color = Array.new(n) { Array.new(m, 0)}

  n.times do
    row = get_each(gets.chomp)
    a << row
  end

  paint = Array.new

  0.upto(n-2) do |r|
    0.upto(m-2) do |c|
      if 4 == (a[r][c] + a[r+1][c] + a[r][c+1] + a[r+1][c+1])
        coloring(color, r, c)
        paint << [r, c]
      end
    end
  end

  if !array_match(a, color)
    puts -1
    return
  elsif paint.empty?
    puts 0
    return
  end

  puts paint.count
  0.upto(paint.size-1) do |i|
    print "#{paint[i][0]+1} #{paint[i][1]+1}\n"
  end
end

def array_match(arr1, arr2)
  0.upto(arr1.size-1) do |r|
    0.upto(arr1[0].size-1) do |c|
      return false unless arr1[r][c] == arr2[r][c]
    end
  end
  true
end

def coloring(color, r, c)
  color[r][c], color[r+1][c], color[r][c+1], color[r+1][c+1] = 1, 1, 1, 1
end

def get_each(str)
  arr = Array.new
  num = 0
  str.each_char do |e|
    if e == ' '
      arr << num
      num = 0
    else
      num = num * 10 + e.to_i
    end
  end
  arr << num #unless num.zero?
  arr
end

board

def board
  nm = get_each gets.chomp
  n, m = nm[0], nm[1]
  a = Array.new
  color = Array.new(n) { Array.new(m, 0)}

  n.times do
    row = get_each(gets.chomp)
    a << row
  end

  paint = Array.new

  0.upto(n-2) do |r|
    0.upto(m-2) do |c|
      if 4 == (a[r][c] + a[r+1][c] + a[r][c+1] + a[r+1][c+1])
        coloring(color, r, c)
        paint << [r, c]
      end
    end
  end

  if !array_match(a, color)
    puts -1
    return
  elsif paint.empty?
    puts 0
    return
  end

  puts paint.count
  0.upto(paint.size-1) do |i|
    print "#{paint[i][0]} #{paint[i][1]}\n"
  end
end

def array_match(arr1, arr2)
  0.upto(arr1.size-1) do |r|
    0.upto(arr1[0].size-1) do |c|
      return false unless arr1[r][c] == arr2[r][c]
    end
  end
  true
end

def coloring(color, r, c)
  color[r][c], color[r+1][c], color[r][c+1], color[r+1][c+1] = 1, 1, 1, 1
end

def get_each(str)
  arr = Array.new
  num = 0
  str.each_char do |e|
    if e == ' '
      arr << num
      num = 0
    else
      num = num * 10 + e.to_i
    end
  end
  arr << num #unless num.zero?
  arr
end

board

$visited = nil
$color = nil

def board
  nm = get_each gets.chomp
  n = nm[0]
  m = nm[1]
  a = Array.new
  $color = Array.new(n) { Array.new(m, 0)}
  $visited = Array.new(n) { Array.new(m, 0) }

  n.times do
    row = get_each(gets.chomp)
    a << row
  end
  coord = start_coord(a, n, m)
  if coord.empty?
    puts 0
    return
  end
  result = collect_result(coord, a)
  if result == -1 || !color_match(a)
    puts -1
    return
  end
  puts result.count
  0.upto(result.size-1) do |i|
    print "#{result[i][0]} #{result[i][1]}\n"
  end
end

def color_match(arr)
  0.upto(arr.size-1) do |r|
    0.upto(arr[0].size-1) do |c|
      return false unless $color[r][c] == arr[r][c]
    end
  end
  true
end

def start_coord(arr, n, m)
  0.upto(n-1) do |r|
    0.upto(m-1) do |c|
      return [r,c] if arr[r][c] == 1
    end
  end
  []
end

def collect_result(coord, a)
  result = Array.new
  q = Array.new
  r, c = coord
  q << [coord]
  i = 4
  until q.empty? do
    point = q.shift.flatten.flatten
    r, c = point[0], point[1]
    coloring(r, c)
    $visited[r][c] = 1
    result << [r+1, c+1]
    ways = way_to_go(a, r, c)
    until ways.empty? do # max 4
      var = ways.shift
      next_r = r + var[0]
      next_c = c + var[1]
      q << [next_r, next_c] if $visited[next_r][next_c].zero?
    end
    i -= 1
    break if i.zero?
  end
  result
end

def coloring(r, c)
  $color[r][c], $color[r+1][c], $color[r][c+1], $color[r+1][c+1] = 1, 1, 1, 1
end

def way_to_go(arr, r, c)
  ways = Array.new
  if (r+1) < arr.size && $visited[r+1][c].zero? && block_check(arr, r+1, c)
    ways << [1,0]
  elsif (r-1) >= 0 && $visited[r-1][c].zero? && block_check(arr, r-1, c)
    ways << [-1,0]
  elsif (c+1) < arr[0].size && $visited[r][c+1].zero? && block_check(arr, r, c+1)
    ways << [0,1]
  elsif (c-1) >= 0 && $visited[r][c-1].zero? && block_check(arr, r, c-1)
    ways << [0,-1]
  end
  ways
end

def block_check(arr, r, c)
  return false unless r >= 0 && (r+1) < arr.size && c >= 0 && (c+1) < arr[0].size
  unless 4 == ($color[r][c] + $color[r+1][c] + $color[r][c+1] + $color[r+1][c+1])
    return 4 == (arr[r][c] + arr[r+1][c] + arr[r][c+1] + arr[r+1][c+1])
  end
  false
end

def get_each(str)
  arr = Array.new
  num = 0
  str.each_char do |e|
    if e == ' '
      arr << num
      num = 0
    else
      num = num * 10 + e.to_i
    end
  end
  arr << num #unless num.zero?
  arr
end

board

$visited = nil
$color = nil

def board
  nm = get_each gets.chomp
  n = nm[0]
  m = nm[1]
  a = Array.new
  $color = Array.new(n) { Array.new(m, 0)}
  $visited = Array.new(n) { Array.new(m, 0) }

  n.times do
    row = get_each(gets.chomp)
    a << row
  end
  coord = start_coord(a, n, m)
  if coord.empty?
    puts 0
    return
  end
  result = collect_result(coord, a)
  if result == -1 || !color_match(a)
    puts -1
    return
  end
  puts result.count
  0.upto(result.size-1) do |i|
    print "#{result[i][0]} #{result[i][1]}\n"
  end
end

def color_match(arr)
  0.upto(arr.size-1) do |r|
    0.upto(arr[0].size-1) do |c|
      return false unless $color[r][c] == arr[r][c]
    end
  end
  true
end

def start_coord(arr, n, m)
  0.upto(n-1) do |r|
    0.upto(m-1) do |c|
      return [r,c] if arr[r][c] == 1
    end
  end
  []
end

def collect_result(coord, a)
  result = Array.new
  q = Array.new
  r, c = coord
  q << [coord]
  until q.empty? do
    point = q.shift.flatten.flatten
    r, c = point[0], point[1]
    coloring(r, c)
    $visited[r][c] = 1
    result << [r+1, c+1]
    ways = way_to_go(a, r, c)
    until ways.empty? do # max 4
      var = ways.shift
      next_r = r + var[0]
      next_c = c + var[1]
      q << [next_r, next_c] if $visited[next_r][next_c].zero?
    end
  end
  result
end

def coloring(r, c)
  $color[r][c], $color[r+1][c], $color[r][c+1], $color[r+1][c+1] = 1, 1, 1, 1
end

def way_to_go(arr, r, c)
  ways = Array.new
  if (r+1) < arr.size && $visited[r+1][c].zero? && block_check(arr, r+1, c)
    ways << [1,0]
  elsif (r-1) >= 0 && $visited[r-1][c].zero? && block_check(arr, r-1, c)
    ways << [-1,0]
  elsif (c+1) < arr[0].size && $visited[r][c+1].zero? && block_check(arr, r, c+1)
    ways << [0,1]
  elsif (c-1) >= 0 && $visited[r][c-1].zero? && block_check(arr, r, c-1)
    ways << [0,-1]
  end
  ways
end

def block_check(arr, r, c)
  return false unless r >= 0 && (r+1) < arr.size && c >= 0 && (c+1) < arr[0].size
  unless 4 == ($color[r][c] + $color[r+1][c] + $color[r][c+1] + $color[r+1][c+1])
    return 4 == (arr[r][c] + arr[r+1][c] + arr[r][c+1] + arr[r+1][c+1])
  end
  false
end

def get_each(str)
  arr = Array.new
  num = 0
  str.each_char do |e|
    if e == ' '
      arr << num
      num = 0
    else
      num = num * 10 + e.to_i
    end
  end
  arr << num #unless num.zero?
  arr
end

board

$visited = nil
$color = nil

def board
  nm = get_each gets.chomp
  n = nm[0]
  m = nm[1]
  a = Array.new
  $color = Array.new(n) { Array.new(m, 0)}
  $visited = Array.new(n) { Array.new(m, 0) }

  n.times do
    row = get_each(gets.chomp)
    a << row
  end
  coord = start_coord(a, n, m)
  if coord.empty?
    puts 0
    return
  end
  result = collect_result(coord, a)
  if result == -1 || !color_match(a)
    puts -1
    return
  end
  puts result.count
  0.upto(result.size-1) do |i|
    print "#{result[i][0]} #{result[i][1]}\n"
  end
end

def color_match(arr)
  0.upto(arr.size-1) do |r|
    0.upto(arr[0].size-1) do |c|
      return false unless $color[r][c] == arr[r][c]
    end
  end
  true
end

def start_coord(arr, n, m)
  0.upto(n-1) do |r|
    0.upto(m-1) do |c|
      return [r,c] if arr[r][c] == 1
    end
  end
  []
end

def collect_result(coord, a)
  result = Array.new
  q = Array.new
  r, c = coord
  coloring(r, c)
  $visited[r][c] = 1
  q << [coord]
  i = 4
  until q.empty? do
    point = q.shift.flatten.flatten
    r, c = point[0], point[1]
    result << [r+1, c+1]
    ways = way_to_go(a, r, c)
    until ways.empty? do # max 4
      var = ways.shift
      next_r = r + var[0]
      next_c = c + var[1]
      q << [next_r, next_c] if $visited[next_r][next_c].zero?
      coloring(next_r, next_c)
      $visited[next_r][next_c] = 1
    end
    i -= 1
    break if i.zero?
  end
  result
end

def coloring(r, c)
  $color[r][c], $color[r+1][c], $color[r][c+1], $color[r+1][c+1] = 1, 1, 1, 1
end

def way_to_go(arr, r, c)
  ways = Array.new
  if (r+1) < arr.size && $visited[r+1][c].zero? && block_check(arr, r+1, c)
    ways << [1,0]
  elsif (r-1) >= 0 && $visited[r-1][c].zero? && block_check(arr, r-1, c)
    ways << [-1,0]
  elsif (c+1) < arr[0].size && $visited[r][c+1].zero? && block_check(arr, r, c+1)
    ways << [0,1]
  elsif (c-1) >= 0 && $visited[r][c-1].zero? && block_check(arr, r, c-1)
    ways << [0,-1]
  end
  ways
end

def block_check(arr, r, c)
  return false unless r >= 0 && (r+1) < arr.size && c >= 0 && (c+1) < arr[0].size
  unless 4 == ($color[r][c] + $color[r+1][c] + $color[r][c+1] + $color[r+1][c+1])
    return 4 == (arr[r][c] + arr[r+1][c] + arr[r][c+1] + arr[r+1][c+1])
  end
  false
end

def get_each(str)
  arr = Array.new
  num = 0
  str.each_char do |e|
    if e == ' '
      arr << num
      num = 0
    else
      num = num * 10 + e.to_i
    end
  end
  arr << num #unless num.zero?
  arr
end

board

n, m = gets.split.map(&:to_i)
aa = []
not_zero = false
n.times do|_x|
   arr = gets.split
   aa << arr
   unless not_zero
     not_zero=true if arr.include?("1")
   end
end

unless not_zero
  puts 0
  exit
end

changed = Array.new(n,"0").map{Array.new(m,"0")}
ans = []

0.upto(n-1-1) do |i|
  0.upto(m-1-1) do |j|
    if aa[i][j]=="1" && aa[i][j+1]=="1" && aa[i+1][j]=="1" && aa[i+1][j+1]=="1"
      ans << "#{i+1} #{j+1}"
      changed[i][j]="1"
      changed[i][j+1]="1"
      changed[i+1][j]="1"
      changed[i+1][j+1]="1"
    end
    #d
    #puts changed.to_s
  end

  unless aa[i] == changed[i]
    # できない
    puts -1
    exit
  end
end

puts("#{ans.size}\n" + ans.join("\n"))

n, m = gets.split.map(&:to_i)
aa = []
not_zero = false
n.times do|_x|
   arr = gets.split
   aa << arr
   unless not_zero
     not_zero=true if arr.include?("1")
   end
end

unless not_zero
  puts 0
  exit
end

changed = Array.new(n).map{Array.new(m)}
ans = []

0.upto(n-1-1) do |i|
  0.upto(m-1-1) do |j|
    if aa[i][j]=="1" && aa[i][j+1]=="1" && aa[i+1][j]=="1" && aa[i+1][j+1]=="1"
      ans << "#{i+1} #{j+1}"
      changed[i][j]=1
      changed[i+1][j]=1
      changed[i+1][j+1]=1
    elsif changed[i][j]==1
    else
      # できない
      puts -1
      exit
    end
    #d
    #puts changed.to_s
  end
end

puts("#{ans.size}\n" + ans.join("\n"))


n = gets.to_i
a = gets.split.map(&:to_i)
ans = 0
c = 0
a += a
(n*2).times do |i|
    if a[i] == 1
        c += 1
        ans = c if ans < c
    else
        c = 0
    end
end
puts [ans,n].min

N = gets.to_i
s = gets.split.join
s += s
p s.scan(/1+/).map{ |s| s.size }.max || 0

# coding: utf-8

# if __FILE__ == $0
# end

n = gets.to_i
a = gets.split.map(&:to_i) # "0" works "1" rests
doublea = a*2 # simulate it with 'mod' operator in other language (looping)
longest_rests = 0
rests = 0
doublea.each { |flag|
    if flag == 0 # works
        rests = 0
    else
        rests += 1

        if rests > longest_rests
            longest_rests = rests
        end
    end
}

puts longest_rests

gets
r=(gets*2).tr('
','').gsub(/1+/).map(&:size).max
p r==nil ?0:r

gets
r=(gets*2).tr('
','').split(?0).map(&:size).max
p r==nil ?0:r

quantidade=gets
numeros=gets
vetordenumeros=numeros.split
vetordenumeros=vetordenumeros+vetordenumeros
i=0
contador=0
for numero in vetordenumeros do
    if numero.to_i==1
        i+=1
    else
        if contador<i
            contador=i
        end
        i=0
    end
end
puts contador

N = gets.to_i
s = gets.split.join
s += s[0]
p s.scan(/1+/).map{ |s| s.size }.max || 0


s = gets.chomp
order = s =~ /\Aa+b+c+$/
cntC = s.count('c')
count = cntC == s.count('a') || cntC == s.count('b')
puts order && count ? 'YES' : 'NO'
puts order


#!/usr/bin/env ruby
n = gets.chomp.to_i
stack = []
exception = nil
n.times do |i|
    line = gets.chomp.strip
    next if line.empty?

    #puts line
    if line == "try"
        stack.push({type: "try", line: i})
        #puts "try"
    elsif line.start_with?("throw")
        exception = line.split(/\(|\)/).last.strip
        stack.push({type: :throw, exception: exception})
        #puts throw_type
    elsif line.start_with?("catch")
        catch_type = line.match(/\(\s*(\w+)/)[1].strip
        message = line.match(/,\s*("[^"]*")\s*\)/)[1]
        x = stack.last
        stack.pop
        if x[:type] == :throw
            stack.pop
            if x[:exception] == catch_type
                puts message[1...-1]
            else
                stack.push(x)
            end
        end
        #puts "#{catch_type} -> #{message}"
    end
end
unless stack.empty?
    puts "Unhandled Exception"
end

#!/usr/bin/env ruby
# encoding: utf-8
n=gets.to_i

thlist = []
thid = []
trylist = []
flag=0

n.times do |id|
  str=gets.strip!
  next if flag == 1
  if /^try$/ =~ str
    trylist << id
  elsif /throw/ =~ str
    /(?<=\()\s*\w+\s*(?=\))/ =~ str
    thlist << $&.strip
    # puts thlist.last
    thid << id
  elsif /catch/ =~ str
    /(?<=\()\s*\w+\s*(?=,)/ =~ str
    if (pos=thlist.index($&.strip))!=nil && thid[pos] > trylist.last
      /(?<=\").+(?=\")/ =~ str
      puts $&
      flag=1
    end
    trylist.pop
  end
end

puts "Unhandled Exception" if flag == 0

#!/usr/bin/env ruby
# encoding: utf-8
n=gets.to_i

thlist = []
thid = []
trylist = []
flag=0

n.times do |id|
  str=gets.strip!
  next if flag == 1
  if /^try$/ =~ str
    trylist << id
  elsif /throw/ =~ str
    /(?<=\()\s*\w+\s*(?=\))/ =~ str
    thlist << $&.strip
    thid << id
  elsif /catch/ =~ str
    /(?<=\()\s*\w+\s*(?=,)/ =~ str
    if (pos=thlist.index($&.strip))!=nil && thid[pos] > trylist.last
      /(?<=\").+(?=\")/ =~ str
      puts $&
      flag=1
    end
    trylist.pop
  end
end

puts "Unhandled Exception" if flag == 0

#!/usr/bin/ruby -w

N = gets.strip.to_i
level = 0
ex = ''
ex_level = 0
dummy = 0

N.times do |i|
  line = gets
  next if not line
  line.strip!

  if line =~ /try$/
    level += 1
    dummy += 1 if ex != ''
    #puts "#{level}, #{dummy}, try, #{ex}"
  elsif line =~ /throw\s*\((.+?)\)/
    #puts "#{level}, #{dummy}, throw #{$1.strip}"
    ex = $1.strip
    ex_level = level
  elsif line =~ /catch\s*\((.+?)\s*,\s*"(.+?)"\s*\)/
    #puts "#{level}, #{dummy}, #{$2}"
    if dummy == 0 && level <= ex_level && ex == $1.strip
      puts $2
      exit
    end
    level -= 1
    dummy -= 1 if dummy > 0
  end
end

puts "Unhandled Exception"

#!/usr/bin/ruby -w

N = gets.strip.to_i
level = 0
ex = ''
ex_level = 0
dummy = 0

N.times do |i|
  line = gets
  next if not line
  line.strip!

  if line =~ /try$/
    level += 1
    dummy += 1 if ex != ''
    #puts "#{level}, #{dummy}, try, #{ex}"
  elsif line =~ /throw\s*\((.+?)\)/
    #puts "#{level}, throw #{$1.strip}"
    ex = $1.strip
    ex_level = level
  elsif line =~ /catch\s*\((.+?)\s*,\s*"(.+?)"\s*\)/
    #puts "#{level}, #{dummy}, #{$2}"
    if dummy == 0 && level <= ex_level && ex == $1.strip
      puts $2
      exit
    end
    level -= 1
    dummy -= 1 if dummy > 0
  end
end

puts "Unhandled Exception"

n = gets.to_i
a = []
for i in (1..n) do
  a[i]=gets
end

thr = /(\s*)throw(.*)/
thr_s = /\s*throw\s*\(\s*([a-zA-Z]+)/
try = /(\s*)try(\s*)/
cat = /(\s*)catch(.*)/
cat_s = /\s*catch\s*\(\s*([a-zA-Z]+).+"(.+)"/

for i in (1..n) do
  r = a[i]=~thr
  if r==0 then break end
end
isc = a[i].match(thr_s)[1]
c = 0
for k in (i+1..n) do
  r = a[k]=~try
  if r==0 then c+=1 end
  r = a[k]=~cat
  if r==0 then
    if c==0 then
      z=a[k].match(cat_s)
      if isc==z[1] then
        puts z[2]
        exit
      end
    else
      c-=1
    end
  end
end
puts 'Unhandled Exception'

#!/usr/bin/ruby

n = $stdin.gets.to_i
lines = []
n.times do
  s = $stdin.gets.chomp.strip
  if s == 'try' || s.start_with?('catch') || s.start_with?('throw')
    lines << s
  end
end

exn = {:level => -1, :type => nil}
level = 0
while not lines.empty?
  s = lines.shift
  case s
  when 'try'
    level += 1
  when /\Acatch\s*\(\s*([A-Za-z]+)\s*,\s*"([^"]+)"\s*\)\z/
    type = $1
    mes = $2
    if level == exn[:level] && type == exn[:type]
      puts mes
      exit 0
    end
    if level == exn[:level]
      exn[:level] -= 1
    end
    level -= 1
  when/\Athrow\s*\(\s*([A-Za-z]+)\s*\)\z/
    exn[:level] = level
    exn[:type] = $1
  end
end
puts 'Unhandled Exception'

#!/usr/bin/env ruby
# encoding: utf-8
n=gets.to_i

thlist = []
thid = []
trylist = []
flag=0

n.times do |id|
  str=gets.strip!
  next if flag == 1
  if /try/ =~ str
    trylist << id
  elsif /throw/ =~ str
    /(?<=\()\s*\w+\s*(?=\))/ =~ str
    thlist << $&.strip
    thid << id
  elsif /catch/ =~ str
    /(?<=\()\s*\w+\s*(?=,)/ =~ str
    if (pos=thlist.index($&.strip))!=nil && thid[pos] > trylist.last
        /(?<=\").+(?=\")/ =~ str
      puts $&
      flag=1
    end
    trylist.pop
  end
end

puts "Unhandled Exception" if flag == 0

#!/usr/bin/ruby -w

N = gets.strip.to_i
level = 0
ex = ''
ex_level = 0
dummy = 0

N.times do |i|
  line = gets
  next if not line
  line.strip!

  if line =~ /try/
    level += 1
    dummy += 1 if ex != ''
    #puts "#{level}, #{dummy}, try, #{ex}"
  elsif line =~ /throw\s*\((.+?)\)/
    #puts "#{level}, throw #{$1.strip}"
    ex = $1.strip
    ex_level = level
  elsif line =~ /catch\s*\((.+?)\s*,\s*"(.+?)"\s*\)/
    #puts "#{level}, #{dummy}, #{$2}"
    if dummy == 0 && level <= ex_level && ex == $1.strip
      puts $2
      exit
    end
    level -= 1
    dummy -= 1 if dummy > 0
  end
end

puts "Unhandled Exception"

n = gets.to_i
a = []
for i in (1..n) do
  a[i]=gets
end

for i in (1..n) do
  if a[i]=~(/(\s*)throw(.*)/) then break end
end
isc = a[i].match(/\s*throw\s*\(\s*([a-zA-Z]+)/)[1]
c = 0
for k in (i+1..n) do
  if a[k]=~(/(\s*)try(\s*)/) then c+=1 end
  if a[k]=~(/(\s*)catch(.*)/) then
    if c==0 then
      z=a[k].match(/\s*catch\s*\(\s*([a-zA-Z]+).+"(.+)"/)
      if isc==z[1] then
        puts z[2]
        exit
      end
    else
      c-=1
    end
  end
end
puts 'Unhandled Exception'

#!/usr/bin/ruby

n = $stdin.gets.to_i
lines = []
n.times do
  s = $stdin.gets.chomp.strip
  if s == 'try' || s.start_with?('catch') || s.start_with?('throw')
    lines << s
  end
end

def parse(lines)
  s = lines.shift
  if s == 'try'
    bodies = []
    while not lines[0].start_with?('catch')
      bodies << parse(lines)
    end
    c = lines.shift
    m = c.match(/\Acatch\s*\(\s*([A-Za-z]+)\s*,\s*"([^"]+)"\s*\)\z/)
    {:catch => {:type => m[1], :mes => m[2], :bodies => bodies} }
  else
    m = s.match(/\Athrow\s*\(\s*([A-Za-z]+)\s*\)\z/)
    {:throw => m[1] }
  end
end

tree = parse lines

def solve(t)
  if c = t[:catch]
    exn = nil
    c[:bodies].each do |b|
      exn = solve b
      break if exn
    end
    if exn && exn == c[:type]
      puts c[:mes]
      exit 0
    end
    exn
  else
    t[:throw]
  end
end
solve tree
puts 'Unhandled Exception'

#!/usr/bin/ruby

n = $stdin.gets.to_i
lines = []
n.times do
  s = $stdin.gets.chomp.strip
  if s == 'try' || s.start_with?('catch') || s.start_with?('throw')
    lines << s
  end
end

def parse(lines)
  if not lines.empty?
    s = lines.shift
    if s == 'try'
      bodies = []
      while lines[0] !~ /\Acatch/
        bodies << parse(lines)
      end
      c = lines.shift
      m = c.match(/\Acatch\s*\(\s*([A-Za-z]+)\s*,\s*"([^"]+)"/)
      {:catch => {:type => m[1], :mes => m[2], :bodies => bodies} }
    else
      m = s.match(/\Athrow\s*\(\s*([A-Za-z]+)\s*\)/)
      {:throw => m[1] }
    end
  end
end

tree = parse lines

def solve(t)
  if c = t[:catch]
    exn = nil
    c[:bodies].each do |b|
      exn = solve b
      break if exn
    end
    if exn && exn == c[:type]
      puts c[:mes]
      exit 0
    end
    exn
  else
    t[:throw]
  end
end
solve tree
puts 'Unhandled Exception'

#!/usr/bin/ruby

n = $stdin.gets.to_i
lines = []
n.times do
  s = $stdin.gets.strip
  if s == 'try' || s.start_with?('catch') || s.start_with?('throw')
    lines << s
  end
end

tree = {}
def parse(lines)
  if not lines.empty?
    s = lines.shift
    if s == 'try'
      bodies = []
      while lines[0] !~ /\Acatch/
        bodies << parse(lines)
      end
      c = lines.shift
      m = c.match(/\Acatch\s*\(\s*([A-Za-z]+)\s*,\s*"([^"]+)"/)
      {:catch => {:type => m[1], :mes => m[2], :bodies => bodies} }
    else
      m = s.match(/\Athrow\s*\(\s*([A-Za-z]+)\s*\)/)
      {:throw => m[1] }
    end
  end
end

tree = parse lines

def solve(t)
  if c = t[:catch]
    exn = nil
    c[:bodies].each do |b|
      a = solve b
      if a
        exn = a
      end
    end
    if exn && exn == c[:type]
      puts c[:mes]
      exit 0
    end
    exn
  else
    t[:throw]
  end
end
solve tree
puts 'Unhandled Exception'


OK = "OK"

n, m = gets.split.map { |v| v.to_i }
t = Array.new(n, 0)

m.times do
  a, b = gets.split.map { |v| v.to_i - 1 }
  (a .. b).each { |index| t[index] += 1 }
end

incorrect_day = nil

t.each_index do |index|
  if t[index] != 1
    incorrect_day = index
    break
  end
end

if incorrect_day
  puts "#{incorrect_day + 1} #{t[incorrect_day]}"
else
  puts OK
end

n, m = gets.split.map { |v| v.to_i }
t = Array.new(n, 0)

m.times do
  a, b = gets.split.map { |v| v.to_i - 1 }
  (a .. b).each { |index| t[index] += 1 }
end

incorrect_day = t.find_index { |v| v != 1 }

if incorrect_day
  puts "#{incorrect_day + 1} #{t[incorrect_day]}"
else
  puts "OK"
end

n,m = gets.chomp.split(/ /).map!{|x| x.to_i}
cnt = 0
err = 0
prevnum = 0
for i in 0..m-1
	a = gets.chomp.split(/ /).map!{|x| x.to_i}
	if a[0] == prevnum
		if err == 1
			cnt += 1
		else
			cnt = 2
			err = 1
		end
		break if a[1] != a[0]
	else
		break if err == 1
		if a[0] > prevnum+1
			err = 2
			break
		end
	end
	prevnum = a[1]
end
if err == 2
	puts (prevnum+1).to_s + " 0"
elsif err == 1
	puts prevnum.to_s + " " + cnt.to_s
elsif n != prevnum
	puts (prevnum+1).to_s + " 0"
else
	puts "OK"
end

n,m = gets.chomp.split(/ /).map!{|x| x.to_i}
cnt = 0
err = 0
prevnum = 0
for i in 0..m-1
	a = gets.chomp.split(/ /).map!{|x| x.to_i}
	if a[0] == prevnum
		if err == 1
			cnt += 1
		else
			cnt = 2
			err = 1
		end
		break if a[1] != a[0]
	else
		break if err == 1
		if a[0] > prevnum+1
			err = 2
			break
		end
	end
	prevnum = a[1]
end
if err == 2
	puts (prevnum+1).to_s + " 0"
elsif err == 1
	puts prevnum.to_s + " " + cnt.to_s
else
	puts "OK"
end


gets.to_i.times do
  gets
  xs = gets.split.map(&:to_i)
  as = xs.zip(0..).filter_map { |x, i| x % 2 if i % 2 == 0 }
  bs = xs.zip(0..).filter_map { |x, i| x % 2 if i % 2 == 1 }
  puts as.uniq.size == 1 && bs.uniq.size == 1 ? "YES" : "NO"
end

def all_odds?(arr)
  arr.each do |a|
    if a.even?
      return false
    end
  end
  return true
end

def all_evens?(arr)
arr.each do |a|
  if a.odd?
    return false
  end
end
return true
end

def odd_even_increments(arr, n)
  if all_odds?(arr) || all_evens?(arr)
    return true
  end
  i = 0
  while i < n
    if (i+1) % 2 != 0
      arr[i] += 1
    end
    i += 2
  end

  if all_evens?(arr) || all_odds?(arr)
    return true
  end
  i = 1

  while i < n
    if (i+1) % 2 == 0
      arr[i] += 1
    end
    i+=2
  end

  if all_odds?(arr) || all_odds?(arr)
    return true
  end

  return false
end

t = gets.chomp.to_i
inputs = []
(0..t-1).each do |i|
  n = gets.chomp.to_i
  arr = gets.chomp
  arr = arr.split(" ").map(&:to_i)
  inputs.push([arr, n])
end

inputs.each do |element|
  result = odd_even_increments(element[0], element[1])
  if result
    puts "YES"
  else
    puts "NO"
  end
end

gets.to_i.times do
  gets
  a = gets.split.map(&:to_i)
  f = true
  a.each_with_index do |_q, i|
    f = false if i.even? && a[i] % 2 != a[0] % 2
    f = false if i.odd? && a[i] % 2 != a[1] % 2
  end
  if f
    puts :YES
  else
    puts :NO
  end
end

def all_odds?(arr)
  arr.each do |a|
    if a.even?
      return false
    end
  end
  return true
end

def all_evens?(arr)
arr.each do |a|
  if a.odd?
    return false
  end
end
return true
end

def odd_even_increments(arr, n)
  if all_odds?(arr) || all_evens?(arr)
    return true
  end
  i = 0
  while i < n
    if (i+1) % 2 != 0
      arr[i] += 1
    end
    i += 2
  end

  if all_evens?(arr) || all_odds?(arr)
    return true
  end
  i = 1

  while i < n
    if (i+1) % 2 == 0
      arr[i] += 1
    end
    i+=2
  end

  if all_odds?(arr) || all_odds?(arr)
    return true
  end

  return false
end

t = gets.chomp.to_i
inputs = []
(0..t-1).each do |i|
  n = gets.chomp.to_i
  arr = gets.chomp
  arr = arr.split(" ").map(&:to_i)
  inputs.push([arr, n])
end

inputs.each do |element|
  result = odd_even_increments(element[0], element[1])
  if result
    p "YES"
  else
    p "NO"
  end
end


def IsPerfect(x)
  Math.sqrt(x)%1==0
end

def Fibonnaci(n)
  IsPerfect(5*n*n + 4) || IsPerfect(5*n*n - 4)
end

n = gets.to_i
i = 1
res = ''
while i <= n
  res=Fibonnaci(i)? res+'O': res+'o'
  i+=1
end

puts res

n = gets.to_i
f, s = 0, 1
fib = []
while s <= n
  fib << s
  f, s = s, f + s
end
n.times { |i| print fib.include?(i + 1) ? 'O' : 'o' }

def fib(n)
  return 1 if n == 1
  return 1 if n == 2
  fib(n-2) + fib(n-1)
end

fib_arr = []
(1..20).each do |i|
  fib_arr << fib(i)
end

fib_s = 'o' * 10000

fib_arr.each do |f|
  fib_s[f-1] = 'O'
end

n = gets.to_i

puts fib_s[0..n-1]

n = gets.to_i

name = String.new

name[0] = 'O'

unless n < 2
    name[1] = 'O'
end

a = 1
b = 2

for i in 2...n
    if (i+1) == a+b
        name[i] = 'O'
        a = i+1
        a,b=b,a
    else
        name[i] = 'o'
    end
end

puts name

n=gets.to_i
s='o'*n
a=b=1
while b<=n
	s[b-1]='O'
	a,b=b,a+b
end
puts s

def IsPerfect(x)
  Math.sqrt(x)%1==0
end

def Fibonnaci(n)
  IsPerfect(5*n*n + 4) || IsPerfect(5*n*n - 4)
end

n = gets.to_i
i = 0
res = ''
while i < n
  res=Fibonnaci(i)? res+'O': res+'o'
  i+=1
end

puts res

n = gets.to_i
res = 'OOOoO'
m = 2
while res.size<=n
  m.times do
    res+='o'
  end
  res+='O'
  m=m**2
end
puts res[0,n]

def fib(n)
  return 1 if n == 1
  return 1 if n == 2
  fib(n-2) + fib(n-1)
end

fib_arr = []
(1..13).each do |i|
  fib_arr << fib(i)
end

fib_s = 'o' * 300

fib_arr.each do |f|
  fib_s[f-1] = 'O'
end

n = gets.to_i

puts fib_s[0..n-1]

def fib(n)
  return 1 if n == 1
  return 1 if n == 2
  fib(n-2) + fib(n-1)
end

fib_arr = []
(1..13).each do |i|
  fib_arr << fib(i)
end

fib_s = 'o' * 10000

fib_arr.each do |f|
  fib_s[f-1] = 'O'
end

n = gets.to_i

puts fib_s[0..n-1]

n = gets.to_i
f, s = 0, 1
fib = []
n.times do
  fib << s
  f, s = s, f + s
end
n.times { |i| print fib.include?(i + 1) ? 'O' : 'o' }


gets.strip.to_i.times do
  pins = []
  gets.strip.to_i.times do
    pins << gets.strip
  end
  steps = 0
  pins.each_with_index do |p, i|
    c = p.dup
    until !(pins.slice(0, i).concat(pins.slice(i + 1, pins.size))).include?(c)
      c = p.dup
      c[(0..3).to_a.shuffle.first] = ('0'..'9').to_a.shuffle.first
    end
    if c != p
      pins[i] = c
      steps += 1
    end
  end
  puts steps
  puts pins.join("\n")
end

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

n = gets.to_i

n.times do
 count = gets.to_i
 cards = []
 digits = Array.new(10, false)

 count.times do |i|
  cards << card = gets.chomp.split('').map(&:to_i)
  digits[cards[i][0]] = true
 end

 moves = 0
 table = {}

 i = 0
 while i < count do
  j = i + 1
  while j < count do
   table[[i, j]] = same = cards[i] == cards[j]

   if same
    k = 0
    while digits[k] do
     k += 1
    end
    cards[i][0] = k
    digits[k] = true
    moves += 1
    break
   end

   j += 1
  end
  i += 1
 end

 puts moves
 cards.each { |card| puts card.join('') }
end

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

n = gets.to_i

n.times do
 count = gets.to_i
 cards = []
 digits = []
 4.times { digits << Array.new(10, false) }

 count.times do |i|
  cards << card = gets.chomp.split('').map(&:to_i)
  4.times do |j|
   digits[j][cards[i][j]] = true
  end
 end

 moves = 0
 table = {}

 i = 0
 while i < count do
  j = i + 1
  while j < count do
   table[[i, j]] = same = cards[i] == cards[j]

   if same
    k = 0
    while digits[0][k] do
     k += 1
    end
    cards[i][0] = k
    digits[0][k] = true
    moves += 1
    break
   end

   j += 1
  end
  i += 1
 end

 puts moves
 cards.each { |card| puts card.join('') }
end

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

require 'prime'

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

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

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

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

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

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

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

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

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

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

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

t = inp[0]
t.times do
  h = {}
  n = inp[0]
  d = []
  mc = 0
  n.times{d<<gets.chomp}
  d.each do |s|
    unless h[s]
      h[s] = 1
      mc += 1
    end
  end
  ans = 0
  anst = []
  d.each do |s|
    if h[s] == 1
      anst.push(s)
      h[s] = true
    else
      (0..9).each do |dd|
        s[-1] = dd.to_s
        if(h[s])
          next
        else
          anst.push(s)
          h[s] = true
          break
        end
      end
    end
    next if h[s]
  end
  p n-mc
  puts anst
end

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

n = gets.to_i

n.times do
 count = gets.to_i
 cards = []
 digits = Array.new(10, false)

 count.times do |i|
  cards << card = gets.chomp.split('').map(&:to_i)
  digits[cards[i][0]] = true
 end

 moves = 0

 i = 0
 while i < count do
  j = i + 1

  while j < count do
   if cards[i] == cards[j]

    k = 0
    k += 1 while digits[k]

    cards[i][0] = k
    digits[k] = true
    moves += 1
    break
   end

   j += 1
  end
  i += 1
 end

 puts moves
 cards.each { |card| puts card.join('') }
end

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

n = gets.to_i

n.times do
 count = gets.to_i
 cards = []
 digits = []
 4.times { digits << Array.new(10, false) }

 count.times do |i|
  cards << card = gets.chomp.split('').map(&:to_i)
  4.times do |j|
   digits[j][cards[i][j]] = true
  end
 end

 moves = 0
 table = {}

 i = 0
 while i < count do
  j = i + 1
  while j < count do
   table[[i, j]] = same = cards[i] == cards[j]

   if same
    k = 0
    while digits[0][k] do
     k += 1
    end
    cards[i][0] = k
    digits[0][k] = true
    moves += 1
    break
   end

   j += 1
  end
  i += 1
 end

 puts moves
 puts cards.inspect
end


N = gets.to_i
B = gets.split.map(&:to_i)

sum = 0
ans = []

B.each do |b|
  if b >= 0
    sum += b
    ans << sum
  else
    ans << sum + b
  end
end

puts ans.join(' ')

# coding: utf-8

# Maximums

n = gets.to_i
remax = 0
ax = []
gets.split.each { |i|
    i = i.to_i
    ax << remax + i
    if remax < (remax + i)
        remax = remax + i
    end
}

puts ax.join ' '

n = gets.to_i
b = gets.split.map(&:to_i)
x = [0]
a = []
n.times do |i|
  a[i] = b[i] + x[i]
  x[i + 1] = [x[i], a[i]].max
end
puts a.join(" ")

max = 0

gets
puts(gets.split(' ').map do |e|
  pmax = max
  max = [max, e.to_i + max].max
  e.to_i + pmax
end.join(' '))

n = gets.chomp.to_i
arr = gets.split(" ").map!{|el| el.to_i}
result = []

current_max = arr[0]
result << arr[0]
1.upto(n-1) do |i|
  new_element = arr[i] + current_max
  result << new_element
  current_max = new_element if new_element > current_max
end

result.each do |x|
  print x.to_s + " "
end

n = gets.chomp.to_i
arr = gets.split(" ").map!{|el| el.to_i}
result = []

current_max = arr[0]
result << arr[0]
1.upto(n-1) do |i|
  new_element = arr[i] + current_max
  result << new_element
  current_max = new_element if new_element > current_max
end

p result

N = gets.to_i
B = gets.split.map(&:to_i)

sum = 0
ans = []

B.each do |b|
  sum += b
  ans << sum
end

puts ans.join(' ')


gets.strip.to_i.times do
  n, k = gets.strip.split(' ').map(&:to_i)
  per_k = ((n / k).to_i * k)
  if per_k.zero?
    puts [n, (k / 2).to_i].min
  else
    puts per_k + [(n % per_k), (k / 2).to_i].min
  end
end

gets.strip.to_i.times {
    n, k = gets.strip.split(' ').map(&:to_i);
    x = ((n / k).floor * k)
    n -= x
    y = (k / 2).floor
    puts x + y if y <= n
    puts x + n if y > n
}

t=gets.to_i
t.times do
    n,k=gets.split.map(&:to_i)
    c1=(n/k)*k
    n-=c1
    c2=[n,k/2].min
    puts c1+c2
end

readline.to_i.times do
  n, k = readline.split.map(&:to_i)
  a = n/k
  print([n, a*k + k/2].min, "\n")
end

gets.to_i.times do
	a, b = gets.split.map(&:to_i)
	puts [a, a / b * b + b / 2].min
end

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

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

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

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

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

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

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

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

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

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

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

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end

q = inp[0]
d = []
ans = []
q.times{d<<inp}
q.times do |i|
  n,m = d[i]
  a = n/m
  ans.push([n,a*m+m/2].min)
end
puts ans

gets.strip.to_i.times do
  n, k = gets.strip.split(' ').map(&:to_i)
  per_k = ((n / k).to_i * k)
  if per_k.zero?
    puts n
  else
    puts per_k + [(n % per_k), (k / 2).to_i].min
  end
end

gets.strip.to_i.times {
    n, k = gets.strip.split(' ').map(&:to_i);
    x = (n / k).floor
    n -= (x * k)
    y = n - (n / 2).floor;
    puts y + (x * k)
}


n = gets.to_i
sum = 0

a = []
a = gets.split.map &:to_i

(0...n).each do |i|
    sum += a[i]
end

puts 1.0 * sum / n

n, a = gets.to_i, gets.chomp.split.map {|x| x.to_i / 100.0 }
puts a.inject(:+) / n * 100.0

n = gets.to_i
k = gets.split.map{|e| e.to_f}
puts k.inject(0){|r,e| r+e}/n

k = gets.to_f
a = gets.split.map(&:to_i).reduce(:+)

puts a/k

n = gets.to_f
arr = gets.split.map &:to_f
total = 0
arr.each { |x| total += x / 100.0 }
printf "%.12f",100.0 * total / n

n = gets.to_i
sums = gets.split.map(&:to_f).inject(:+)
puts sums/n

n = gets.strip.to_i
p = gets.strip.split.map(&:to_i)
ans = 0
n.times do |i|
    ans += p[i] / 100.0
end
ans /= n
ans *= 100
puts "%.12f" % ans

n=gets.to_f
x=gets.split.map{|e| e.to_f}.inject(0){|sum,e| sum+e}
puts x/n

n = gets.to_i
p gets.split.map(&:to_i).inject(:+) / n.to_f

n = gets.to_i
sum = gets.split(' ').map(&:to_i).inject(:+)
puts Rational(sum,n).to_f

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

puts (arr.inject(0, :+))/n.to_f

n=gets.to_i
p=gets.chomp.split.collect{|a| a.to_i}
puts Float(p.reduce(:+))/(Float(p.size*100.0))*100.0

n = Integer(gets)
input = gets.chomp
nums = input.split
p = Array.new
for i in 0...n
    p[i] = Float(nums[i])
end
sum = 0
for i in 0...n
    if p[i] != 0
        sum += p[i] / 100
    end
end

puts sum / n * 100

number = gets.chomp.to_i
pi = gets.chomp
percentages = pi.split

x = 0
percentages.each do |orange|
	x += orange.to_i
end

print x/number.to_f

n=gets.to_i
per=gets.split.map(&:to_i)
count=0
per.each {|t| count+=t}
puts 1.0*count/n;

#puts "Enter number of juice bottle\n"
n = gets.to_i
t = 0
#puts "Enter percentage by one space\n"
s = gets.chomp.to_s.split(" ")
for i in 0...n do
    t += s[i].to_i
end
r = t/n.to_f
puts "%1.12f" % r

# cook your code here

n = gets.to_i
s = 0

g = gets.chomp.split

for i in 0...n
    s = s + g[i].to_i
end

s = s/n.to_f

puts s

require "scanf"
ans = 0
n = gets.to_i
gets.split(" ").each {
    |i| ans += i.to_i
}
ans = ans * 1.0 / n;
printf("%.12f\n",ans)

n = gets.to_f

v = gets.split.map(&:to_i).reduce(:+)

puts v/n

n = gets.to_f
juice = gets.split(' ').take(n).map { |e| e.to_f }
total = 0
juice.each do |volume|
  total += volume
end
print total / n

n = gets.to_i
puts gets.split.map(&:to_f).inject(:+)/n

n = gets.to_i
sum = 0
gets.split(" ").each{|a|
sum+=a.to_f
}
puts sum.to_f/n

n = STDIN.gets
ps = STDIN.gets.split

n = n.to_i
s = 0
ps.each do |p|
  s += p.to_i
end

p s.to_f / n

gets
puts(gets.split(' ').map(&:to_i).instance_eval { reduce(&:+) / size.to_f })

# Codeforces Round #126
# Problem B -- Drinks
n = gets.to_i
puts gets.split.map(&:to_i).inject { |s, i| s + i } / n.to_f

n = gets.chomp.to_i
a = gets.chomp.split(" ")
sum = 0
while b = a.shift do
    sum += b.to_i
end
puts (sum+0.0)/n

n = gets.to_f
print "%.12f" % (gets.split.map(&:to_i).inject(&:+) / n)

def calc_proc(num_arr)
  numer = num_arr.inject(:+)
  denom = 100 * num_arr.size
  Float(100 * numer) / denom
end

if __FILE__ == $0
  #while line = gets
  #  puts line
  #end
  num_arr = []
  STDIN.each_with_index do |line, index|
    if index == 1
      num_arr = line.split.collect {|val| Integer(val) }
    end
  end
  #p num_arr
  STDOUT.puts calc_proc(num_arr)
end

n = gets.to_i
sum = gets.split.map { |x| x.to_i }.reduce(:+)

puts '%.6f' % (sum.to_f / n)

n = gets.to_i
a = gets.split.map(&:to_i)
sum = 0.0
a.each{|dj| sum+=dj}
puts sum/n

n = gets.to_i
p = gets.split(" ").map{|x| x.to_i}
s = p.inject(:+)
puts s.to_f/n

# codeforce#127(Div2.A)
n = gets.chomp.to_i
p = gets.chomp.split(" ").map{|e| e.to_i}
sum = p.inject{|i, sum| sum += i}

puts (sum.to_f / n.to_f)

require 'bigdecimal'

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

r = BigDecimal(p.sum.to_s) / n
puts r.to_f.round(8)

class Main
  #def get_problem_link
  #  problem_link = "https://codeforces.com/contest/200/problem/B"
  #  return problem_link
  #end

  #def get_submission_link
  #  submission_link = ''
  #  return submisson_link
  #end

  #begin
  #of codeforces interface
  def run_interface
    n = gets.to_i
    k = gets.split(' ').map(&:to_i)
    puts solution(n, k)
  end
  #end
  #of codeforces interface

  def solution(n, drinks_array)
      sum = 0
      drinks_array.each {|value|
        sum += value
      }
      return sum.fdiv(n).round(12)
  end

end

#then upload to codeforces uncomment this line:
Main.new.run_interface


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

puts "#{xs[1]-xs[0]} #{xs[-1]-xs[0]}"

for i in 1..n-2
  if xs[i]-xs[i-1] < xs[i+1]-xs[i]
    print xs[i]-xs[i-1]
  else
    print xs[i+1]-xs[i]
  end
  print " "
  if   xs[i]-xs[0] < xs[-1]-xs[i]
    print xs[-1]-xs[i]
  else
    print xs[i]-xs[0]
  end
  print "\n"
end

puts "#{xs[-1]-xs[-2]} #{xs[-1]-xs[0]}"

n = gets.to_i
a = gets.split.map(&:to_i)
a = a.map{|x| x -= a[0]}
n.times do |i|
  mi = a[n - 1]
  mi = a[i] - a[i - 1] if i != 0
  mi = [mi, a[i + 1] - a[i]].min if i != n - 1
  mx = [a[i] - a[0], a[n - 1] - a[i]].max
  puts "#{mi} #{mx}"
end

n = gets.chomp
n = n.to_i

arr = gets.chomp.split(' ')

n.times do |x|
  arr[ x ] = arr[ x ].to_i
end

n.times do |ith|
  if ith == 0
    mx = ( arr[ 1 ] - arr[ 0 ]).abs
    mn = ( arr.last - arr[ 0 ] ).abs
    mx, mn = mn, mx if mx < mn
    print mn.to_s +  " "  + mx.to_s + "\n"
  elsif ith > 0 && ith < n - 1
    mn = [ ( arr[ ith ] - arr[ ith - 1 ] ).abs, (arr[ ith ] - arr[ ith + 1 ]).abs ].min
    mx = [ ( arr.last - arr[ ith ] ).abs, ( arr.first - arr[ith] ).abs ].max
    mx, mn = mn, mx if mx < mn
    print mn.to_s + " " + mx.to_s + "\n"
  else
    mn = ( arr[ ith ] - arr[ ith - 1 ] ).abs
    mx = ( arr.first - arr[ith] ).abs
    mx, mn = mn, mx if mx < mn
    print mn.to_s + " " + mx.to_s + "\n"
  end

end

cityNum = gets.chomp.to_i
city = gets.chomp.split(' ').map {|item| item.to_i}
result = []

city.each_with_index do |value, index|
	ans = []

	if index > 0
		left = city[index - 1]
	else
		left = -100000000001
	end

	if index < cityNum - 1
		right = city[index + 1]
	else
		right = 100000000001
	end

	mostLeft = city[0]
	mostRight = city[cityNum - 1]

=begin
	puts "cityNum : #{cityNum}"
	puts "index : #{index}"
	puts "left : #{left}"
	puts "right : #{right}"
	puts "mostLeft : #{mostLeft}"
	puts "mostRight : #{mostRight}"
=end

	if value - left > right - value
		ans << right - value
	else
		ans << value - left
	end

	if value - mostLeft > mostRight - value
		ans << value - mostLeft
	else
		ans << mostRight - value
	end

	result << ans
end

result.each do |value|
	value.each do |item|
		print "#{item} "
	end

	puts ''
end

# http://codeforces.com/contest/567/problem/A
n = gets.chomp.to_i
array = gets.chomp.split.map(&:to_i)

array.each.with_index do |num, idx|
  possibles = [].tap do |out|
    out << array[idx - 1] if idx != 0
    out << array[idx + 1] if idx != (n - 1)
    out << array[0] if idx != 0
    out << array[n - 1] if idx != (n - 1)
  end
  possibles.map! { |b| (b - num).abs }.sort!

  puts [possibles.first, possibles.last].join(' ')

end

n = gets.chomp.to_i;
arr = gets.chomp.split.map(&:to_i);
min = Array.new;
max = Array.new;
min[0] = arr[1] - arr[0];
max[0] = arr[-1] - arr[0];

(1..(n - 2)).each do |i|
   min[i] = [arr[i] - arr[i - 1], arr[i + 1] - arr[i]].min();
   max[i] = [arr[i] - arr[0], arr[-1] - arr[i]].max();
   # print min[i], max[i], arr[i], "\n";
 end
min.push(arr[-1] - arr[-2]);
max.push(arr[-1] - arr[0]);

(0..n-1).each do |i|
  puts "#{min[i]} #{max[i]}";
end

def calc (mas)
  pairs = []
  mas.each_index { |i| mas[i]= mas[i].to_i }
  mas.each_index { |i|
    dist=[i>0 ? mas[i]-mas[i-1] : 2**50, i+1<mas.size ? mas[i+1]-mas[i] : 2**50].min
    pairs[i] = [dist,[mas[i]-mas.first,mas.last-mas[i]].max]
  }
  pairs
end
gets
a = gets.split(" ")
b = calc(a)
b.each{|x| puts x.join(' ')}

# require 'pry'
def read_ints; gets.chomp.split.map(&:to_i) end
n = read_ints[0]
x = read_ints
puts (x[1]-x[0]).to_s+" "+(x[-1]-x[0]).to_s
(1..(n-2)).each do |i|
	puts [x[i]-x[i-1],x[i+1]-x[i]].min.to_s + " " + [x[i]-x[0],x[-1]-x[i]].max.to_s
end

puts (x[-1]-x[-2]).to_s+" "+(x[-1]-x[0]).to_s

n = gets.to_i
a = gets.split.map(&:to_i)
print a[1] - a[0],' ',a.last - a[0],"\n"
1.upto(n - 2) do |i|
	print [a[i] - a[i - 1] , a[i + 1] - a[i]].min,' ',[a.last - a[i], a[i] - a.first].max,"\n"
end
print a.last - a[ n - 2],' ',a.last - a.first

# coding: utf-8

# if __FILE__ == $0
# end

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

cities.each_with_index { |base, index|
    near, far = 2* (10**9), 0

    # near
    [index -1, index +1].each { |nidx|
        if nidx >= 0 && nidx < n
            dist = (cities[index] - cities[nidx]).abs
            if dist < near
                near = dist
            end
        end
    }

    # far
    [0, n-1].each { |fidx|
        if index != fidx
            dist = (cities[index] - cities[fidx]).abs
            if dist > far
                far = dist
            end
        end
    }

    puts "#{near} #{far}"
}

n = gets.to_i
a = gets.split.map(&:to_i)
a = a.map{|x| x -= a[0]}
n.times do |i|
  mi = n
  mi = a[i] - a[i - 1] if i != 0
  mi = [mi, a[i + 1] - a[i]].min if i != n - 1
  mx = [a[i] - a[0], a[n - 1] - a[i]].max
  puts "#{mi} #{mx}"
end

cityNum = gets.chomp.to_i
city = gets.chomp.split(' ').map {|item| item.to_i}
result = []

city.each_with_index do |value, index|
	ans = []

	if index > 0
		left = city[index - 1]
	else
		left = -1000000001
	end

	if index < cityNum - 1
		right = city[index + 1]
	else
		right = 1000000001
	end

	mostLeft = city[0]
	mostRight = city[cityNum - 1]

=begin
	puts "cityNum : #{cityNum}"
	puts "index : #{index}"
	puts "left : #{left}"
	puts "right : #{right}"
	puts "mostLeft : #{mostLeft}"
	puts "mostRight : #{mostRight}"
=end

	if value - left > right - value
		ans << right - value
	else
		ans << value - left
	end

	if value - mostLeft > mostRight - value
		ans << value - mostLeft
	else
		ans << mostRight - value
	end

	result << ans
end

result.each do |value|
	value.each do |item|
		print "#{item} "
	end

	puts ''
end


t = gets.to_i
def check_odd(n, arr)
  flag = true
  [*0..(n/2)].each{|i|
    if arr[i]<i
      flag = false
      break
    end
  }
  [*(n/2)+1..n-1].each{|i|
    if arr[i]<(n-1-i)
      flag = false
      break
    end
  } if flag
  flag
end
def check_even(n, arr)
  flag = true
  [*0..(n/2)-1].each{|i|
    if arr[i]<i
      flag = false
      break
    end
  }
  [*(n/2)..n-1].each{|i|
    if arr[i]<(n-1-i)
      flag = false
      break
    end
  } if flag
  flag = false if arr[n/2-1]==n/2-1 && arr[n/2]==n/2-1
  flag
end
t.times{
  n = gets.to_i
  arr = gets.split.map(&:to_i)
  if n.odd?
    puts check_odd(n, arr) ? "Yes" : "No"
  else
    puts check_even(n, arr) ? "Yes" : "No"
  end
}

num_tests = gets.chomp.to_i

def array_sharpening(arr)
  peak = false
  i = 0
  while i < arr.size
    if arr[i] < i && !peak
      return "No"
    elsif arr[i] < arr.size - i - 1
      return "No" if arr[i] < i
      peak = false
    elsif !peak
      peak = true
    end
    i += 1
  end
  peak ? "Yes" : "No"
end

i = 0
while i < num_tests
  n = gets.chomp
  arr = gets.chomp.split(" ").map(&:to_i)
  puts array_sharpening(arr)
  i += 1
end

T = gets.to_i

def checker(nums)
  success = true
  l = nums.size
  cur = 0
  mode = :increase

  l.times do |i|
    if mode == :increase
      if nums[i] < cur
        mode = :decrease
        cur = nums[i - 1]
      else
        cur += 1
      end
    end

    if mode == :decrease
      cur = [cur - 1, nums[i]].min

      if cur < 0
        success = false
      end
    end
  end

  success
end

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

  if checker(a) || checker(a.reverse)
    puts 'Yes'
  else
    puts 'No'
  end
end

num_tests = gets.chomp.to_i

def array_sharpening(arr)
  peak = false
  i = 0
  while i < arr.size
    if arr[i] < i && !peak
      return "No"
    elsif arr[i] < arr.size - i - 1
      peak = false
    elsif !peak
      peak = true
    end
    i += 1
  end
  peak ? "Yes" : "No"
end

i = 0
while i < num_tests
  n = gets.chomp
  arr = gets.chomp.split(" ").map(&:to_i)
  puts array_sharpening(arr)
  i += 1
end


t = gets.to_i
t.times do
  n,x = gets.split.map(&:to_i)
  p x*2
end

# https://codeforces.com/contest/1194/problem/A
t = gets.to_i

t.times do
  _, x = gets.split.map &:to_i
  puts x * 2
end

n = gets
output = []

Array.new n.to_i do
  input = gets
  output << 2 * input.split(" ")[1].to_i
end

output.each do |e|
  puts e
end

gets.strip.to_i.times do
  n, x = gets.strip.split(' ').map(&:to_i)
  puts x * 2
end

t = gets.to_i
t.times do
  n, x = gets.split.map(&:to_i)
  puts x * 2
end

num = gets.to_i
num.times do
  puts gets.split(" ").last.to_i*2
end

t = gets.to_i
t.times do
  n, x = gets.split.map &:to_i
  puts 2*x
end

n=gets.to_i
for _ in 1..n
a=gets.split.map &:to_i
puts a[1]*2
end

num = gets.to_i
num.times do
  puts gets.split(" ").last.to_i
end


require 'set'
N = 1000000
n = gets.to_i
#x = Set.new(gets.split.map(&:to_i))
x = gets.split.map(&:to_i).sort!
a = []
y = []
pairs = 0
for i in x
  a[i] = 1
end
for i in (1..N)
  if a[i] and a[N+1-i]
    pairs += 1 if i <= N/2
  elsif a[i]
    y << (N + 1 -i)
  end
end
for i in (1..N)
  break if pairs == 0
  unless a[i] or a[N+1-i]
    y << i << (N+1-i)
    pairs -= 1
  end
end
puts y.size
print y.join(' ')


n,x=gets.to_i,0
n.times{x+=gets.split[1].to_f}
p 5+x/n

n = gets.to_i
sum = 0.00
for i in 1..n do
    a, b = gets.split
    sum += b.to_f
end
puts sum / n + 5


n = gets.to_i

coco = 4
moco = n - 4
until (coco%2 == 0 || coco%3 == 0) && (moco%2 == 0 || moco%3 == 0)
 coco+=1
 moco-=1
end

puts coco.to_s + " " + moco.to_s

nn = gets.to_i

if nn%2==0
    puts "4 " + (nn-4).to_s ;
else
    puts "9 " + (nn-9).to_s ;
end

require 'prime'

n = gets.chomp.to_i
(2..n-1).each do |i|
    if !Prime.prime?(i) && !Prime.prime?(n-i)
        puts "#{i} #{n-i}"
        exit
    end
end

require "prime"
n = gets.chomp.to_i
a,b = 4,0
loop do
	b = n - a
	break if !b.prime? and !a.prime?
	a += 1
end
puts "#{a} #{b}"

n = STDIN.readline.to_i
if n%2 == 0
	puts [4, n-4].join(' ')
else
	puts [9, n-9].join(' ')
end

def sost(a)
  return false if a<=2
  for i in 2..a**(1/2.0)
    if a%i==0
      return true
    end
  end
  false
end

n=gets.to_i

i=4
if n%4==0
  puts "#{n/2} #{n/2}"
else
  loop do
    n1=n-i
    if sost(i)==true && sost(n1)==true
      puts "#{n1} #{i}"
      break
    end
    i+=1
  end
end

def check_prime(num)
	for i in 2..Math.sqrt(num)
		if num % i == 0
			return false
		end
	end
	return true
end

n = gets.to_i
if check_prime(n-8)
	puts "9 #{n-9}"
else
	puts "8 #{n-8}"
end

require 'prime'
puts (z = (3...n = gets.to_i).to_a.find {|x| !x.prime? && !(n-x).prime? }).to_s+" "+(n-z).to_s

require 'prime'

n = $stdin.readline.to_i

a = n/2
b = n - a
while a.prime? || b.prime?
    a-=1
    b+=1
end

puts "#{a} #{b}"

#le roi est mort is here
x = gets.to_i
if x % 2 == 0
  puts 4, ' ', x-4
else
  puts 9, ' ', x-9
end

n = gets.to_i
if n % 2 == 0
  puts n % 2 + 4
  puts n - n % 2 - 4
else
  puts n % 2 + 8
  puts n - n % 2 - 8
end

n = gets.chomp.to_i
if n%2==0
  n-=8
  puts "8 #{n}"
else
  n-=9
  puts "9 #{n}"
end

require 'prime'
n=gets.to_i
i = 4
loop do
  if !Prime.prime?(i)&&!Prime.prime?(n-i)
    print "#{i} #{n-i}"
    break
  else
    i +=1
  end
end

n = gets.to_i

if n.odd?
  if n > 18
    x = 9
    y = n - 9
  else
    x = n - 9
    y = 9
  end
  puts "#{x} #{y}"
else
  puts "#{4} #{n-4}"
end

require 'prime'
n=gets.to_i
4.upto(n){|i|
	if !Prime.prime?(i)&&!Prime.prime?(n-i) then
		puts [i,n-i]*" "
		break
	end
}

n = gets.chomp.to_i

if n%2 == 0
  puts [8,n-8].sort.join(' ')
else
  puts [9,n-9].sort.join(' ')
end

def sost(n)
  return false if n==1
    #перебираем возможные делители от 2 до sqrt(n)
	i=2
    while i*i<=n do
	 return true if n%i==0
	 i+=1
	end
  return false
end

n=gets.to_i

if n%2==1
 x=(n/2.0).floor
 y=(n/2.0).ceil
end

if n%2==0
 x=n/2
 y=n/2
end

until (sost(x)==true and sost(y)==true)
 x-=1
 y+=1
end

puts "#{x} #{y}"

n = gets.to_i

if n.even?
    puts "#{4} #{n - 4}"
else
    puts "#{9} #{n - 9}"
end

def is_composite(number)
	return false if [1, 2, 3].include?(number)
	2.upto(Math.sqrt(number).to_i) {|element| return true if number % element == 0}
	return false
end
number = gets.strip.to_i
4.upto(number / 2) do |first_half|
	other_half = number - first_half
	if is_composite(first_half) && is_composite(other_half)
		puts "#{first_half} #{other_half}"
		break
	end
end

n = Integer(gets)

def prime(x)
    e = 1
    for i in 2...x
        if x % i == 0
            e = 0
            break
        end
    end
    return e
end

a = 0
b = 0
c = 0
for i in 4...n
   for j in 2...i
    if i % j == 0
        a = i
        b = n - a
        if prime(b) == 0
           c = 2
        end
    end
   end
   if c == 2
    break
   end
end

print a, " ", b

number = gets.chomp.to_i

if number % 2 == 0
	print 4
	print " "
	print number-4
else
	print 9
	print " "
	print number-9
end

n = gets.to_i

if n % 2 == 0 ;
	print 4, ' ', n - 4, ?\n
else
	print 9, ' ', n - 9, ?\n
end

N=gets.chomp.to_i
def is_composite(num)
  i=2
  while i*i<=num
    return true if num%i==0
    i+=1
  end
  false
end

def solve(n)
  if n%2==0
    left=n/2;right=n/2
  else
    left=n/2;right=(n/2)+1
  end
  while left>0 && right<n
    if is_composite(left) && is_composite(right)
      puts left.to_s+" "+right.to_s
      return
    else
      left-=1;right+=1
    end
  end
end
solve(N)

number = gets.chomp.to_i
number1 = number / 2
number2 = number - number1

while (number1%2 != 0 && number1%3 != 0) || (number2%2 != 0 && number2%3 != 0)
  number1 = number1 + 1
  number2 = number - number1
end

print number1.to_s + " "+ number2.to_s

require 'prime'
n = gets.to_i
(4..n).each do |x|
    if !x.prime? && !(n-x).prime?
        puts "#{x} #{n-x}"
        break
    end
end

def prime n
	if n == 1
		return 0
	elsif n == 2
		return 1
	end
	for i in 2..Math.sqrt(n)
		if n % i == 0
			return 0
		end
	end
	return 1
end

index = 1
n = gets
n = n.to_i
for i in 4..n
	if (prime(i) == 0 && prime(n - i) == 0)
		index = i
		break
	end
end
puts "#{index} #{n - index}"

require 'prime'

n = gets.to_i
4.upto(n / 2) do |i|
	if !Prime.prime?(i) && !Prime.prime?(n - i) then
		printf("%d %d\n", i, n - i)
		exit(0)
	end
end

require 'prime'

n = gets.to_i
2.upto(n / 2) do |i|
	if !Prime.prime?(i) && !Prime.prime?(n - i) then
		printf("%d %d\n", i, n - i)
		exit(0)
	end
end

require 'prime'
n = gets.to_i
1000000.times do |i|
	if Prime.prime?((n / 2) - i) != true && Prime.prime?((n - n / 2) + i) != true
		puts n / 2 - i, n - n / 2 + i
		break
	end
end

$o = {1 => false, 2 => false, 3 => false}

def compost?(n)
  return $o[n] unless $o[n].nil?

  d = 2
  while d <= Math.sqrt(n)
    if n % d == 0
      $o[n] = true
      return true
    end
    d += 1
  end

  $o[n] = false
  return false
end

# (1..1_000_000).each{|x| compost?(x); puts x if x % 100 == 0}
# puts $op

def solve(n)
  (4..n).each do |c|
    return [c, n - c] if compost?( n - c ) && compost?(c)
  end
  return []
end

if __FILE__==$0
  n = gets.to_i
  s = solve(n)
  puts "#{s[0]} #{s[1]}"
end

n = gets.chomp.to_i

prime = Array.new( 1000005 , 0 )
num = Array.new( 1000005 , 0 )

i = 2
m = 0

until i==1000000 do

	if prime[i]==0
		j = i* i
		while j<=1000000 do
			prime[j] = 1
			j += i
		end

		num[m] = i
		m += 1

	end

	i += 1
end

for i in 2...m

	if prime[i]==1 && prime[n-i]==1
		puts "#{i} #{n - i}"
		break
	end

end

# cook your code here
n=gets.to_i;
if (n&1 == 0)
    p 8, n-8
else
    p 9, n-9
end

n = gets.to_i

x = [8, 9, 10].select { |i| n-i > 3 && ( (n-i).modulo(3).zero? || (n-i).modulo(2).zero? ) }.first

puts "#{x} #{n-x}"

n = gets.to_i
if (n%2 == 1)
	puts 9, n-9
else
	puts 4, n-4
end

n = gets.to_i
if n.odd?
	puts [9, n - 9].join ' '
else
	puts [4, n - 4].join ' '
end

require 'prime'

number = gets.chomp.to_i

(2...number).each do |num|
	if !Prime.prime?(num) && !Prime.prime?(number - num)
		puts "#{num} #{number - num}"
		break
	end
end

require "prime"
n=gets.to_i
(4..(n/2)).each do |i|
  next if Prime.prime?(i) || Prime.prime?(n-i)
  puts [i, n-i].join(" ")
  break
end

n = STDIN.readline.to_i
if n%2 == 0
	puts [4, n-4].join(' ')
else
	puts [3, n-3].join(' ')
end

require 'prime'
puts (z = (1..n = gets.to_i).to_a.find {|x| !x.prime? && !(n-x).prime? }).to_s+" "+(n-z).to_s

n = gets.to_i

coco = 4
moco = n - 4
until coco%2 == 0 || coco%3 == 0 && moco%2 == 0 || moco%3 == 0
 coco+=1
 moco-=1
end

p [coco, moco]

n = gets.to_i

coco = 4
moco = n - 4
until coco%2 == 0 || coco%3 == 0 && moco%2 == 0 || moco%3 == 0
 coco+=1
 moco-=1
end

puts coco.to_s + " " + moco.to_s

def sost(n)
  return false if n==1
    #перебираем возможные делители от 2 до sqrt(n)
	i=2
    while i*i<=n do
	 return true if n%i==0
	 i+=1
	end
  return false
end

n=gets.to_i
x=(n/2.0).floor
y=(n/2.0).ceil

s1=false
s2=false
while (sost(x)!=true and sost(y)!=true)
 x-=1
 y+=1
end

puts "#{x} #{y}"

def sost(n)
  return false if n==1
    #перебираем возможные делители от 2 до sqrt(n)
	i=2
    while i*i<=n do
	 return true if n%i==0
	 i+=1
	end
  return false
end

n=gets.to_i
if n%2==1
 x=(n/2.0).floor
 y=(n/2.0).ceil
end

if n%2==0
 x=n/2
 y=n/2
end

while (sost(x)!=true and sost(y)!=true)
 x-=1
 y+=1
end

puts "#{x} #{y}"

def sost(n)
  return false if n==1
    #перебираем возможные делители от 2 до sqrt(n)
	i=2
    while i*i<=n do
	 return true if n%i==0
	 i+=1
	end
  return false
end

n=gets.to_i
x=(n/2.0).floor
y=(n/2.0).ceil

s1=false
s2=false
while sost(x)!=sost(y)
 x-=1
 y+=1
end

puts "#{x} #{y}"

n = gets.to_i

if n % 2 == 0 ;
	print 2, ' ', n - 2, ?\n
else
	print 9, ' ', n - 9, ?\n
end

number = gets.chomp.to_i
print (number / 2).to_s + " "+ (number-(number/2)).to_s

def prime n
	if n == 1
		return 0
	elsif n == 2
		return 1
	end
	for i in 3..Math.sqrt(n)
		if n % i == 0
			return 0
		end
	end
	return 1
end

index = 1
n = gets
n = n.to_i
for i in 4..n
	if (prime(i) == 0 && prime(n - i) == 0)
		index = i
		break
	end
end
puts "#{index} #{n - index}"

def prime n
	if n == 1
		return 0
	elsif n == 2
		return 1
	end
	m = n - 1
	for i in 3..m
		if n % i == 0
			return 0
		end
	end
	return 1
end

index = 1
n = gets
n = n.to_i
for i in 4..n
	if (prime(i) == 0 && prime(n - i) == 0)
		index = i
		break
	end
end
puts "#{index} #{n - index}"

n = gets.to_i
if (n%2 == 1)
	puts 7, n-7
else
	puts 8, n-8
end


M=10**5+1
gets
a=Array.new(M,0)
x=Array.new(M){Array.new}
b=gets.split.map(&:to_i)
b.each{|c|a[c]+=1}
s=0
(M-1).downto(1){|m|
	if a[m]>0
		1.upto(m-1){|i|a[i]-=a[m]}
		t=[*s+1..s+a[m]]
		s+=a[m]
		a[m]=0
		1.upto(m){|i|x[i]+=t}
	end
}
if a.sort.first<0
	p -1
else
	p s
	puts b.map{|i|x[i].pop}*" "
end

n=gets.to_i
a=gets.split.map(&:to_i)
cnt=Array.new(100005,0)
a.each{|i|
        cnt[i]+=1
}
1.upto(100003){|i|
        if cnt[i]<cnt[i+1] then
                puts "-1"
                exit
        end
}
puts cnt[1]
a.each{|i|
        printf "%d ",cnt[i]
        cnt[i]-=1
}
puts


class GenomPart
    @genom
    @chars
    def initialize
        @genom = ""
        @chars = []
    end
    def is_valid_part(part)
        if @genom == ""
            return true
        end
        for i in (0...part.size)
            if @chars.include?(part[i])
                return true
            end
        end
        return false
    end
    def insert_part(part)
        if @genom == ""
            @genom = part
            @chars = part.chars
            return
        end
        @chars |= part.chars
        count = @genom.count(part)
        if count == @genom.size # genon is substring of part
            @genom = part
            #@chars = part.chars
        elsif count == part.size
            # nothing
        else
            if @genom.index(part[0...count]) != nil
                @genom = (@genom.chars | part.chars).join
            else
                @genom = (part.chars | @genom.chars).join
            end
            #@chars = @genom.chars
        end
    end
    def genom
        @genom
    end
end

n = gets.to_i
parts = []
n.times do
    s = gets.chomp
    parts.push(s)
end

genom_parts = []
while !parts.empty?
    genom = GenomPart.new
    while true
        action = false
        temp = parts.clone
        temp.each do |item|
            if genom.is_valid_part(item)
                action = true
                genom.insert_part(item)
                parts.delete(item)
            end
        end
        if !action
            break
        end
    end
    genom_parts.push(genom)
end

answer = ""
genom_parts.each do |part|
    answer += part.genom
end

puts answer

n=gets.to_i

def concatable?(a,b)
    concat=false
    a.size.times do |i|
        if b.include?(a[i])
            concat=true
        end
    end
    concat
end

def do_concat(a,b)
    if a.include?(b)
        a
    else
       if b.include?(a)
           b
       else
           if b.include?(a[0])
               (b+a).split(//).uniq.join
           else
               (a+b).split(//).uniq.join
           end
       end
    end
end
arr = []
n.times do |i|
    arr.push(gets.split("\n")[0].to_s)
end
arr=arr.uniq
k = arr.count-1
i = 0
while i<=k do
    broken = false
    for j in (i+1..k)
        if broken
            next
        end
        if concatable?(arr[i],arr[j])
            temp=do_concat(arr[i],arr[j])
            arr-=[arr[j]]
            arr[i]=temp
            k-=1
            i=0
            broken = true

        end
    end
    if not broken
        i+=1
    end
end
print arr.join

class GenomPart
    @genom
    @chars
    def initialize
        @genom = ""
        @chars = []
    end
    def is_valid_part(part)
        if @genom == ""
            return true
        end
        for i in (0...part.size)
            if @chars.include?(part[i])
                return true
            end
        end
        return false
    end
    def insert_part(part)
        if @genom == ""
            @genom = part
            @chars = part.chars
            return
        end
        @chars |= part.chars
        count = @genom.count(part)
        if count == @genom.size # genon is substring of part
            @genon = part
        elsif count == part.size
            # nothing
        else
            if @genom.index(part[0...count]) != nil
                @genom = (@genom.chars | part.chars).join
            else
                @genom = (part.chars | @genom.chars).join
            end
        end
    end
    def genom
        @genom
    end
end

n = gets.to_i
parts = []
n.times do
    s = gets.chomp
    parts.push(s)
end

genom_parts = []
while !parts.empty?
    genom = GenomPart.new
    while true
        action = false
        temp = parts.clone
        temp.each do |item|
            if genom.is_valid_part(item)
                action = true
                genom.insert_part(item)
                parts.delete(item)
            end
        end
        if !action
            break
        end
    end
    genom_parts.push(genom)
end

answer = ""
genom_parts.each do |part|
    answer += part.genom
end

puts answer


t = gets.chomp.to_i

t.times do
    n = gets.chomp.to_i
    a = gets.chomp.split(" ").map(&:to_i)
    b = gets.chomp.split(" ").map(&:to_i)
    aa = a.min
    bb = b.min
    i = 0
    goukei = 0
    until n == i
        sa = a[i] - aa
        sb = b[i] - bb
        goukei += sa + sb - [sa,sb].min
        i += 1
    end
    puts goukei
end

gets.to_i.times do

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

  a_min = a.min
  b_min = b.min

  answer = 0
  a.zip(b) do |x, y|
    diff_a = x - a_min
    diff_b = y - b_min
    answer += x - a_min < y - b_min ? y - b_min : x - a_min
  end
  puts answer
end

gets.to_i.times do

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

  a_min = a.min
  b_min = b.min

  puts a.zip(b).reduce(0) { |sum, pair| sum + [pair[0] - a_min, pair[1] - b_min].max }
end

gets.to_i.times do

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

  a_min = a.min
  b_min = b.min

  puts a.zip(b).reduce(0) { |sum, (x, y)| sum + [x - a_min, y - b_min].max }
end

t=gets.chomp.to_i

while t!=0
num= gets.chomp.to_i
candy = gets.chomp.split(' ').map!{ |o| o.to_i }
oranges = gets.chomp.split(' ').map!{ |o| o.to_i }

min_c= candy.min
min_o= oranges.min

#min= [min_c,min_o].max
c=0
i=0
while i< num
if(candy[i] !=min_c && oranges[i] != min_o)

vc,vo=candy[i]-min_c,oranges[i]-min_o

min_v=[vc,vo].min
c+=min_v
candy[i]-=min_v
oranges[i]-=min_v
end

i+=1
end
i=0
while i< num
if(candy[i] !=min_c)
vc=candy[i]-min_c
c+=vc
end
if(oranges[i] !=min_o)
vo=oranges[i]-min_o
c+=vo
end
i+=1
end
puts c
t-=1
end

times = gets.to_i

def resolve(candies, oranges)
  min_c = candies.min
  min_o = oranges.min
  ops_c = candies.map{|e| e-min_c}
  ops_o = oranges.map{|e| e-min_o}
  ops_c.zip(ops_o).each.map(&:max).sum
end

(1..times).each do |i|
  array_size = gets.to_i

  c,o = Array.new(array_size)
  c = gets.split(/\s+/).map(&:to_i)
  o = gets.split(/\s+/).map(&:to_i)
  puts resolve(c,o)
end

def read
    gets.split.map &:to_i
end
gets.to_i.times do
    n = gets.to_i
    a, b = read, read
    res, ma, mb = 0, a.min, b.min
    n.times do |i|
        res += [a[i] - ma, b[i] - mb].max
    end
    puts res
end

t = gets.to_i
ans = []
t.times do
  n = gets.to_i
  a = gets.chomp.split(" ").map(&:to_i)
  b = gets.chomp.split(" ").map(&:to_i)
  amin = a.min
  bmin = b.min
  cnt = 0
  n.times do |i|
    asub = a[i] - amin
    bsub = b[i] - bmin
    same = [asub,bsub].min
    cnt += same + asub - same + bsub - same
  end
  ans << cnt
end
ans.each do |x|
  puts x
end

gets.to_i.times do
    gets
    candies = gets.split(' ').map(&:to_i)
    oranges = gets.split(' ').map(&:to_i)

    puts candies.zip(oranges).inject(0) { |sum, (x, y)| sum + [x - candies.min, y - oranges.min].max }
end

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

  am = a.min
  bm = b.min

  puts 0.upto(n-1).to_a.map { |i| [a[i] - am, b[i] - bm].max }.inject(&:+)
end

n = gets.chomp.to_i

tests = []

n.times do
  test_length = gets.chomp.to_i
  test = []
  2.times do
    test.push(gets.chomp.split(' ').map {|e| e.to_i})
  end
  tests.push(test)
end

tests.each do |test|
  min_1 = test[0].min
  min_2 = test[1].min
  difference = 0
  (0..test[0].length - 1).each do |index|
    difference += [test[0][index] - min_1, test[1][index] - min_2].max
  end
  p difference
end

t=gets.chomp.to_i

while t!=0
num= gets.chomp.to_i
candy = gets.chomp.split(' ').map!{ |o| o.to_i }
oranges = gets.chomp.split(' ').map!{ |o| o.to_i }

min_c= candy.min
min_o= oranges.min

#min= [min_c,min_o].max
c=0
i=0
while i!= num-1
if(candy[i] !=min_c && oranges[i] != min_o)

vc,vo=candy[i]-min_c,oranges[i]-min_o

min_v=[vc,vo].min
c+=min_v
candy[i]-=min_v
oranges[i]-=min_v
end

i+=1
end
i=0
while i!= num-1
if(candy[i] !=min_c)
vc=candy[i]-min_c
c+=vc
end
if(oranges[i] !=min_o)
vo=oranges[i]-min_o
c+=vo
end
i+=1
end
puts c
t-=1
end

t=gets.chomp.to_i

while t!=0
num= gets.chomp.to_i
candy = gets.chomp.split(' ').map!{ |o| o.to_i }
oranges = gets.chomp.split(' ').map!{ |o| o.to_i }

min_c= candy.min
min_o= oranges.min

#min= [min_c,min_o].max
c=0
i=0
while i!= num-1
if(candy[i] !=min_c && oranges[i] != min_o)

vc,vo=candy[i]-min_c,oranges[i]-min_o

min_v=[vc,vo].min
c+=1
candy[i]-=min_v
oranges[i]-=min_v
end

i+=1
end
i=0
while i!= num-1
if(candy[i] !=min_c)
vc=candy[i]-min_c
c+=vc
end
if(oranges[i] !=min_o)
vo=oranges[i]-min_o
c+=vo
end
i+=1
end
puts c
t-=1
end

def read
    gets.split.map &:to_i
end
gets.to_i.times do
    n = gets.to_i
    a, b = read, read
    res, ma, mb = 0, a.min, b.min
    n.times do |i|
        res += [a[i] - ma, b[i] - mb].min
    end
    puts res
end


n = gets.chop.to_i
ar = gets.chop.split(' ')

pr = []

ok = true

i = 0
while i < n
    line = gets.chop
    if (line.scan(/a|e|i|o|u|y/).size != ar[i].to_i )
        ok = false
    end
    i += 1
end

if ok
    puts 'YES'
else
    puts 'NO'
end

#! /usr/bin/env ruby

n = gets.to_i
sylcnt = gets.split.map{|v| v.to_i}
good = true

n.times {|i|
  good = false if gets.count('aeiouy') != sylcnt[i]
}

puts( good ? 'YES' : 'NO' )
#p n, sylcnt

def getcount(line)
  res = 0
  ['a', 'e', 'i', 'o', 'u', 'y'].each do |c|
    res += line.count(c)
  end
  res
end

n = gets.to_i
patters = gets.strip.split.map(&:to_i)
lines = []
n.times do
  lines << gets.strip
end

result = true
n.times do |i|
  result = result && (patters[i] == getcount(lines[i]))
end
puts (result ? "YES" : "NO")

n = gets.strip.to_i
p = gets.strip.split.map(&:to_i)
lines = Array.new n
count_vowels = Array.new n, 0
vowels = ['a', 'e', 'i', 'o', 'u', 'y']
n.times do |i|
    lines[i] = gets.strip.split(' ')
    lines[i].each do |word|
        count_vowels[i] += word.each_char.count { |c| vowels.include? c }
    end
end
puts count_vowels == p ? "YES" : "NO"

n=gets.to_i
p=gets.split.map &:to_i
n.times{|i|
    if gets.scan(/[aeiouy]/).size!=p[i]
        puts "NO"
        exit
    end
}
puts "YES"

n = gets.chomp.to_i
ps = gets.chomp.split.map(&:to_i)
qs = []
n.times do
  s = gets.chomp
  qs << 'aeiouy'.split('').map { |c| s.count(c)}.inject(:+)
end

puts ps == qs ? "YES" : "NO"

n = gets.to_i
a = gets.split.map(&:to_i)
b = true
n.times do |i|
    s = gets
    b = false if a[i] != s.scan(/[aeiouy]/).count
end

puts b ? "YES" : "NO"

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

ans = 'YES'

n.times do |i|
    partStringNum = 0

    gets.chomp.each_char do |c|
        partStringNum += 1 if c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'
    end

    ans = 'NO' if partStringNum != p[i]
end

puts ans

n=gets.to_i
s=gets.split(" ").map(&:to_i)
list=%w[a e i o u y]
if ((0...n).map do |i|
  w=gets.strip
  w.chars.select{|c| list.include? c }.size == s[i]
end).all?
  puts "YES"
else
  puts "NO"
end

_,a,*l=$<.to_a
a=a.split.map(&:to_i)
puts l.zip(a).all?{|x,y|x.scan(/[aeiouy]/).size==y} ? :YES : :NO

n = gets.to_i
p = gets.strip.split.map(&:to_i)
cnt = []
n.times do
  str = gets.strip
  cnt.push str.split(//).select{|x| %w[a e i o u y].include? x}.size
end
if p == cnt
  puts "YES"
else
  puts "NO"
end

n = gets.to_i
p = gets.strip.split.map(&:to_i)
cnt = []
n.times do
  str = gets.strip
  cnt.push str.split(//).select{|x| %w[a e i o u].include? x}.size
end
if p == cnt
  puts "YES"
else
  puts "NO"
end

n=gets.to_i
p=gets.split.map &:to_i
n.times{|i|
    if gets.scan(/[aeiouy]/).size<p[i]
        puts "NO"
        exit
    end
}
puts "YES"

n = gets.to_i
a = gets.split.map(&:to_i)
b = true
n.times do |i|
    s = gets
    b = false if a[i] > s.scan(/[aeiouy]/).count
end

puts b ? "YES" : "NO"

n = gets.to_i
a = gets.split.map(&:to_i)
b = true
n.times do |i|
    s = gets
    b = false if a[i] != s.scan(/[aeiou]/).count
end

puts b ? "YES" : "NO"

n = gets.to_i
a = gets.split.map(&:to_i)
b = true
n.times do |i|
    s = gets
    b = false if a[i] > s.scan(/[aeiou]/).count
end

puts b ? "YES" : "NO"

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

ans = 'YES'

n.times do |i|
    partStringNum = 0

    gets.chomp.each_char do |c|
        partStringNum += 1 if c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y'
    end

    ans = 'NO' if partStringNum < p[i]
end

puts ans


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

a = ""
b = ""
n+=20
while n>0
  a << '4'
  b << '5'
  n-=4
end
a[-1]='5'

puts a
puts b

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

def max(a,b)
  a > b ? a : b
end

def min(a,b)
  a < b ? a : b
end

a = '4'*(n / 4)
a+= '4' if n % 4 > 0
q = min(m,a.length+1)
x = '1'*m + '0'*max(0, a.length+1-m)
puts a
puts x.to_i - a.to_i


def lowbit str
	for k in 0...str.size
		return k if str[k] == '1'
	end
end

T = gets.to_i
T.times do
	x = gets.chomp.reverse
	y = gets.chomp.reverse

	l = lowbit y
	ans = lowbit x[l..-1]
	puts ans
end

def lowbit n
	n & -n
end

T = gets.to_i
T.times do
	x = gets.to_i
	y = gets.to_i
	ans = []
	cnt = 0
	until lowbit(y) > x
		tmp = x + y
		ans << [tmp.to_s(2).reverse, cnt]
		cnt += 1
		y *= 2
	end
	ans.sort!
	puts ans[0][1]
end


a=gets.split.map(&:to_i)
s=gets.chomp.bytes.map{|i|i-97}
ans=t=0
cnt=Hash.new{0}
s.each{|i|
  ans+=cnt[[i,t]]
  t+=a[i]
  cnt[[i,t]]+=1
}
p ans

ratings = gets.chomp.split(' ').map {|x| x.to_i}
string = gets.chomp

string_values = string.chars.map {|c| ratings[c.ord - 'a'.ord]}
running_sum = string_values.inject([]){ |res, c| res << res.last.to_i + c }

char_positions = Array.new(26)

string.chars.each_with_index { |c, i|
  if char_positions[c.ord - 'a'.ord].nil?
    char_positions[c.ord - 'a'.ord] = []
  end
  char_positions[c.ord - 'a'.ord] << i
}
ans = 0

char_positions.each { |pos|
  if pos.nil?
    next
  end

  temp = {}

  pos.each { |position|
    if temp[running_sum[position - 1]].nil?
      temp[running_sum[position - 1]] = 0
    end

    if temp[running_sum[position]].nil?
      temp[running_sum[position]] = 0
    end
    ans += temp[running_sum[position - 1]]

    temp[running_sum[position]] += 1
  }
}

p ans

@ratings = gets.chomp.split(' ').map {|x| x.to_i}
@string = gets.chomp

@sum_table = {}

def calc_sum(start, len)
  key = start.to_s + '_' + len.to_s
  if @sum_table.has_key? key
    @sum_table[key]
  elsif (len > 1)
    @sum_table[key] = calc_sum(start, len - 1) + calc_sum(start + len-1, 1)
  else
    @sum_table[key] = @ratings[@string[start].ord - 'a'.ord]
  end
end

string_values = @string.chars.map {|c| @ratings[c.ord - 'a'.ord]}

count = 0
@string.chars.each_with_index do |e, i|
  for j in (i+1)..@string.length
    if @string[j] == e
      if calc_sum(i+1, j-i-1) == 0
        count += 1
      end
    end
  end
end

puts count


n, b, d = gets.split.map(&:to_i)
a       = gets.split.map(&:to_i).reject { |e| e > b }
f, c    = 0, 0

a.each do |e|
  f += e
  if f > d
    f = 0
    c += 1
  end
end

puts c

n, b, d = gets.strip.split.map(&:to_i)
a = gets.strip.split.map(&:to_i)
total_size = ans = 0
n.times do |i|
    next if a[i] > b
    total_size += a[i]
    if total_size > d
        ans += 1
        total_size = 0
    end
end
puts ans

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

sum=0
ans=0
x.each{|e|
	if e<=b then
		sum+=e
		if sum>d then
			ans+=1
			sum=0
		end
	end
}
puts ans

input = gets.strip.split(' ').map(&:to_i)
n = input[0]
b = input[1]
d = input[2]
oranges = gets.strip.split(' ').map(&:to_i)
juicer = 0
counter = 0
oranges.each do |o|
  if o > b
    next
  else
    juicer += o
    if juicer > d
      juicer = 0
      counter += 1
    end
  end
end
puts counter

# coding: utf-8

n, b, d = gets.split.map(&:to_i)
ar = gets.split.map(&:to_i)
fs = 0
empties = 0
for i in ar
    if i <= b
        fs += i
    end

    if fs > d
        empties += 1
        fs = 0
    end
end
puts empties

#!/usr/bin/ruby
n,b,d,*a=$<.read.split.map(&:to_i)
r=k=0
a.each{|e|
	if e<=b
		if d<k+=e
			r+=1;k=0
		end
	end
}
p r

#!/usr/bin/ruby
n,b,d,*a=$<.read.split.map(&:to_i)
r=k=0
a.each{|e|
	if e<=b
		(d<k+=e)&&(r+=1;k=0)
	end
}
p r

n, b, d = gets.split.map(&:to_i)
x = 0
ans = 0
gets.split.map(&:to_i).each{|a|
    if a <= b
        x += a
        if x > d
            x = 0
            ans += 1
        end
    end
    }
p ans

#!/usr/bin/env ruby

def juicer(arr, max_orange_size, wastebin_size)
	initial = [0,0] #tuple of wastebin and bin emptying
	res = arr.inject(initial) do |cntr, orange|
		cntr[0] += orange unless orange > max_orange_size
		if cntr[0] > wastebin_size
			cntr[1] += 1
			cntr[0] = 0
		end
		cntr
	end
	res[1]
end

params = STDIN.readline.split(" ").map(&:to_i)
arr = STDIN.readline.split(" ").map(&:to_i)

puts juicer(arr, params[1], params[2])

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

temp = 0
ans = 0
a.each do |x|
   temp += x if x <= b
   if temp > d
       ans += 1
       temp = 0
   end
end

puts ans

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

c = 0
sum = 0
arr.each do |a|
  next if a > b
  if sum + a > d
    c += 1
    sum = 0
  else
    sum += a
  end
end
puts c

n,b,d = gets.split(" ").map(&:to_i)
oranges = gets.split(" ").map(&:to_i)
crushed_oranges = 0
clean_up = 0
oranges.each do |orange|
    if orange <= b
        crushed_oranges += orange
        if crushed_oranges > d
            clean_up +=1
            crushed_oranges = 0
        end
    end
end
if crushed_oranges > d
    clean_up +=1
end
puts clean_up

n, b, d = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)
a.delete_if { |e| e > b }
s = a.reduce(0, :+)
puts s % d == 0 ? s / d - 1 : s / d

n, b, d = gets.split.map(&:to_i)
a       = gets.split.map(&:to_i).reject { |e| e > b }

s = a.reduce(0, :+)
r = s / d
r -= 1 if s % d == 0 && a.any?

puts r

n, b, d = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)
a.delete_if { |e| e > b }
puts a.reduce(0, :+) / d

n, b, d = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)
a.delete_if { |e| e > b }
s = a.reduce(0, :+)
puts s % d == 0 && s > 0 ? s / d - 1 : s / d

# coding: utf-8

n, b, d = gets.split.map(&:to_i)
ar = gets.split.map(&:to_i)
empties = 0
filtered_sum = 0
for i in ar
    if i <= b
        filtered_sum += i
    end
end

if filtered_sum > 0 && filtered_sum%d == 0
    # last dumping will not be required
    # since there's no overflow at the end.
    puts filtered_sum/d - 1
else
    puts filtered_sum/d
end

# coding: utf-8

n, b, d = gets.split.map(&:to_i)
ar = gets.split.map(&:to_i)
filtered_sum = 0
for i in ar
    if i <= b
        filtered_sum += i
    end
end
if filtered_sum <= d
    puts 0
else
    if filtered_sum%d == 0
        puts filtered_sum/d - 1
    else
        puts filtered_sum
    end
end

# coding: utf-8

n, b, d = gets.split.map(&:to_i)
ar = gets.split.map(&:to_i)
filtered_sum = 0
for i in ar
    if i <= b
        filtered_sum += i
    end
end
if filtered_sum <= d
    puts 0
else
    if filtered_sum%d == 0
        puts filtered_sum/d - 1
    else
        puts filtered_sum/d
    end
end

# coding: utf-8

n, b, d = gets.split.map(&:to_i)
ar = gets.split.map(&:to_i)
empties = 0
nb, nd = 0, 0 # current status
while !ar.empty?
    nb = 0
    while !ar.empty?
        i = ar.first

        if i <= b
            if i + nb <= b
                nb += ar.shift
            else
                break
            end
        else
            ar.shift # waste
        end # other case, it doesn't fit to the juicer and will be skipped
    end

    #p "#{nb} #{ar}"
    nd += nb

    if nd > d
        empties += nd/d
        nd = nd%d
    end
end
puts empties

# coding: utf-8

n, b, d = gets.split.map(&:to_i)
ar = gets.split.map(&:to_i)
empties = 0
nb, nd = 0, 0 # current status
while !ar.empty?
    nb = 0
    while !ar.empty?
        i = ar.first

        if i <= b
            if i + nb <= b
                nb += ar.shift
            else
                break
            end
        else
            ar.shift # waste
        end # other case, it doesn't fit to the juicer and will be skipped
    end

    #p "#{nb} #{ar}"
    nd += nb

    if nd > d
        nd = 0
        empties += 1
    end
end
puts empties

n, b, d = gets.split.map(&:to_i)
x = 0
ans = 0
gets.split.map(&:to_i).each{|a|
    if a > b
        ans += 1
    else
        x += a
        if x > d
            x = 0
            ans += 1
        end
    end
    }
p ans

#!/usr/bin/env ruby

def juicer(arr, max_orange_size, wastebin_size)
	initial = [0,0] #tuple of wastebin and bin emptying
	res = arr.inject(initial) do |cntr, orange|
		cntr[0] += orange unless orange >= max_orange_size
		if cntr[0] > wastebin_size
			cntr[1] += 1
			cntr[0] = 0
		end
		cntr
	end
	res[1]
end

params = STDIN.readline.split(" ").map(&:to_i)
arr = STDIN.readline.split(" ").map(&:to_i)

puts juicer(arr, params[1], params[2])

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

temp = 0

a.each do |x|
   temp += x if x <= b
end

puts temp==d ? 0 : temp/d

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

c = 0
sum = 0
arr.each do |a|
  if a < b && sum + a <= d
    c += 1
    sum += a
  end
end
puts c

n,b,d = gets.split(" ").map(&:to_i)
oranges = gets.split(" ").map(&:to_i)
crushed_oranges = 0
clean_up = 0
oranges.each do |orange|
    if orange <= b
        crushed_oranges += orange
        if crushed_oranges >= d
            clean_up +=1
            crushed_oranges = 0
        end
    end
end
if crushed_oranges >= d
    clean_up +=1
end
puts clean_up


gets.to_i.times do
  n = gets.to_i
  xys = n.times.map { gets.split.map(&:to_i) }
  xs = xys.map { |x, y| x }
  ys = xys.map { |x, y| y }
  p 2 * ([xs.filter { |x| x < 0 }.min&.abs,
          xs.filter { |x| x > 0 }.max,
          ys.filter { |y| y < 0 }.min&.abs,
          ys.filter { |y| y > 0 }.max].compact.sum)
end

gets.to_i.times do
  xp,yp=[0],[0]
  (n=gets.to_i).times do
    xy=gets.split.map(&:to_i)
    xy[0]==0 ? yp << xy[1] : xp << xy[0]
  end
  xp.sort!
  yp.sort!
  puts 2*(xp[-1]-xp[0])+2*(yp[-1]-yp[0])
end


n, p = gets.split.map {|v| v.to_i}

route = Array.new
p.times do
	f, t, d = gets.split.map {|v| v.to_i}

	temp = route.find {|v| v[:to]==f && v[:from]==t}
	if temp then
		route.delete temp
		next
	end

	ff = route.find {|v| v[:to]==f}
	tt = route.find {|v| v[:from]==t}
	if ff && tt then
		ff[:to] = tt[:to]
		ff[:dia] = d if d<ff[:dia]
		ff[:dia] = tt[:dia] if tt[:dia]<ff[:dia]
		route.delete tt
	elsif ff then
		ff[:to] = t
		ff[:dia] = d if d<ff[:dia]
	elsif tt then
		tt[:from] = f
		tt[:dia] = d if d<tt[:dia]
	else
		route << {:from => f, :to => t, :dia => d}
	end

end

route = route.sort_by {|v| v[:from]}

puts route.size
route.each do |v|
	print v[:from]," ",v[:to]," ",v[:dia],"\n"
end

arg = STDIN.gets.split(" ").map {|i| i.to_i}

depart = []
dest   = []
meter  = []
arg[1].times do
  pipe = STDIN.gets.split(" ").map {|i| i.to_i}
  depart << pipe[0]
  dest   << pipe[1]
  meter  << pipe[2]
end

tank = []
(1..arg[0]).each do |i|
  tank << i if (not dest.index(i)) and depart.index(i)
end

tap  = (1..tank.length).map {|i| 0}
if tank == []
  puts 0
else
  puts tank.length
  (0..tank.length-1).each do |i|
    capa = 1000_001
    #dp = tank[i]
    idx = depart.index(tank[i])
    ds = dest[idx]
    capa = [capa,meter[idx]].min
    while idx = depart.index(ds)
      capa = [capa,meter[idx]].min
      ds = dest[idx]
    end
    puts "#{tank[i]} #{ds} #{capa}"
  end
end

#sharyo
inf=2*(10**9)
res=Array.new
in1,out,f=Array.new(1001,-1),Array.new(1001,-1),Array.new(1001,-1)
s=gets.split(" ")
n,m=s[0].to_i,s[1].to_i
for i in 0..m-1
	s=gets.split(" ")
	u,v,d=s[0].to_i,s[1].to_i,s[2].to_i
	f[u]=d
	in1[v]=out[u]=v
end
for i in 1..n
	next unless in1[i]==-1
	u,w,cnt,c=i,inf,0,false
	while out[u]!=-1
         cnt+=1
         if cnt>n-1
         	c=1
         	break
         end
         v=out[u]
         w=[w,f[u]].min
         u=v
	end
	next unless !c&&w!=inf
	res.push([i,[v,w]])
end
puts res.size
res.each { |x,y|
	puts (x.to_s+" "+y[0].to_s+" "+y[1].to_s)
  }

#!/usr/bin/ruby

n, p = gets.split.map(&:to_i)
v = Array.new(n) { [nil, nil, nil] }
p.times do
	a, b, d = gets.split.map(&:to_i)
	a -= 1
	b -= 1
	v[a][1..2] = [b, d]
	v[b][0] = a
end

ans = []
v.each_with_index do |item, idx|
	if item[0].nil?
		cur = idx
		d = 10000000
		while v[cur][1]
			d = [d, v[cur][2]].min
			cur = v[cur][1]
		end
		ans << [idx+1, cur+1, d] if idx != cur
	end
end

p ans.size
ans.each do |item|
	puts item.join(' ')
end

n, p = gets.split.map {|v| v.to_i}

route = Array.new
p.times do
	f, t, d = gets.split.map {|v| v.to_i}

	ff = route.find {|v| v[:to]==f}
	tt = route.find {|v| v[:from]==t}
	if ff then
		ff[:to] = t
		ff[:dia] = d if d<ff[:dia]
	elsif tt then
		tt[:from] = f
		tt[:dia] = d if d<tt[:dia]
	else
		route << {:from => f, :to => t, :dia => d}
	end

end

route.reject! {|v| v[:to]==v[:from]}
route.sort_by {|v| v[:dia]}

puts route.size
route.each do |v|
	print v[:from]," ",v[:to]," ",v[:dia],"\n"
end

n, p = gets.split.map {|v| v.to_i}

route = Array.new
p.times do
	f, t, d = gets.split.map {|v| v.to_i}

	temp = route.find {|v| v[:to]==f && v[:from]==t}
	if temp then
		route.delete temp
		next
	end

	ff = route.find {|v| v[:to]==f}
	tt = route.find {|v| v[:from]==t}
	if ff && tt then
		ff[:to] = tt[:to]
		ff[:dia] = d if d<ff[:dia]
		ff[:dia] = tt[:dia] if tt[:dia]<ff[:dia]
		route.delete tt
	elsif ff then
		ff[:to] = t
		ff[:dia] = d if d<ff[:dia]
	elsif tt then
		tt[:from] = f
		tt[:dia] = d if d<tt[:dia]
	else
		route << {:from => f, :to => t, :dia => d}
	end

end

route.sort_by {|v| v[:dia]}

puts route.size
route.each do |v|
	print v[:from]," ",v[:to]," ",v[:dia],"\n"
end

n, p = gets.split.map {|v| v.to_i}

route = Array.new
p.times do
	f, t, d = gets.split.map {|v| v.to_i}

	temp = route.find {|v| v[:to]==f && v[:from]==t}
	if temp then
		route.delete temp
		next
	end

	ff = route.find {|v| v[:to]==f}
	tt = route.find {|v| v[:from]==t}
	if ff && tt then
		ff[:to] = tt[:to]
		ff[:dia] = d if d<ff[:dia]
		ff[:dia] = tt[:dia] if tt[:dia]<ff[:dia]
		route.delete tt
	elsif ff then
		ff[:to] = t
		ff[:dia] = d if d<ff[:dia]
	elsif tt then
		tt[:from] = f
		tt[:dia] = d if d<tt[:dia]
	else
		route << {:from => f, :to => t, :dia => d}
	end

end

route.sort_by {|v| v[:from]}

puts route.size
route.each do |v|
	print v[:from]," ",v[:to]," ",v[:dia],"\n"
end

#!/usr/bin/ruby

n, p = gets.split.map(&:to_i)
v = Array.new(n) { [nil, nil, nil] }
p.times do
	a, b, d = gets.split.map(&:to_i)
	a -= 1
	b -= 1
	v[a][1..2] = [b, d]
	v[b][0] = a
end

ans = []
v.each_with_index do |item, idx|
	if item[0].nil?
		cur = idx
		d = 10000000
		while v[cur][1]
			d = [d, v[cur][2]].min
			cur = v[cur][1]
		end
		ans << [idx+1, cur+1, d]
	end
end

p ans.size
ans.each do |item|
	puts item.join(' ')
end


t = gets.chomp.to_i
(0...t).each {|_| m,n = gets.chomp.split.map(&:to_i); puts (m%n == 0) ? "YES" : "NO";}

1.upto(gets.to_i) do
  a, b = gets.split(' ').map(&:to_i)

  puts a.modulo(b).zero? ? 'YES' : 'NO'
end

T = gets.to_i

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

  if n % m == 0
    puts 'YES'
  else
    puts 'NO'
  end
end

 gets.chomp.to_i.times do
     n, m = gets.chomp.split.map(&:to_i)
     puts n%m == 0 ? "YES" : "NO"
 end


q = gets.to_i

q.times do
  n, m, k = gets.split.map(&:to_i)

  if n < m
    n, m = m, n
  end

  if n > k
    puts -1
  else
    ans = m + (n - m) - (n - m) % 2
    k -= n
    if k % 2 != 0
      if (n - m) % 2 == 0
	ans -= 1
        k -= 1
      end
    end
    puts ans + k
  end
end

nq = gets.to_i

nq.times do
	a, b, k = gets.split.map &:to_i
	if [a,b].max > k
		puts -1
	elsif (a+b)%2 == 1
		puts k-1
	elsif a%2 == k%2
		puts k
	else
		puts k-2
	end
end

Q = gets.to_i
Q.times do
    n, m, k = gets.split.map(&:to_i)
    if n > k || m > k
        puts -1
    else
        ans = k
        ans -= 1 if (n-k) % 2 == 1
        ans -= 1 if (m-k) % 2 == 1
        puts ans
    end
end

q = gets.strip.to_i
q.times do
  x,y,k = gets.strip.split.map(&:to_i)
  if k<x || k<y
    puts -1
    next
  end
  x,y = [y,x] if y > x
  # cx,cy=[y,y]
  ans=y
  k-=y
  x-=y

  if x%2==0
    ans+=x
    k-=x
    x=0
    if k%2==0
      ans+=k
    else
      ans+=(k-2)
    end
  else
    ans+=(x-1)
    k-=(x-1)
    x=1
    ans+=(k-1)
  end
  puts ans
end