#!/usr/bin/env ruby

n = gets.split.collect{|i| i.to_i}.min

puts n + 1

0.upto(n) { |i| puts "#{i} #{n-i}" }

a=gets.split.map &:to_i
(p a.min+1).times{|i|puts [a[0]-i,i]*' '}

t = gets.split.collect{|x| x.to_i}
n,m = t[0],t[1]

min = t.min

puts min+1

(min+1).times do |i|
	print i,' ', min-i, "\n"
end

n,m=gets.split.map &:to_i
(p [n,m].min+1).times{|i|puts [n-i,i]*' '}

def run
  n, m = ARGF.readline.split.map(&:to_i)
  puts num = [n, m].min + 1
  num.times do |i|
    puts [n - i, i].join(' ')
  end
end

run if $0 == __FILE__

n, m = gets.split(' ').map &:to_i
q = [n,m].min
puts q + 1
(q+1).times do |time|
  puts [time, q - time].join(' ')
end

n,m=gets.split.map(&:to_i)
k=[n,m].min+1
puts k
i=0
k.times do
    puts "#{k-i-1} #{i}"
    i+=1
end

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

if n>m
  n = m
end
puts n+1
(0..n).each do |k|
  puts "#{k} #{n-k}"
end

n, m = gets.split(' ')
n = n.to_i
m = m.to_i

if n < m
	min = n
else
	min = m
end

beaty = []

osx = min
osy = 0

(min+1).times do |x|
	beaty << [osx, osy]
	osx -= 1
	osy += 1
	osx = n if osx < 0
	osy = 0 if osy > m
end

puts beaty.length

beaty.each do |e|
	puts e.join(' ')
end

n,m = gets.split(" ").map(&:to_i)
min = [n,m].min + 1
puts min
(0...min).each do |i|
	puts "#{i} #{min - i - 1}"
end

n,m = gets.chomp.split(" ").collect! {|x| x.to_i}
if n>m
	n = m
end

puts n+1
(0..n).each{|k|
	puts "#{k} #{n-k}"
}

n, m = gets.split.collect{|i| i.to_i}
ans = [n, m].min+1
puts ans
(0...ans).each do |i|
    print i, " ", ans-1-i, "\n"
end

n, m = gets.split.map { |x| x.to_i }
puts [n, m].min + 1
m.downto([0, m - n].max).each { |y| puts "#{m - y} #{y}" }

n,m=gets.split(&:to_i)
k=[n,m].min.to_i+1
puts k
i=0
k.times do
    puts "#{i} #{i}"
    i+=1
end

n,m=gets.split.map(&:to_i)
n+=1
m+=1
if n<m
    puts n
    for i in 1..n
        puts "#{i-1} #{i}"
    end
else
    puts m
    for i in 1..m
        puts "#{i%m} #{(i-1)%n}"
    end
end

n,m=gets.split(&:to_i)
k=[n,m].min.to_i+1
puts k
i=0
k.times do
    puts "#{k-i-1} #{i}"
    i+=1
end

n,m=gets.split(&:to_i)
k=[n,m].min.to_i
puts k+1
i=0
k.times do
    puts "#{i} #{i+1}"
    i+=1
end
puts "#{k} 0"

n, m = gets.split(' ')
n = n.to_i
m = m.to_i

if n < m
	min = n
else
	min = m
end

beaty = []

osx = 0
osy = 1

(min+1).times do |x|
	beaty << [osx, osy]
	osx += 1
	osy += 1
	osx = 0 if osx > n
	osy = 0 if osy > m
end

puts beaty.length

beaty.each do |e|
	puts e.join(' ')
end

n,m = gets.split(" ").map(&:to_i)
min = [n,m].min + 1
puts min
(0...min).each do |i|
	puts "#{i} #{min - i}"
end

#!/usr/bin/env ruby

n = gets.split.collect{|i| i.to_i}.min

puts n + 1

puts "0 1"
puts "1 0"

2.upto(n) { |i| puts "#{i} #{i}" }


s, p = gets.chomp.unpack("C*"), gets.chomp.unpack("C*")
n, m = s.length, p.length

cnt = Array.new(256,0)
a = "abcdefghijklmnopqrstuvwxyz?".unpack("C*")

if n < m
 p 0
 exit
end

for i in 0...m
 cnt[s[i]] += 1
 cnt[p[i]] -= 1
end

ans = 0
for i in m..n
 tmp = cnt[a[26]]
 for j in 0..25
  tmp -= cnt[a[j]].abs
 end
 ans += 1 if tmp >= 0
 break if i == n
 cnt[s[i]] += 1
 cnt[s[i-m]] -= 1
end
p ans

a=gets.split[0].bytes.to_a
b=gets.split[0].bytes.to_a
cntb=Array.new(256,0)
if a.length<b.length then
        puts 0
        exit
end
ans=0
cnta=Array.new(256,0)
0.upto(b.length-1){|i|
        cnta[a[i]]+=1
        cntb[b[i]]+=1
}
ok=true
for i in 97..122
        if cnta[i]>cntb[i] then
                ok=false
                break
        end
end
ans+=1 if ok
for i in 1..a.length-b.length
        cnta[a[i-1]]-=1
        cnta[a[i+b.length-1]]+=1
        ok=true
        for i in 97..122
                if cnta[i]>cntb[i] then
                        ok=false
                        break
                end
        end
        ans+=1 if ok
end
p ans


n, m = gets.split.map &:to_i
r = false
if n > m
  n, m = m, n
  r = true
end

ans = []
if n == 0
  ans << [0, 1] << [0, m] << [0, 0] << [0, m - 1]
elsif Math.hypot(n, m) * 2 + m > Math.hypot(n, m) + Math.hypot(m, n - 1) * 2
  ans << [0, 0] << [n, m] << [n, 0] << [0, m]
else
  ans << [1, 0] << [n, m] << [0, 0] << [n - 1, m]
end

ans.each{|i|
  if !r
    puts i * ' '
  else
    puts i.reverse * ' '
  end
}

def dist(a, b)
  dx = a[0]-b[0]
  dy = a[1]-b[1]
  Math.sqrt(dx*dx+dy*dy)
end

def len(arr)
  dist(arr[0],arr[1]) + dist(arr[1],arr[2]) + dist(arr[2],arr[3])
end

n, m = gets.strip.split(" ").map{|x| x.to_i}

if n == 0
  puts "0 1"
  puts "0 #{m}"
  puts "0 0"
  puts "0 #{m-1}"
  exit
end
if m == 0
  puts "1 0"
  puts "#{n} 0"
  puts "0 0"
  puts "#{n-1} 0"
  exit
end

candidates = []

candidates.push [
  [n, m-1],
  [0, 0],
  [n, m],
  [0, 1]
]
candidates.push [
  [n-1, m],
  [0, 0],
  [n, m],
  [1, 0]
]
candidates.push [
  [0, 0],
  [n, m],
  [n, 0],
  [0, m]
]
candidates.push [
  [0, 0],
  [n, m],
  [0, m],
  [n, 0]
]

candidates.sort!{|a, b| -(len(a)<=>len(b))}

puts candidates.first.map{|x| x.join(" ")}

n,m=gets.split.map{|i| i.to_i}
n,m=m,n if n>m
puts "0 1"
puts "#{n} #{m}"
puts "0 0"
puts "#{n} #{m-1}"

n,m=gets.split.map{|i| i.to_i}
n,m=m,n if n>m
puts "0 0"
puts "#{n} #{m}"
puts "0 1"
puts "#{n} #{m-1}"

n,m=gets.split.map{|i| i.to_i}
r=false
if n>m
	n,m=m,n
	r=true
end
if n==m
	puts "#{n} #{m}\n0 0\n#{n} 0\n0 #{m}\n"
	exit
end
a=[]
if n==0
	a<<[0,1]<<[0,m]<<[0,0]<<[0,m-1]
else
	a<<[1,0]<<[n,m]<<[0,0]<<[n-1,m]
end
a.each{|i|
	if !r
		puts i*' '
	else
		puts i.reverse*' '
	end}

n,m=gets.split.map{|i| i.to_i}
n,m=m,n if n>m
if n+m==2
	puts "1 1\n0 0\n1 0\n0 1\n"
	exit
end

puts "0 1"
puts "#{n} #{m}"
puts "0 0"
puts "#{n} #{m-1}"

n,m=gets.split.map{|i| i.to_i}
n,m=m,n if n>m
if n+m==2
	puts "0 1\n1 1\n0 0\n1 0\n"
	exit
end

puts "0 1"
puts "#{n} #{m}"
puts "0 0"
puts "#{n} #{m-1}"

n,m=gets.split.map{|i| i.to_i}
r=false
if n>m
	n,m=m,n
	r=true
end
if n==m&&n<4
	puts "#{n} #{m}\n0 0\n#{n} 0\n0 #{m}\n"
	exit
end
a=[]
if n==0
	a<<[0,1]<<[0,m]<<[0,0]<<[0,m-1]
else
	a<<[1,0]<<[n,m]<<[0,0]<<[n-1,m]
end
a.each{|i|
	if !r
		puts i*' '
	else
		puts i.reverse*' '
	end}

n,m=gets.split.map{|i| i.to_i}
r=false
if n>m
	n,m=m,n
	r=true
end
if n+m==2
	puts "1 1\n0 0\n1 0\n0 1\n"
	exit
end
a=[]
if n==0
	a<<[0,1]<<[0,m]<<[0,0]<<[0,m-1]
else
	a<<[1,0]<<[n,m]<<[0,0]<<[n-1,m]
end
a.each{|i|
	if !r
		puts i*' '
	else
		puts i.reverse*' '
	end}

n,m=gets.split.map{|i| i.to_i}
r=false
if n>m
	n,m=m,n
	r=true
end
if n+m==2
	puts "1 1\n0 0\n1 0\n0 1\n"
	exit
end
a=[]
puts r
if n==0
	a<<[0,1]<<[0,m]<<[0,0]<<[0,m-1]
else
	a<<[1,0]<<[n,m]<<[0,0]<<[n-1,m]
end
a.each{|i|
	if !r
		puts i*' '
	else
		puts i.reverse*' '
	end}

n,m=gets.split.map{|i| i.to_i}
r=false
if n>m
	n,m=m,n
	r=true
end
if n+m==2
	puts "1 1\n0 0\n1 0\n0 1\n"
	exit
end
a=[]
if n==0
	a<<[0,1]<<[0,m]<<[0,0]<<[0,m-1]
else
	a<<[1,0]<<[n,m]<<[0,0]<<[n-1,m]
end
a.each{|i|
	if r
		puts i*' '
	else
		puts i.reverse*' '
	end}


f = STDIN.readline.split.map { |x| x.to_i }
p = Array.new(2) { [] }
0.upto(1) do |i|
	a = f[i]-1
	b = 0
	a.downto(1) do |a|
		b += 1 while (b+1)**2 + a**2 <= f[i]**2
		if a**2 + b**2 == f[i]**2 ;
			p[i] << ( [a,b])
		end
	end
end

# print p

p[0].each do |a|
	p[1].each do |b|
		if a[0]*b[1] == a[1]*b[0] && a[1] != b[0] ;
			print "YES\n"
			print "0 0\n"
			print "#{a[0]} #{a[1]}\n"
			print "#{-b[1]} #{b[0]}\n"
			exit
		end
	end
end
print "NO\n"

a,b = gets.split.map(&:to_i)
ans = (1...a).map { |dx|
    dy = Math.sqrt(a * a - dx * dx).to_i
    next if dx * dx + dy * dy != a * a
    dx2 = dy * b / a;
    dy2 = dx * b / a;
    next if dx2 * dx2 + dy2 * dy2 != b * b || dy == dy2

    [dx, dy, -dx2, dy2]
}.select { |d|
    d != nil
}.first

unless ans
    puts "NO"
else
    puts "YES"
    puts "0 0"
    puts ans[0..1].join(" ")
    puts ans[2..3].join(" ")
end

x, y = gets.split.map { |x| Integer x }
p1 = 1.0
p2 = 1000.0
for i in 1..2000
  if p1 ** 2 + p2 ** 2 > x ** 2
    p2 -= 1
  elsif p1 ** 2 + p2 ** 2 < x ** 2
    p1 += 1
  else
    arc = Math.acos(p1 / x)
    arc2 = Math::PI / 2 - arc
    p3 = y * Math.cos(arc2)
    p4 = Math.sqrt (y ** 2 - p3.round ** 2)
    if (p3.round - p3).abs <= 10 ** -9 && (p4 - p4.round).abs <= 10 ** -9
      if [p1, p3, p2, p4].index(0) != nil
        puts 'NO'
        exit
      end
      if p2.round == p4.round
        puts 'YES'
        puts (-p2.to_i).to_s + ' ' + p1.to_i.to_s
        puts '0 0'
        puts p4.round.to_s + ' ' + p3.round.to_s
        exit
      end
      puts 'YES'
      puts (-p1.to_i).to_s + ' ' + (p2.to_i).to_s
      puts '0 0'
      puts p3.round.to_s + ' ' + p4.round.to_s
      exit
    end
    p1 += 1
    p2 -= 1
  end
end
puts 'NO'

def pita(a)
  ps = []
  x = 1
  while x * x < a * a
    y = Math.sqrt(a * a - x * x).to_i
    break if y < x
    ps << [x, y] if x * x + y * y == a * a
    x += 1
  end
  ps
end

a, b = gets.split.map(&:to_i)
# p pita(a)
# p pita(b)
# exit

def check(p, q)
  px, py = p
  qx, qy = q
  if px * qx + py * qy == 0 && px != qx && py != qy
    puts :YES
    puts "0 0"
    puts "#{px} #{py}"
    puts "#{qx} #{qy}"
    true
  else
    false
  end
end

ok = false

pita(a).each do |px, py|
  pita(b).each do |qx, qy|

    if check([px, py], [-qx, qy])
      ok = true
      break
    end
    if check([px, py], [qx, -qy])
      ok = true
      break
    end
    if check([px, py], [-qy, qx])
      ok = true
      break
    end
    if check([px, py], [qy, -qx])
      ok = true
      break
    end

    break if ok
  end
  break if ok
end

if !ok
  puts :NO
end

a,b = gets.split.map &:to_i
as = a*a
bs = b*b

av = []
1.upto(a-1).each do |x|
  break if as <= x*x
  y = Math.sqrt(as - x*x).round
  #print [x,y]
  if as == x*x + y*y
    av << [x,y]
  end
end

bv = []
1.upto(b-1).each do |x|
  break if bs <= x*x
  y = Math.sqrt(bs - x*x).round
  bv << [x,y] if bs == x*x + y*y
end

#print av
#print bv

av.each do |as|
  bv.each do |bs|
    x1,y1 = *as
    x2,y2 = *bs
    if x1*x2 == y1*y2 && (x1 != -x2) && (y1 != y2)
      puts "YES"
      print "0 0\n#{x1} #{y1}\n-#{x2} #{y2}\n"
      exit
    end
  end
end

puts "NO"

a,b=gets.split.map &:to_i
q1,q2=[],[]
def cal(x)
  q=[]
  (1..x-1).each{|i| (1..x-1).each{ |j| q.push [i,j] if i*i+j*j==x*x}}
  return q
end
q1=cal(a)
q2=cal(b)
q1.each do |i|
  q2.each do |j|
    if j[0]*i[0]-j[1]*i[1]==0&&j[0]!=i[0]
      j[1]=-j[1]
      puts 'YES','0 0',i.join(' '),j.join(' ')
      exit
    end
  end
end
puts 'NO'

a,b=gets.split.map &:to_i
q1,q2=[],[]
(1..a-1).each do |i|
  (1..a-1).each do |j|
    if i*i+j*j==a*a
     q1.push [i,j]
    end
  end
end
(1..b-1).each do |i|
  (-(b-1)..-1).each do |j|
    if i*i+j*j==b*b
      q2.push [i,j]
    end
  end
end
q1.each do |i|
  q2.each do |j|
    if j[0]*i[0]+j[1]*i[1]==0&&j[0]!=i[0]
      puts 'YES'
      puts '0 0'
      puts i.join' '
      puts j.join' '
      exit
    end
  end
end
puts 'NO'

x, y = gets.split.map {|x| Integer x}
p1 = 1.0
p2 = 1000.0
while p2 - p1 > 1
  if p1 ** 2 + p2 ** 2 > x ** 2
    p2 -= 1
  elsif p1 ** 2 + p2 ** 2 < x ** 2
    p1 += 1
  else
    break
  end
end
if p1 ** 2 + p2 ** 2 != x ** 2
  puts 'NO'
  exit
end
arc = Math.acos(p1 / x)
arc2 = Math::PI / 2 - arc
p3 = y * Math.cos(arc2)
if (p3.round - p3).abs > 10 ** -8
  puts 'NO'
  exit
end
p4 = Math.sqrt (y ** 2 - p3.round ** 2)
if (p4 - p4.round).abs > 10 ** -8
  puts 'NO'
  exit
end
if p2.round == p4.round
  puts 'YES'
  puts (-p2.to_i).to_s + ' ' + p1.to_i.to_s
  puts '0 0'
  puts p4.round.to_s + ' ' + p3.round.to_s
  exit
end
puts 'YES'
puts (-p1.to_i).to_s + ' ' + (p2.to_i).to_s
puts '0 0'
puts p3.round.to_s + ' ' + p4.round.to_s

x, y = gets.split.map {|x| Integer x}
p1 = 1.0
p2 = 1000.0
while p2 - p1 > 1
  if p1 ** 2 + p2 ** 2 > x ** 2
    p2 -= 1
  elsif p1 ** 2 + p2 ** 2 < x ** 2
    p1 += 1
  else
    break
  end
end
if p1 ** 2 + p2 ** 2 != x ** 2
  puts 'NO'
  exit
end
arc = Math.acos(p1 / x)
arc2 = Math::PI / 2 - arc
p3 = y * Math.cos(arc2)
if (p3.round - p3).abs > 10 ** -9
  puts 'NO'
  exit
end
p4 = Math.sqrt (y ** 2 - p3.round ** 2)
if (p4 - p4.round).abs > 10 ** 9
  puts 'NO'
  exit
end
if p3.round == p4.round
  puts 'NO'
  exit
end
puts 'YES'
puts (-p1.to_i).to_s + ' ' + (p2.to_i).to_s
puts '0 0'
puts p3.round.to_s + ' ' + p4.round.to_s

x, y = gets.split.map { |x| Integer x }
p1 = 1.0
p2 = 1000.0
while p2 - p1 > 1
  if p1 ** 2 + p2 ** 2 > x ** 2
    p2 -= 1
  elsif p1 ** 2 + p2 ** 2 < x ** 2
    p1 += 1
  else
    arc = Math.acos(p1 / x)
    arc2 = Math::PI / 2 - arc
    p3 = y * Math.cos(arc2)
    p4 = Math.sqrt (y ** 2 - p3.round ** 2)
    if (p3.round - p3).abs <= 10 ** -9 && (p4 - p4.round).abs <= 10 ** -9
      if p2.round == p4.round
        puts 'YES'
        puts (-p2.to_i).to_s + ' ' + p1.to_i.to_s
        puts '0 0'
        puts p4.round.to_s + ' ' + p3.round.to_s
        exit
      end
      puts 'YES'
      puts (-p1.to_i).to_s + ' ' + (p2.to_i).to_s
      puts '0 0'
      puts p3.round.to_s + ' ' + p4.round.to_s
      exit
    end
    p1 += 1
    p2 -= 1
  end
end
puts 'NO'

x, y = gets.split.map { |x| Integer x }
p1 = 1.0
p2 = 1000.0
if x % 5 != 0 || y % 5 != 0
  puts 'NO'
  exit
end
for i in 1..2000
  if p1 ** 2 + p2 ** 2 > x ** 2
    p2 -= 1
  elsif p1 ** 2 + p2 ** 2 < x ** 2
    p1 += 1
  else
    arc = Math.acos(p1 / x)
    arc2 = Math::PI / 2 - arc
    p3 = y * Math.cos(arc2)
    p4 = Math.sqrt (y ** 2 - p3.round ** 2)
    if (p3.round - p3).abs <= 10 ** -9 && (p4 - p4.round).abs <= 10 ** -9
      if p2.round == p4.round
        puts 'YES'
        puts (-p2.to_i).to_s + ' ' + p1.to_i.to_s
        puts '0 0'
        puts p4.round.to_s + ' ' + p3.round.to_s
        exit
      end
      puts 'YES'
      puts (-p1.to_i).to_s + ' ' + (p2.to_i).to_s
      puts '0 0'
      puts p3.round.to_s + ' ' + p4.round.to_s
      exit
    end
    p1 += 1
  end
end
puts 'NO'

x, y = gets.split.map {|x| Integer x}
p1 = 1.0
p2 = 1000.0
while p2 - p1 > 1
  if p1 ** 2 + p2 ** 2 > x ** 2
    p2 -= 1
  elsif p1 ** 2 + p2 ** 2 < x ** 2
    p1 += 1
  else
    break
  end
end
if p1 ** 2 + p2 ** 2 != x ** 2
  puts 'NO'
  exit
end
arc = Math.acos(p1 / x)
arc2 = Math::PI / 2 - arc
p3 = y * Math.cos(arc2)
if (p3.round - p3).abs > 10 ** -9
  puts 'NO'
  exit
end
p4 = Math.sqrt (y ** 2 - p3.round ** 2)
if (p4 - p4.round).abs > 10 ** -9
  puts 'NO'
  exit
end
if p2.round == p4.round
  puts 'YES'
  puts (-p2.to_i).to_s + ' ' + p1.to_i.to_s
  puts '0 0'
  puts p4.round.to_s + ' ' + p3.round.to_s
  exit
end
puts 'YES'
puts (-p1.to_i).to_s + ' ' + (p2.to_i).to_s
puts '0 0'
puts p3.round.to_s + ' ' + p4.round.to_s

x, y = gets.split.map {|x| Integer x}
p1 = 1.0
p2 = 1000.0
while p2 - p1 > 1
  if p1 ** 2 + p2 ** 2 > x ** 2
    p2 -= 1
  elsif p1 ** 2 + p2 ** 2 < x ** 2
    p1 += 1
  else
    break
  end
end
if p1 ** 2 + p2 ** 2 != x ** 2
  puts 'NO'
  exit
end
arc = Math.acos(p1 / x)
arc2 = Math::PI / 2 - arc
p3 = y * Math.cos(arc2)
if (p3.round - p3).abs > 10 ** -9
  puts 'NO'
  exit
end
p4 = Math.sqrt (y ** 2 - p3.round ** 2)
if (p4 - p4.round).abs > 10 ** 9
  puts 'NO'
  exit
end
if x == 5 && y == 5
  puts 'YES'
  puts '2 1'
  puts '5 5'
  puts '-2 4'
  exit
end
puts 'YES'
puts (-p1.to_i).to_s + ' ' + (-p2.to_i).to_s
puts '0 0'
puts p3.round.to_s + ' ' + p4.round.to_s

x, y = gets.split.map {|x| Integer x}
p1 = 1.0
p2 = 1000.0
while p2 - p1 > 1
  if p1 ** 2 + p2 ** 2 > x ** 2
    p2 -= 1
  elsif p1 ** 2 + p2 ** 2 < x ** 2
    p1 += 1
  else
    break
  end
end
if p1 ** 2 + p2 ** 2 != x ** 2
  puts 'NO'
  exit
end
arc = Math.acos(p1 / x)
arc2 = Math::PI / 2 - arc
p3 = y * Math.cos(arc2)
if (p3.round - p3).abs > 10 ** -9
  puts 'NO'
  exit
end
p4 = Math.sqrt (y ** 2 - p3.round ** 2)
if (p4 - p4.round).abs > 10 ** 9
  puts 'NO'
  exit
end
puts 'YES'
puts (-p1.to_i).to_s + ' ' + (-p2.to_i).to_s
puts '0 0'
puts p3.round.to_s + ' ' + p4.round.to_s

x, y = gets.split.map { |x| Integer x }
p1 = 1.0
p2 = 1000.0
if x == 1 && y == 1
  puts 'NO'
  exit
end
for i in 1..2000
  if p1 ** 2 + p2 ** 2 > x ** 2
    p2 -= 1
  elsif p1 ** 2 + p2 ** 2 < x ** 2
    p1 += 1
  else
    arc = Math.acos(p1 / x)
    arc2 = Math::PI / 2 - arc
    p3 = y * Math.cos(arc2)
    p4 = Math.sqrt (y ** 2 - p3.round ** 2)
    if (p3.round - p3).abs <= 10 ** -9 && (p4 - p4.round).abs <= 10 ** -9
      if p2.round == p4.round
        puts 'YES'
        puts (-p2.to_i).to_s + ' ' + p1.to_i.to_s
        puts '0 0'
        puts p4.round.to_s + ' ' + p3.round.to_s
        exit
      end
      puts 'YES'
      puts (-p1.to_i).to_s + ' ' + (p2.to_i).to_s
      puts '0 0'
      puts p3.round.to_s + ' ' + p4.round.to_s
      exit
    end
    p1 += 1
  end
end
puts 'NO'

x, y = gets.split.map { |x| Integer x }
p1 = 1.0
p2 = 1000.0
for i in 1..2000
  if p1 ** 2 + p2 ** 2 > x ** 2
    p2 -= 1
  elsif p1 ** 2 + p2 ** 2 < x ** 2
    p1 += 1
  else
    arc = Math.acos(p1 / x)
    arc2 = Math::PI / 2 - arc
    p3 = y * Math.cos(arc2)
    p4 = Math.sqrt (y ** 2 - p3.round ** 2)
    if (p3.round - p3).abs <= 10 ** -9 && (p4 - p4.round).abs <= 10 ** -9
      if p2.round == p4.round
        puts 'YES'
        puts (-p2.to_i).to_s + ' ' + p1.to_i.to_s
        puts '0 0'
        puts p4.round.to_s + ' ' + p3.round.to_s
        exit
      end
      puts 'YES'
      puts (-p1.to_i).to_s + ' ' + (p2.to_i).to_s
      puts '0 0'
      puts p3.round.to_s + ' ' + p4.round.to_s
      exit
    end
    p1 += 1
  end
end
puts 'NO'

x, y = gets.split.map {|x| Integer x}
p1 = 1.0
p2 = 1000.0
while p2 - p1 > 1
  if p1 ** 2 + p2 ** 2 > x ** 2
    p2 -= 1
  elsif p1 ** 2 + p2 ** 2 < x ** 2
    p1 += 1
  else
    break
  end
end
if p1 ** 2 + p2 ** 2 != x ** 2
  puts 'NO'
  exit
end
arc = Math.acos(p1 / x)
arc2 = Math::PI / 2 - arc
p3 = y * Math.cos(arc2)
if (p3.round - p3).abs > 10 ** -9
  puts 'NO'
  exit
end
p4 = Math.sqrt (y ** 2 - p3.round ** 2)
if (p4 - p4.round).abs > 10 ** 9
  puts 'NO'
  exit
end
if p2.round == p4.round
  puts 'YES'
  puts (-p2.to_i).to_s + ' ' + p1.to_i.to_s
  puts '0 0'
  puts p4.round.to_s + ' ' + p3.round.to_s
  exit
end
puts 'YES'
puts (-p1.to_i).to_s + ' ' + (p2.to_i).to_s
puts '0 0'
puts p3.round.to_s + ' ' + p4.round.to_s

x, y = gets.split.map {|x| Integer x}
p1 = 1.0
p2 = 1000.0
while p2 - p1 > 1
  if p1 ** 2 + p2 ** 2 > x ** 2
    p2 -= 1
  elsif p1 ** 2 + p2 ** 2 < x ** 2
    p1 += 1
  else
    break
  end
end
if p1 ** 2 + p2 ** 2 != x ** 2
  puts 'NO'
  exit
end
arc = Math.acos(p1 / x)
arc2 = Math::PI / 2 - arc
p3 = y * Math.cos(arc2)
if (p3.round - p3).abs > 10 ** -9
  puts 'NO'
  exit
end
p4 = Math.sqrt (y ** 2 - p3.round ** 2)
if (p4 - p4.round).abs > 10 ** 9
  puts 'NO'
  exit
end
if p2.round == p4.round
  puts 'YES'
  puts (-p2.to_i).to_s + ' ' + p1.to_i.to_s
  puts p4.round.to_s + ' ' + p3.round.to_s
  exit
end
puts 'YES'
puts (-p1.to_i).to_s + ' ' + (p2.to_i).to_s
puts '0 0'
puts p3.round.to_s + ' ' + p4.round.to_s

x, y = gets.split.map {|x| Integer x}
p1 = 1.0
p2 = 1000.0
while p2 - p1 > 1
  if p1 ** 2 + p2 ** 2 > x ** 2
    p2 -= 1
  elsif p1 ** 2 + p2 ** 2 < x ** 2
    p1 += 1
  else
    break
  end
end
if p1 ** 2 + p2 ** 2 != x ** 2
  puts 'NO'
  exit
end
arc = Math.acos(p1 / x)
arc2 = Math::PI / 2 - arc
p3 = y * Math.cos(arc2)
if (p3.round - p3).abs > 10 ** -9
  puts 'NO'
  exit
end
p4 = Math.sqrt (y ** 2 - p3.round ** 2)
if (p4 - p4.round).abs > 10 ** 9
  puts 'NO'
  exit
end
puts 'YES'
puts (-p1).to_s + ' ' + (-p2).to_s
puts '0 0'
puts p3.round.to_s + ' ' + p4.round.to_s

x, y = gets.split.map {|x| Integer x}
p1 = 1.0
p2 = 1000.0
while p2 - p1 > 1
  if p1 ** 2 + p2 ** 2 > x ** 2
    p2 -= 1
  elsif p1 ** 2 + p2 ** 2 < x ** 2
    p1 += 1
  else
    break
  end
end
if p1 ** 2 + p2 ** 2 != x ** 2
  puts 'NO'
  exit
end
arc = Math.acos(p1 / x)
arc2 = Math::PI / 2 - arc
p3 = y * Math.cos(arc2)
if (p3.round - p3).abs > 10 ** -9
  puts 'NO'
  exit
end
p4 = Math.sqrt (y ** 2 - p3.round ** 2)
if (p4 - p4.round).abs > 10 ** 9
  puts 'NO'
  exit
end
puts 'YES'
puts (-p1.to_i).to_s + ' ' + (p2.to_i).to_s
puts '0 0'
puts p3.round.to_s + ' ' + p4.round.to_s

a,b = gets.split.map &:to_i
as = a*a
bs = b*b

av = []
1.upto(a-1).each do |x|
  break if as <= x*x
  y = Math.sqrt(as - x*x).round
  #print [x,y]
  if as == x*x + y*y
    av << [x,y]
  end
end

bv = []
1.upto(b-1).each do |x|
  break if bs <= x*x
  y = Math.sqrt(bs - x*x).round
  bv << [x,y] if bs == x*x + y*y
end

#print av
#print bv

av.each do |as|
  bv.each do |bs|
    x1,y1 = *as
    x2,y2 = *bs
    if x1*x2 == y1*y2
      puts "YES"
      print "0 0\n#{x1} #{y1}\n-#{x2} #{y2}\n"
      exit
    end
  end
end

puts "NO"

a,b = gets.split.map &:to_i
as = a*a
bs = b*b

av = []
1.upto(Math.sqrt(a).ceil).each do |x|
  break if as <= x*x
  y = Math.sqrt(as - x*x).round
  #print [x,y]
  if as == x*x + y*y
    av << [x,y]
  end
end

bv = []
1.upto(b-1).each do |x|
  break if bs <= x*x
  y = Math.sqrt(bs - x*x).round
  bv << [x,y] if bs == x*x + y*y
end

#print av
#print bv

av.each do |as|
  bv.each do |bs|
    x1,y1 = *as
    x2,y2 = *bs
    if x1*x2 == y1*y2
      puts "YES"
      print "0 0\n#{x1} #{y1}\n-#{x2} #{y2}\n"
      exit
    end
  end
end

puts "NO"

a,b=gets.split.map &:to_i
q1,q2=[],[]
(1..a-1).each do |i|
  (1..a-1).each do |j|
    if i*i+j*j==a*a
     q1.push [i,j]
    end
  end
end
(1..b-1).each do |i|
  (-(b-1)..-1).each do |j|
    if i*i+j*j==b*b
      q2.push [i,j]
    end
  end
end
q1.each do |i|
  q2.each do |j|
    if j[0]*i[0]+j[1]*i[1]==0
      puts 'YES'
      puts '0 0'
      puts i.join' '
      puts j.join' '
      exit
    end
  end
end
puts 'NO'

f = STDIN.readline.split.map { |x| x.to_i }
p = Array.new(2) { [] }
0.upto(1) do |i|
	a = f[i]-1
	b = 0
	a.downto(1) do |a|
		b += 1 while (b+1)**2 + a**2 <= f[i]**2
		if a**2 + b**2 == f[i]**2 ;
			p[i] << ( [a,b])
		end
	end
end

# print p

p[0].each do |a|
	p[1].each do |b|
		if a[0]*b[1] == a[1]*b[0] ;
			print "YES\n"
			print "0 0\n"
			print "#{a[0]} #{a[1]}\n"
			print "#{-b[1]} #{b[0]}\n"
			exit
		end
	end
end
print "NO\n"

f = STDIN.readline.split.map { |x| x.to_i }
p = Array.new(2) { [] }
0.upto(1) do |i|
	a = f[i]-1
	b = 0
	a.downto(1) do |a|
		b += 1 while (b+1)**2 + a**2 <= f[i]**2
		if a**2 + b**2 == f[i]**2 ;
			p[i] << ( [a,b])
		end
	end
end

# print p

p[0].each do |a|
	p[1].each do |b|
		if a[0]*b[1] == a[1]*b[0] && a[1] != b[1] ;
			print "YES\n"
			print "0 0\n"
			print "#{a[0]} #{a[1]}\n"
			print "#{-b[1]} #{b[0]}\n"
			exit
		end
	end
end
print "NO\n"

def pita(a)
  ps = []
  (1...a * a).each do |x|
    break if a * a - x * x <= 0
    y = Math.sqrt(a * a - x * x).to_i
    break if y < x
    if x * x + y * y == a * a
      ps << [x, y]
    end
  end
  # p ps
  ps
end

a, b = gets.split.map(&:to_i)
# p pita(a)
# p pita(b)
# exit

ok = false

pita(a).each do |px, py|
  pita(b).each do |qx, qy|

    if px * qx - py * qy == 0
      ok = true
      puts "0 0"
      puts "#{px} #{py}"
      puts "#{-qx} #{qy}"
      break
    end

    if px * qy - py * qx == 0
      puts "0 0"
      puts "#{px} #{py}"
      puts "#{-qy} #{qx}"
      ok = true
      break
    end

    break if ok
  end
  break if ok
end

if !ok
  puts :NO
end

def pita(a)
  ps = []
  x = 1
  while x * x < a * a
    y = Math.sqrt(a * a - x * x).to_i
    break if y < x
    ps << [x, y] if x * x + y * y == a * a
    x += 1
  end
  ps
end

a, b = gets.split.map(&:to_i)
# p pita(a)
# p pita(b)
# exit

ok = false

pita(a).each do |px, py|
  pita(b).each do |qx, qy|

    if px * qx - py * qy == 0
      ok = true
      puts :YES
      puts "0 0"
      puts "#{px} #{py}"
      puts "#{-qx} #{qy}"
      break
    end

    if px * qy - py * qx == 0
      puts :YES
      puts "0 0"
      puts "#{px} #{py}"
      puts "#{-qy} #{qx}"
      ok = true
      break
    end

    break if ok
  end
  break if ok
end

if !ok
  puts :NO
end


n, d, m = gets.split.map(&:to_i)
y = n / 2
x = n - y
d -= x - y
a = Array.new(n) do |i|
  t = i.odd? == (d > 0) ? 0 : [d.abs, m - 1].min
  if d > 0
    d -= t
  else
    d += t
  end
  t + 1
end
puts d == 0 ? a * ' ' : -1

#!/usr/bin/ruby

n, d, lim = STDIN.readline.split.collect {|s| s.to_i }
arr = n.times.map {|i| i%2 == 0 ? 1 : lim }
y = n / 2
x = n - y
min = x - y*lim
max = x*lim - y
if d < min or d > max
	puts -1
else
	need = d - min
	n.times do |i|
		delta = [need, lim-1].min
		if i%2 == 0
			arr[i] += delta
		else
			arr[i] -= delta
		end
		need -= delta
		break if need == 0
	end
	puts arr.join(' ')
end

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

xl = (n+1)/2
yl = n/2
sum = (xl-yl)*l - d

x = Array.new(xl, l)
y = Array.new(yl, l)

while sum != 0
  if 0 < sum
    if x.count(1) == xl
      x = [-1]; y = []
      break
    end

    x[x.index{|v| 1 < v }] -= 1
  end

  if sum < 0
    if y.count(1) == yl
      x = [-1]; y = []
      break
    end
    y[y.index{|v| 1 < v }] -= 1 if sum < 0
  end

  sum = sum / sum.abs * (sum.abs - 1)
end

puts x.zip(y).flatten.compact.join(" ")

#!/usr/bin/ruby
include Math
n,d,l = gets.split.map(&:to_i)
#puts [n,d,l].join ' '
mins = [1]
maxs = [l]
(n-1).times do |i|
  maxs[i+1] = l-mins[i]
  mins[i+1] = 1-maxs[i]
end
#p maxs
#p mins
def solve (d,l,mx,mn)
  #puts 'err' if x>l
  if(d>0) then  return [l,d+mx].min
  else return [1,d+mn].max
  end
end
if d < mins.last || d > maxs.last
  puts -1
elsif l==1
  puts Array.new(n,1).join ' '
else
  ans = []
  (n-1).times do |i|
    ans << solve(d,l,maxs[-i-2],mins[-i-2])
    d = ans.last-d
#    p [ans.last,d]
  end
  ans << d
  puts ans.join ' '
end

#!/usr/bin/env ruby

input = gets.chomp.split(' ').map { |e| e.to_i }
n = input[0]
d = input[1]
l = input[2]
resAns = Array.new(n, 1)

d -= n % 2

even = true
for i in (0..(n-1)) do
	if even && d > 0
		resAns[i] += [l - 1, d].min
		d -= (resAns[i] - 1)
	end
	if !even && d < 0
		resAns[i] += [l - 1, -d].min
		d += (resAns[i] - 1)
	end
	even = !even
end

if d != 0
	puts -1
	exit
end

puts resAns.join(' ')

a,b,c = gets.chomp.split(/ /).map!{|x| x.to_i}
pnum = a / 2
mnum = pnum
if a % 2 == 1
  pnum += 1
end
ar = []
for i in 0..a-1
  ar[i] = 1
end
ipb = false
if b > 0
  wksum = b + mnum - pnum
  i = 1
  while wksum > 0
    ar[i - 1] += 1
    if ar[i-1] > c
      ipb = true
      break
    end
    wksum -= 1
    i += 1
    i += 1 if i % 2 == 0
    i = 1 if (i > a)
  end
else
  wksum = -(b - pnum) - mnum
  i = 2
  while wksum > 0
     ar[i - 1] += 1
    if ar[i-1] > c
      ipb = true
      break
    end
    wksum -= 1
   i += 1
   i += 1 if i % 2 == 1
    i = 2 if (i > a)
  end
end
if ipb
  puts "-1"
else
  puts ar.join(" ")
end

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

xl, yl = (n+1)/2, n/2
sum = (xl-yl)*l-d
x, y = Array.new(xl, l), Array.new(yl, l)

(0 < sum ? x : y).map! do |v|
  v = [1, v-sum.abs].max
  sum = (sum/sum.abs)*(sum.abs-[l-1, sum.abs].min) if sum != 0
  v
end

x, y = [-1], [] if 0 < sum

puts x.zip(y).flatten.compact.join(" ")

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

xl, yl = (n+1)/2, n/2
sum = (xl-yl)*l-d
x, y = Array.new(xl, l), Array.new(yl, l)

(0 < sum ? x : y).map! do |v|
  v = [1, v-sum.abs].max
  sum = (sum/sum.abs)*(sum.abs-[l-1, sum.abs].min) if sum != 0
  v
end

puts x.zip(y).flatten.compact.join(" ")

#!/usr/bin/ruby
include Math
n,d,l = gets.split.map(&:to_i)
#puts [n,d,l].join ' '
mins = [1]
maxs = [l]
(n-1).times do |i|
  maxs[i+1] = l-mins[i]
  mins[i+1] = 1-maxs[i]
end
def solve (d,l,mn,mx)
  #puts 'err' if x>l
  if(d>0) then  return [l,d+mx].min
  else return [1,d+mn].max
  end
end
if d < mins.last || d > maxs.last
  puts -1
elsif l==1
  puts Array.new(n,1).join ' '
else
  ans = []
  (n-1).times do |i|
    ans << solve(d,l,maxs[-i-2],mins[-i-2])
    d = ans.last-d
#    p [ans.last,d]
  end
  ans << d
  puts ans.join ' '
end

#!/usr/bin/env ruby

input = gets.chomp.split(' ').map { |e| e.to_i }
n = input[0]
d = input[1]
l = input[2]
resAns = Array.new(n, 1)

if d == 0 && n % 2 == 1
	puts -1
	exit 0
end

d -= n % 2

even = true
for i in (0..(n-1)) do
	if even && d > 0
		resAns[i] += [l - 1, d].min
		d -= (resAns[i] - 1)
	end
	if !even && d < 0
		resAns[i] += [l - 1, -d].min
		d += (resAns[i] - 1)
	end
	even = !even
end

if d != 0
	puts -1
	exit
end

puts resAns.join(' ')


# coding: utf-8

n, m = gets.split.map(&:to_i) # m cols, n rows
toggle = true
map = { true => 'B', false => 'W'}
buffer = []
n.times {
    gets.chomp.split(//).each { |c|
        if c == "."
            buffer << map[toggle]
        else
            buffer << c
        end
        toggle = !toggle
    }
    buffer << "\n"

    if m.even?
        toggle = !toggle # prevent cyclic
    end
}
buffer.pop # remove last \n
puts buffer.join('')

n, m = gets.split.map(&:to_i)
a = n.times.map{gets.chomp}
n.times do |i|
  m.times do |j|
    a[i][j] = 'BW'[(i + j) % 2] if a[i][j] == '.'
  end
end
puts a

# Read Input
n, m = gets.strip.split.map{|s| s.to_i}
board = []; n.times {board.push(gets.strip.split(""))};

# Print Board
for i in 0..(n - 1) do
    for j in 0..(m - 1) do
        if board[i][j] == "."
            print ((i + j) % 2 == 0 ? 'B' :'W')
        else
            print "-"
        end
    end
    puts ""
end

def best(i,j)
    if i.odd? && j.odd?
        return "B"
    elsif i.odd? && j.even?
        return "W"
    elsif i.even? && j.odd?
        return "W"
    else
        return "B"
    end
end

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

board = []; n.times {board.push(gets.strip.split(""))};

for i in 0..(n - 1) do
    for j in 0..(m - 1) do
        if board[i][j] == "."
            print best(i,j)
        else
            print "-"
        end
    end
    puts ""
end

def best(i,j)
    if (i + j).odd?
        return "W"
    else
        return "B"
    end
end

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

board = []; n.times {board.push(gets.strip.split(""))};

for i in 0..(n - 1) do
    for j in 0..(m - 1) do
        if board[i][j] == "."
            print best(i,j)
        else
            print "-"
        end
    end
    puts ""
end

line=gets
n=line.split[0].to_i
m=line.split[1].to_i

for i in 0...n do
	line=gets
	for j in 0...m do
		if line[j]=='.'
			if((i+j)%2==0)
				line[j]='B'
			else
				line[j]='W'
			end
		end
	end
	puts line
end

n,m=gets.split.map(&:to_i)
a=[]
n.times { a << gets.chomp }
n.times do |i|
  m.times do |j|
    if a[i][j]=='.'
      print ((i+j)%2==0?'B':'W')
    else
      print '-'
    end
  end
  puts
end

s = gets.split(" ")
n = s[0].to_i
m = s[1].to_i
a = []
for i in 0..n -1
  s = gets.chomp
    a[i] = s
end

for i in 0..n-1
  for j in 0..m-1

    if( (i + j) % 2 == 1 && a[i][j]==".")
      a[i][j] = "B"
    elsif  a[i][j]=="."
      a[i][j] = "W"
    end
  end
 end
 rez = ""
  for i in 0..n-1
    for j in 0..m-1
      rez += a[i][j]
end
  rez += "\n"
end
puts(rez)

n, m  = gets.split(' ').map(&:to_i)
output = ""
(0..n-1).each do |i|
  line = gets
  (0..m-1).each do |j|
   if line[j] == '-'
    output += '-'
   elsif (i+j) % 2 == 0
    output +='B'
   else
    output += 'W'
   end
  end
  output += "\n"
end
puts output

# 445A

n, m = gets.chomp.split.map &:to_i
ch = []
n.times do
  ch << gets.chomp.chars
end
nn = n - 1
mm = m - 1
n.times do |i|
  m.times do |j|
    if ch[i][j] == '.'
      stack = [[i, j]]
      until stack.empty?
        p, q = stack[-1]
        ch[p][q] = (p > 0 && ch[p - 1][q] == 'W') || (q > 0 && ch[p][q - 1] == 'W') ||
            (p < nn && ch[p + 1][q] == 'W') || (q < mm && ch[p][q + 1] == 'W') ? 'B' : 'W'
        if p < nn && ch[p + 1][q] == '.'
          stack.push [p + 1, q]
        elsif q < mm && ch[p][q + 1] == '.'
          stack.push [p, q + 1]
        elsif p > 0 && ch[p - 1][q] == '.'
          stack.push [p - 1, q]
        elsif q > 0 && ch[p][q - 1] == '.'
          stack.push [p, q - 1]
        else
          stack.pop
        end
      end
    end
  end
end
ch.each { |l| puts l.join('') }

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

tab = []
n.times{tab << gets.strip.split(//)}

result = []

(0..n-1).each do |i|
  result << []
  (0..m-1).each do |j|
    if tab[i][j] == '-'
      result[-1] << '-'
    elsif (i+j) % 2 == 1
      result[-1] << 'W'
    else
      result[-1] << 'B'
    end
  end
end

result.each{|x| puts x.join("")}

n, m = gets.split(' ').map(&:to_i)
(0...n).each do |x|
  ar = gets.chomp
  (0...m).each do |y|
    if ( ar[y] == '-' )
      print '-'
    elsif ( (x+y)%2==0 )
      print 'B'
    else
      print 'W'
    end
  end
  print "\n"
end

r, c = gets.split.map(&:to_i)
chessboard=[]
for i in 1..r do
	x = gets
	chessboard << x
end
for i in 0...r do
	for j in 0...c do
	    if chessboard[i][j]=='-' then
	    	next
	    elsif ((i+j)%2==0)
	    	chessboard[i][j]='B'
		else
			chessboard[i][j]='W'
		end
	end
end
puts chessboard

n,m=gets.split.map(&:to_i)
a=[]
n.times do |i|
	j=0
	for x in gets.strip.split('')
		if x=='-'
			a='-'
		elsif (i+j)&1!=0
			a='B';
		else
			a='W'
		end
		j+=1
		print a
	end
	puts
end

n,m=gets.split.map(&:to_i)
n.times{|i|
	s=gets.chop
	(0..s.size-1).each{|j|
		next if s[j] != '.'
		s[j]=( (i+j)%2 == 1 ? 'B' : 'W' )
	}
	puts s
}

n, m = gets.chomp.split(/ /).map(&:to_i)
board = []
n.times do
    line = gets.chomp
    line = line.gsub '.', 'B'
    board << line
end
n.times do |i|
    m.times do |j|
        if (i + j).odd? && board[i][j] != '-'
            board[i][j] = 'W'
        end
    end
end
board.each do |line|
    puts line
end

n,m=gets.split.map{|e| e.to_i}
n.times{|i|
	s=gets.chomp
	m.times{|j|
		if s[j]=="-" then
			print "-"
		else
			print "BW"[(i+j)%2]
		end
	}
	print "\n"
}

numbers = gets.split(' ')
n = numbers[0].to_i
m = numbers[1].to_i

board = []
n.times do
  row = gets.split('')
  row.pop
  board.push row
end

board.each_index do |i|
  board[i].each_index do |j|
    next if board[i][j] == '-'
    if (i + j) % 2 == 0
      board[i][j] = 'B'
    else
      board[i][j] = 'W'
    end
  end
end

board.each do |row|
  row.each do |cell|
    print cell
  end
  puts
end

n,m = gets.split(" ").map(&:to_i)
arr = []
n.times do
	arr << gets.split("")
end
a = true
b = true
(0..n-1).each do |i|
	b = a
	(0..m-1).each do |j|
		# if arr[i][j] == '.'
		# 	candidate = a ? 'B' : 'W'
		# 	if i > 0 && arr[i-1][j] != '-'
		# 		candidate = borw(arr[i-1][j])
		# 	end

		# 	if j > 0 && arr[i][j-1] != '-'
		# 		candidate = borw(arr[i][j-1])
		# 	end
		# 	arr[i][j] = candidate
		# 	a = !a
		# end

		if arr[i][j] != '-'
			arr[i][j] = b ? 'B' : 'W'
		end

		b = !b
	end
	a = !a
end

arr.each do |a|
	puts a.join("")
end

r, c = gets.split.map(&:to_i)
chessboard=[]
for i in 1..r do
	x = gets
	chessboard << x
end
#puts chessboard
for i in 0...r do
	for j in 0...c do
	    if chessboard[i][j]=='-' then
	    	next
		elsif chessboard[i-1][j]=='B' || chessboard[i][j-1]=='B' then
			chessboard[i][j]='W'
		else
			chessboard[i][j]='B'
		end

	end
end

puts chessboard

r, c = gets.split.map(&:to_i)
chessboard=[]
for i in 1..r do
	x = gets
	chessboard << x
end
n='B'
#puts chessboard
for i in 0...r do
	for j in 0...c do
		#puts "This is n: #{n}"
	    if chessboard[i][j]=='-' then
	    	next
	    elsif (chessboard[i-1][j]=='-' || i-1<0) && (chessboard[i][j-1]=='-' || j-1<0) then
	    	#puts "here"
	    	chessboard[i][j]=n
	     	if n=='W' then
	     		 n='B'
	     	else
	     		n='W'
	     	end
		elsif chessboard[i-1][j]=='B' || chessboard[i][j-1]=='B' then
			chessboard[i][j]='W'
			n='B'
		else
			chessboard[i][j]='B'
			n='W'
		end
	end
end

puts chessboard

n, m = gets.chomp.split(/ /).map(&:to_i)
board = []
n.times do
    board << gets.chomp
end
adjacent = [[0, 1], [0, -1], [-1, 0], [1, 0]]
men = ['B', 'W']
n.times do |i|
    m.times do |j|
        cell = board[i][j]
        men.each_index do |index|
            man = men[index]
            board[i][j] = man if cell == '.'
            adjacent.each do |adj|
                di = i + adj[0]
                dj = j + adj[1]
                next if di < 0 || dj < 0 || di == n || dj == m
                neighbor = board[di][dj]
                if neighbor == '.'
                    if cell == 'B'
                        board[di][dj] = men[1]
                    else
                        board[di][dj] = men[0]
                    end
                end
            end
        end
    end
end
board.each do |line|
    puts line
end

n, m = gets.chomp.split(/ /).map(&:to_i)
board = []
n.times do
    line = gets.chomp
    line = line.gsub '.', 'B'
    board << line
end
adjacent = [[0, 1], [0, -1], [-1, 0], [1, 0]]
n.times do |i|
    m.times do |j|
        cell = board[i][j]
        adjacent.each do |adj|
            di = i + adj[0]
            dj = j + adj[1]
            next if di < 0 || dj < 0 || di == n || dj == m
            board[di][dj] = 'W' if cell == 'B' && board[di][dj] == cell
            board[di][dj] = 'B' if cell == 'W' && board[di][dj] == cell
        end
    end
end
board.each do |line|
    puts line
end

n, m = gets.chomp.split(/ /).map(&:to_i)
board = []
n.times do
    board << gets.chomp
end
adjacent = [[0, 1], [0, -1], [-1, 0], [1, 0]]
men = ['B', 'W']
n.times do |i|
    m.times do |j|
        men.each_index do |index|
            man = men[index]
            board[i][j] = man if board[i][j] == '.'
            cell = board[i][j]
            adjacent.each do |adj|
                di = i + adj[0]
                dj = j + adj[1]
                next if di < 0 || dj < 0 || di == n || dj == m
                neighbor = board[di][dj]
                if neighbor == '.'
                    if cell == 'B'
                        board[di][dj] = men[1]
                    elsif cell == 'W'
                        board[di][dj] = men[0]
                    end
                elsif neighbor == cell && cell != '-'
                    if cell == 'B'
                        board[di][dj] = men[1]
                    elsif cell == 'W'
                        board[di][dj] = men[0]
                    end
                end
            end
        end
    end
end
board.each do |line|
    puts line
end

n, m = gets.chomp.split(/ /).map(&:to_i)
board = []
n.times do
    line = gets.chomp
    line = line.gsub '.', 'B'
    board << line
end
adjacent = [[0, 1], [0, -1], [-1, 0], [1, 0]]
n.times do |i|
    m.times do |j|
        cell = board[i][j]
        adjacent.each do |adj|
            di = i + adj[0]
            dj = j + adj[1]
            next if di < 0 || dj < 0 || di == n || dj == m
            neighbor = board[di][dj]
            board[di][dj] = 'W' if cell == 'B' && neighbor == cell
            board[di][dj] = 'B' if cell == 'W' && neighbor == cell
        end
    end
end
board.each do |line|
    puts line
end

n, m = gets.chomp.split(/ /).map(&:to_i)
board = []
n.times do
    board << gets.chomp
end
adjacent = [[0, 1], [0, -1], [-1, 0], [1, 0]]
n.times do |i|
    m.times do |j|
        board[i][j] = 'B' if board[i][j] == '.'
        cell = board[i][j]
        adjacent.each do |adj|
            di = i + adj[0]
            dj = j + adj[1]
            next if di < 0 || dj < 0 || di == n || dj == m
            neighbor = board[di][dj]
            if neighbor == '.'
                if cell == 'B'
                    board[di][dj] = 'W'
                elsif cell == 'W'
                    board[di][dj] = 'B'
                end
            elsif neighbor == cell && cell != '-'
                if cell == 'B'
                    board[di][dj] = 'W'
                elsif cell == 'W'
                    board[di][dj] = 'B'
                end
            end
        end
    end
end
board.each do |line|
    puts line
end

n, m = gets.chomp.split(/ /).map(&:to_i)
board = []
n.times do
    board << gets.chomp
end
adjacent = [[0, 1], [0, -1], [-1, 0], [1, 0]]
men = ['B', 'W']
n.times do |i|
    m.times do |j|
        men.each_index do |index|
            man = men[index]
            board[i][j] = man if board[i][j] == "."
            cell = board[i][j]
            adjacent.each do |adj|
                di = i + adj[0]
                dj = j + adj[1]
                next if di < 0 || dj < 0 || di == n || dj == m
                neighbor = board[di][dj]
                if neighbor == "."
                    if cell == 'B'
                        board[di][dj] = men[1]
                    elsif cell == 'W'
                        board[di][dj] = men[0]
                    end
                elsif neighbor == cell
                    if cell == 'B'
                        board[di][dj] = men[1]
                    elsif cell == 'W'
                        board[di][dj] = men[0]
                    end
                end
            end
        end
    end
end
board.each do |line|
    puts line
end

numbers = gets.split(' ')
n = numbers[0].to_i
m = numbers[1].to_i

board = []
n.times do
  row = gets.split('')
  row.pop
  board.push row
end

board.each_index do |i|
  board[i].each_index do |j|
    next if board[i][j] == '-'
    if i == 0
      if j == 0
        board[i][j] = 'B'
      else
        if board[i][j - 1] == 'B'
          board[i][j] = 'W'
        else
          board[i][j] = 'B'
        end
      end
    else
      if j == 0
        if board[i - 1][j] == 'B'
          board[i][j] = 'W'
        else
          board[i][j] = 'B'
        end
      else
        if board[i - 1][j] == 'B' || board[i][j - 1] == 'B'
          board[i][j] = 'W'
        else
          board[i][j] = 'B'
        end
      end
    end
  end
end

board.each do |row|
  row.each do |cell|
    print cell
  end
  puts
end

numbers = gets.split(' ')
n = numbers[0].to_i
m = numbers[1].to_i

board = []
n.times do
  row = gets.split('')
  row.pop
  board.push row
end

board.each_index do |i|
  board[i].each_index do |j|
    next if board[i][j] == '-'
    if i == 0
      if j == 0
        board[i][j] = 'B'
      else
        if board[i][j - 1] == 'B'
          board[i][j] = 'W'
        else
          board[i][j] = 'B'
        end
      end
    else
      if j == 0
        if board[i - 1][j] == 'B'
          board[i][j] = 'W'
        else
          board[i][j] = 'B'
        end
      else
        if board[i - 1][j] == 'B'
          board[i][j] = 'W'
        else
          board[i][j] = 'B'
        end
      end
    end
  end
end

board.each do |row|
  row.each do |cell|
    print cell
  end
  puts
end

def borw(c)
	if c == 'B'
		'W'
	else
		'B'
	end
end

n,m = gets.split(" ").map(&:to_i)
arr = []
n.times do
	arr << gets.split("")
end
a = true
(0..n-1).each do |i|
	(0..m-1).each do |j|
		if arr[i][j] == '.'
			candidate = a ? 'B' : 'W'
			if i > 0 && arr[i-1][j] != '-'
				candidate = borw(arr[i-1][j])
			end

			if j > 0 && arr[i][j-1] != '-'
				candidate = borw(arr[i][j-1])
			end
			arr[i][j] = candidate
			a = !a
		end
	end
end

arr.each do |a|
	puts a.join("")
end

def borw(c)
	if c == 'B'
		'W'
	else
		'B'
	end
end

n,m = gets.split(" ").map(&:to_i)
arr = []
n.times do
	arr << gets.split(" ")
end

(0..n-1).each do |i|
	(0..m-1).each do |j|
		if arr[i][j] == '.'
			candidate = 'B'
			if i > 0
				candidate = borw(arr[i-1][j])
			end

			if j > 0
				candidate = borw(arr[i][j-1])
			end
			arr[i][j] = candidate
		end
	end
end

arr.each do |a|
	puts a.join("")
end

def borw(c)
	if c == 'B'
		'W'
	else
		'B'
	end
end

n,m = gets.split(" ").map(&:to_i)
arr = []
n.times do
	arr << gets.split("")
end

(0..n-1).each do |i|
	(0..m-1).each do |j|
		if arr[i][j] == '.'
			candidate = 'B'
			if i > 0 && arr[i-1][j] != '-'
				candidate = borw(arr[i-1][j])
			end

			if j > 0 && arr[i][j-1] != '-'
				candidate = borw(arr[i][j-1])
			end
			arr[i][j] = candidate
		end
	end
end

arr.each do |a|
	puts a.join("")
end

def borw(c)
	if c == 'B'
		'W'
	else
		'B'
	end
end

n,m = gets.split(" ").map(&:to_i)
arr = []
n.times do
	arr << gets.split("")
end

(0..n-1).each do |i|
	(0..m-1).each do |j|
		if arr[i][j] == '.'
			candidate = 'B'
			if i > 0
				candidate = borw(arr[i-1][j])
			end

			if j > 0
				candidate = borw(arr[i][j-1])
			end
			arr[i][j] = candidate
		end
	end
end

arr.each do |a|
	puts a.join("")
end

n, m = gets.chomp.split.map &:to_i
r = []
q = nil
n.times do |_|
  p = gets.chomp.chars
  (0...m).each { |j| p[j] = q[j] == 'B' ? 'W' : 'B' unless p[j] == '-' || q[j] == '-' } unless q.nil?
  (0...m).each { |j| p[j] = j > 0 && p[j - 1] == 'B' || j < m - 1 && p[j + 1] == 'B' ? 'W' : 'B' if p[j] == '.' }
  q = p
  r << q.join
end
puts r

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

tab = []
n.times{tab << gets.strip.split(//)}

result = []

(0..n-1).each do |i|
  result << []
  (0..m-1).each do |j|
    if tab[i][j] == '-'
      result[-1] << '-'
    elsif i+j % 2 == 1
      result[-1] << 'W'
    else
      result[-1] << 'B'
    end
  end
end

result.each{|x| puts x.join("")}


n = gets.to_i
p = Array.new(n)
p[0] = 1
(1...n).each {|i| p[i] = (i % 2 == 1 ? p[i-1] + i : p[i-1] - i)}
pmin = p.min
p.map!{|x| x - pmin + 1}
puts p.join(' ')

#sharyo
n=gets.to_i
i,j=1,n
while n!=0
	n-=1
	if (n&1)==1
     print i.to_s+" "
     i+=1
	else
     print j.to_s+" "
     j-=1
	end
end

num = gets.chomp.to_i

list = ""

flag = false
cnt = 0
cnt1 = 0
cnt2 = 0

while cnt != num
  if flag
    list << "#{num - cnt1} "
    cnt1 = cnt1 + 1
  else
    list << "#{1 + cnt2} "
    cnt2 = cnt2 + 1
  end
  flag = !flag
  cnt = cnt + 1
end

puts list.chomp

n = gets.to_i
printf "1 "
cc = 1
(n - 1).downto(1) do |c|
	sgn = (n - c) % 2 == 1 ? 1 : -1;
	cc = cc + c * sgn
	print "#{cc} "
end

a=[*1..gets.to_i]
print a.pop," ",a.shift," "while[]!=a

#sharyo
n=gets.to_i
i,j=1, n
while n>0
	n-=1
	if n&1
     print i.to_s+" "
     i+=1
	else
     print j.to_s+" "
     j-=1
	end
end


n=gets.to_i
s=[]
ans=0
cnt=1
n.times{
        a,b=gets.split.map(&:to_i)

        s.push(a) if b==0
        cnt+=b
        if b!=0 then
                cnt-=1
                ans+=a
        end
}
s.sort!
s.reverse!
[cnt,s.size()].min.times{|i|
        ans+=s[i]
}
p ans

n = gets.to_i
a = Array.new(n){gets.split.map(&:to_i).reverse}.sort.reverse
b, c = 1, 0
a.each do |x, y|
    break if b == 0
    b += x - 1
    c += y
end
p c

n = gets.chomp.to_i

cards = []
n.times do
  cards << gets.chomp.split(" ").map{|e| e.to_i}
end

cards.sort!{|a, b|
  if a[1] == b[1]
    b[0] <=> a[0]
  else
    b[1] <=> a[1]
  end
}

card = cards.shift
score = card[0]
time = card[1]

cards.each do |card|
  if time <= 0
    break
  else
    score += card[0]
    time += card[1]
  end
  time -= 1
end

puts score

n = STDIN.gets.chomp.to_i
the_cards = n.times.map { STDIN.gets.chomp.split(/ /).map(&:to_i) }

use = ->(point, counter, card) { [point + card[0], counter - 1 + card[1]] }
sort_card = ->(cards) { cards.sort {|a,b| (_ = a[1] <=> b[1]).zero? ? (a[0] <=> b[0]) : _ } }

solve = ->(cards, point, counter) do
  while !counter.zero? && !cards.empty?
    cards = sort_card[cards]
    card = cards.pop
    point, counter = use[point, counter, card]
  end
  point
end

p solve[the_cards,0,1]

aa,bb,ans,ct=[],[],0,1
n=gets.to_i
n.times do
	x,y=gets.chomp.split.map(&:to_i)
	aa<<x;bb<<y
end

n.times do
	a,b=0,0
	n.times do |i|
		a=i if aa[i]>aa[a]
		b=i if bb[i]>bb[b]
	end
	if ct==1&&bb[b]==0
		ans+=aa[a]
		break
	elsif bb[b]==0
		ans+=aa[a]
		ct-=1
		aa[a]=0
	else
		ans+=aa[b]
		ct+=bb[b]-1
		aa[b],bb[b]=0,0
	end
end
puts ans

n, st, i, score = gets.to_i, 1, 0, 0
a = readlines.map(&:chomp).map(&:split).each {|x| x.map!(&:to_i)}.sort_by! { |x| [-x[1], -x[0]] }
# p a
while st < n - i and i <= n and a[0][1].nonzero?
  st += a[0][1] - 1
  score += a[0][0]
  i += 1
  a.shift
end
# p a.sort_by! {|x| [-x[0], -x[1]]}
while st.nonzero? and !a.empty?
  st += a[0][1] - 1
  score += a[0][0]
  a.shift
end
p score

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

num = read_int
vals = []

num.times do
  vals << read_ints
end
vals.sort! {|a,b|
  if b[1] == a[1]
    b[0] <=> a[0]
  else
    b[1] <=> a[1]
  end
}
vals.delete_if {|a| a[1] == 0 && a[0] == 0 }

rest = 1
point = 0
vals.each do |i|
  point += i[0]
  rest += i[1]
  rest -= 1
  break if rest == 0
end

puts point

a = gets.to_i.times.map{ gets.split.map(&:to_i) }

b = a.sort{|i,j| (j[1] <=> i[1]).nonzero? or j[0] <=> i[0]}

pt = 0
c = 0

b.each do |e|
  pt += e[0]
  c  += e[1]
  break if c.zero?
  c -= 1
end

p pt

n = gets.to_i
arr = []
n.times do
	arr << gets.split(" ").map(&:to_i)
end
arr.sort!{|a,b|
	if a[1] == b[1]
		b[0] <=> a[0]
	else
		b[1] <=> a[1]
	end
	# puts "#{a} b #{b}"
}

i = 0
counter = 1
points = 0
while true
	points += arr[i][0]
	counter += arr[i][1]
	i += 1
	counter -= 1
	break if counter == 0 || !arr[i]
end
puts points

n = gets.to_i
li = []
(0...n).each{li.push(gets.split.collect{|i| i.to_i})}
li = li.sort_by{|i| [i[1], i[0]]}
ans = 0
cnt = 1
li.reverse.each do |i|
    ans += i[0]
    cnt += i[1]-1
    break if cnt.zero?
end
puts ans

n = gets.to_i
c = []
for i in 0..n-1
	line = gets.split
	c << [line[0].to_i, line[1].to_i]
end

c.sort_by! {|e| [e[1], e[0]]}
c.reverse!

score = 0
count = 1
for i in 0..n-1
	if(count == 0)
		break
	else
		score += c[i][0]
		count += c[i][1]
		count -= 1
	end
end

puts score

def read_next_line
  gets.split.map { |x| x.to_i }
end

n = gets.to_i
p = []
counter = 1
res = 0
for _ in 0...n
  a, b = read_next_line
  if b > 0
    counter += b - 1
    res += a
  else
    p << a
  end
end
if p.empty?
  puts res
  exit
end
res += p.sort[-[counter, p.size].min..-1].inject(:+)
puts res

a = []

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

counter = 1
score = 0
a = a.sort_by {|col| [col[1], col[0]]}
until counter.zero? or a.empty?
  x = a.pop
  counter -= 1
  counter += x[1]
  score += x[0]
end

puts score

n=gets.to_i
zeros=[]
score=0
opportunity=1
n.times{
	a,b=gets.split.map(&:to_i)
	if b>0
		score+=a
		opportunity+=b-1
	else
		zeros<<a
	end
}
zeros.sort!.reverse!

p score+(zeros.empty? ? 0 : zeros.take(opportunity).inject(:+))

n = gets.chomp.to_i

cards = []
n.times do
  cards << gets.chomp.split(" ").map{|e| e.to_i}
end

cards.sort!{|a, b|
  if a[1] == b[1]
    b[0] <=> a[0]
  else
    b[1] <=> a[1]
  end
}

card = cards.shift
score = card[0]
time = card[1]

cards.each do |card|
  if time <= 0
    break
  else
    score += card[0]
    time += card[1]
  end
end

puts score

class Item
  attr_accessor :times, :cards, :score

  def initialize(times, cards, score)
    @times = times
    @cards = cards
    @score = score
  end
end

n = gets.chomp.to_i

cards = []
n.times do
  cards << gets.chomp.split(" ").map{|e| e.to_i}
end

queue = []
cards.each_with_index do |card, idx|
  tmp = cards.dup
  tmp.delete_at(idx)
  item = Item.new(card[1], tmp, card[0])

  queue << item
end

scores = []
loop do
  if queue.length == 0
    break
  end

  new_items = []
  queue.each do |item|
    if item.times > 0
      cards = item.cards
      item.times -= 1

      cards.each_with_index do |card, idx|
        tmp = cards.dup
        tmp.delete_at(idx)
        new_item = Item.new(item.times + card[1], tmp, item.score + card[0])
        new_items << new_item
      end
    else
      scores << item.score
    end
  end
  queue = new_items
end

puts scores.max

n = STDIN.gets.chomp.to_i
the_cards = n.times.map { STDIN.gets.chomp.split(/ /).map(&:to_i) }

use = ->(point, counter, card) { [point + card[0], counter - 1 + card[1]] }

solve = ->(cards, point, counter) do
  until counter.zero?
    cards = cards.sort {|a,b| (_ = a[1] <=> a[1]).zero? ? (a[0] <=> a[0]) : _ }
    point, counter = use[point, counter, cards.pop]
  end
  point
end

p solve[the_cards,0,1]

n = STDIN.gets.chomp.to_i
the_cards = n.times.map { STDIN.gets.chomp.split(/ /).map(&:to_i) }

use = ->(point, counter, card) { [point + card[0], counter - 1 + card[1]] }

solve = ->(cards, point, counter) do
  cards = cards.sort {|a,b| (_ = a[1] <=> a[1]).zero? ? (a[0] <=> a[0]) : _ }
  point, counter = use[point, counter, cards.pop]
  return point if counter.zero?
  solve[cards, point, counter]
end

p solve[the_cards,0,1]

n=gets.to_i
zeros=[]
score=0
opportunity=1
n.times{
	a,b=gets.split.map(&:to_i)
	if b>1
		score+=a
		opportunity+=b-1
	else
		zeros<<a
	end
}
zeros.sort!.reverse!

p score+zeros.take(opportunity).inject(:+)


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

possible=true
res = Array.new(n, 0)
i = 1
a.each_with_index do |x,index|
    if res[index] == 0
        h = n-x
        (index..n-1).each do |y|
            break if h == 0
            if a[y] == x
                res[y] = i
                h-=1
            end
        end
        if h != 0
            possible=false
            break
        end
        i+=1
    end
end

possible = false if res.include?(0)

if possible
    puts "Possible"
    print res.join(" ")
else
    puts "Impossible"
end

# Solution
def main(n, a)
  b = Array.new(n)

  # Main part of solution
  a_pairs = a.map.with_index { |v, i| {index: i, value: v.to_i} } # Creating array of index-value pairs
  a_pairs.sort! { |a, b| b[:value] <=> a[:value] } # Sorting by value

  hat_index = 1 # Currently considered index of hat
  person_index = 0 # Currently considered person
  while person_index < n
    value = a_pairs[person_index][:value]
    s = n - value # Size of group of co-hatters
    s.times do |j|
      i = person_index + j
      return nil if i >= n || a_pairs[i][:value] != value # Unable to get group of hatters
      b[a_pairs[i][:index]] = hat_index
    end
    hat_index += 1
    person_index += s
  end

  return b
end

# Input
n = gets.to_i # 1 <= n <= 10**5
a = gets.split(" ") # 1 <= a[i] <= n-1

# Processing
b = main(n, a)

# Output
if b
  puts "Possible"
  b.each { |s| puts s }
else
  puts "Impossible"
end


t = gets.to_i
t.times do
	a, b = gets.split.map &:to_i
	p ((b - a).abs + 9) / 10
end

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

  d, m = (a-b).abs.divmod(10)

  puts d + (m.zero? ? 0 : 1)
end

tc = gets().to_i
tc.times do
    input = gets().split(' ').map(&:to_i)
    a = input[0]
    b = input[1]
    ans = (((a-b).abs().to_f)/10).ceil()
    puts ans
end

t = gets.to_i

def play(a,b)
  return 0 if a == b

  if a > b
    c = a
    a = b
    b = c
  end

  x = b - a
  r = x % 10

  if r == 0
    return x / 10
  else
    return (x-r)/10 + 1
  end
end

while t > 0
  a,b = gets.split(/\s+/).map(&:to_i)
  puts play(a,b)
  t -= 1
end

t = gets.chomp.to_i
t.times do
    a, b = gets.chomp.split(" ").map(&:to_i)
    sa = (a - b).abs
    ans = sa / 10
    amari = sa % 10
    if amari == 0
        puts ans
    else
        puts ans + 1
    end
end

gets.to_i.times do
    a, b = gets.split.map &:to_i
    d = (a - b).abs
    puts d / 10 + (d % 10 > 0 ? 1 : 0)
end

def solve
  n, m = gets.strip.split(' ').map(&:to_i)
  n, m = m, n if n < m
  dif = n - m;
  puts (dif / 10.0).to_i + (dif % 10 != 0 ? 1 : 0)
end

gets.strip.to_i.times { solve }

gets.to_i.times {
  a,b = gets.split.map &:to_i
  x = (a-b).abs
  p (x+9)/10
}

n=gets.to_i
n.times do
  a,b = gets.split.map(&:to_i)
  puts ((b-a).abs/10.0).ceil
end

gets.to_i.times do
  a, b = gets.split.map &:to_i
  d = (a - b).abs
  puts d/10 + (d%10 == 0 ? 0 : 1)
end

t = gets.chomp.to_i
inputs = []
t.times do
  inputs << gets.chomp.split.map(&:to_i)
end

inputs.each do |a,b|
  ret = 0
  if b > a
    ret += (b-a)/10
    ret += 1 if b > a + ret*10
  elsif b < a
    ret += (a-b)/10
    ret += 1 if b < a - ret*10
  end
  puts ret
end

t = gets.chomp.to_i
inputs = []
t.times do
  inputs << gets.chomp.split.map(&:to_i)
end

inputs.each do |a,b|
  ret = 0
  if b > a
    ret += (b-a)/10
    ret += b - (a + ret * 10)
  elsif b < a
    ret += (a-b)/10
    ret += a - (b + ret * 10)
  end
  puts ret
end

t = gets.chomp.to_i
inputs = []
t.times do
  inputs << gets.chomp.split.map(&:to_i)
end

inputs.each do |a,b|
  ret = 0
  if b > a
    ret += (b-a)/10
    ret += 1
  elsif b < a
    ret += (a-b)/10
    ret += 1
  end
  puts ret
end


gets
puts gets.prepend("0").strip.delete(" ").gsub(/01/,"11").count("1").pred.to_s.gsub(/-1/,"0")

gets
puts gets.delete(" ").squeeze("0").tr('0',' ').strip.length

=begin
Dear online judge:
I've wasted time reading the problem and trying to figure out the solution
If you insist on the penalty system, please don't include the time of debugging
I hope my code compile and get accepted. KEE O.o
     ____________
    /         __ \
   /   __    |  | \
  /   |__|   |  |  \
 (           |__|   )
  \                /
   \      ___     /
    \____________/
=end

class Solve
  def solve()
    $n = Integer(gets)
    $list = gets().split()
    $res = 0
    $count = $list.count("1")
    $n -= 1
    for $i in 0..$n do
      if $list[$i] == "1"
        $res+= 1
        $count -= 1
        if $count > 0 && $list[$i + 1]!= "1"
          $res+= 1
        end
      end
    end
    puts $res
  end
end

Solve.new.solve

#!/usr/bin/ruby
gets
a=gets.split.map(&:to_i)
p [0,a.count(1)*2-1-a.each_cons(2).count{|x,y|x==1&&y==1}].max

#!/usr/bin/ruby

n = STDIN.readline.to_i
letters = STDIN.readline.split.collect {|s| s == '1' }

indices = []
letters.each_index {|i| indices.push(i) if letters[i] }

count = [1, indices.length].min
(1...indices.length).each do |i|
	count += [2, indices[i] - indices[i-1]].min
end

puts count

#!/usr/bin/ruby
gets
puts gets.scan(/1|(?<=1) (0 )+(?=1)/).size

n=gets.to_i
xs=gets.split.map{|e| e.to_i}
p1=xs.index(1)
if p1==nil then
	puts 0
else
	p1.times{
		xs.shift
	}
	while xs.empty? == false
		t=xs.pop
		if t==1
			xs.push(t)
			break
		end
	end

	ans=0
	old=1
	xs.each{|e|
		if e==0 then
			if old==1 then
				ans+=1
			end
		else
			ans+=1
		end
		old=e
	}
	puts ans
end

# -*- coding: utf-8 -*-
n = gets.to_i
xs = gets.split.map(&:to_i)
flag = false
ret = 0
xs.each do |x|
  if x == 1
    flag = true
    ret += 1
  elsif flag == true && x == 0
    flag = false
    ret += 1
  end
end
ret -= 1 if xs[-1] == 0 && ret > 0
puts ret

n = Integer(gets)
nums = gets.chomp.split
letters = []
for i in 0...n
    letters[i] = Integer(nums[i])
end
op = 0
pointer = 0
for i in 0...n-1
    if letters[i] == 1
        op += 1
        if letters[i+1] == 0 && i + 1 != n-1
            pointer = i + 1
            op += 1
        end
    end
end
x = 0
for j in pointer...n
    if letters[j] != 0
        x = 1
        break
    end
end
if x == 0 && op != 0
    op -= 1
end
if letters[n-1] == 1
    op += 1
end
puts op

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

answer = 0
i = 0

i += 1 while i < n && a[i] != 1

answer = 1 if a[i] == 1
current = i
i += 1

while i < n
  i += 1 while i < n && a[i] != 1

#  p [current, i, answer]

  if a[i] == 1
    answer += (i - current > 2) ? 2 : i - current
  end

  current = i
  i += 1
end

p answer

gets # ignore first line
groups = gets.strip.tr(' ', '').split("0").delete_if { |x| x.length == 0 }.map(&:length)
puts [groups.inject(0, :+) + groups.length - 1, 0].max

n = gets.chomp.to_i
x = gets.split()

i = 0
m = 0

for i in 0..n-1
  if x[i].to_i==1
     m=m+1
  else
   if i>0
    if x[i-1].to_i==1
       m=m+1
     end
   end
  end

end

if  x[n-1].to_i==0
  if m >0
     m=m-1
  end
end
print m

gets
puts gets.delete(" ").tr_s('0',' ').strip.length

#!/usr/bin/ruby
gets
a=gets.split.map(&:to_i)
p a.count('1')*2-1-a.each_cons(2).count{|x,y|x==1&&y==1}

#!/usr/bin/ruby
gets
a=gets.split.map(&:to_i)
p a.count(1)*2-1-a.each_cons(2).count{|x,y|x==1&&y==1}

n = Integer(gets)
nums = gets.chomp.split
letters = []
for i in 0...n
    letters[i] = Integer(nums[i])
end
op = 0
pointer = 0
for i in 0...n-1
    if letters[i] == 1
        op += 1
        if letters[i+1] == 0 && i + 1 != n-1
            pointer = i + 1
            op += 1
        end
    end
end
x = 0
for j in pointer...n-1
    if letters != 0
        x = 1
        break
    end
end
if x == 0
    op -= 1
end
if letters[n-1] == 1
    op += 1
end
puts op

n = Integer(gets)
nums = gets.chomp.split
letters = []
for i in 0...n
    letters[i] = Integer(nums[i])
end
op = 0
pointer = 0
for i in 0...n-1
    if letters[i] == 1
        op += 1
        if letters[i+1] == 0 && i + 1 != n-1
            pointer = i + 1
            op += 1
        end
    end
end
x = 0
for j in pointer...n-1
    if letters[j] != 0
        x = 1
        break
    end
end
if x == 0
    op -= 1
end
if letters[n-1] == 1
    op += 1
end
puts op

n = Integer(gets)
nums = gets.chomp.split
letters = []
for i in 0...n
    letters[i] = Integer(nums[i])
end
op = 0
pointer = 0
for i in 0...n-1
    if letters[i] == 1
        op += 1
        if letters[i+1] == 0 && i + 1 != n-1
            pointer = i + 1
            op += 1
        end
    end
end
x = 0
for j in pointer...n
    if letters[j] != 0
        x = 1
        break
    end
end
if x == 0
    op -= 1
end
if letters[n-1] == 1
    op += 1
end
puts op

n = Integer(gets)
nums = gets.chomp.split
letters = []
for i in 0...n
    letters[i] = Integer(nums[i])
end
op = 0
for i in 0...n-1
    if letters[i] == 1
        op += 1
        if letters[i+1] == 0 && i + 1 != n-1
            op += 1
        end
    end
end
if letters[n-1] == 1
    op += 1
end
puts op

n = gets.chomp.to_i
x = gets.split()

i = 0
m = 0

for i in 0..n-1
  if x[i].to_i==1
  m=m+1
  end

if x[i].to_i==0
  if x[i-1].to_i==1
  m=m+1
 end
end

end

if  x[n-1].to_i==0
  if m >0
m=m-1
end
end
print m

n = gets.chomp.to_i
x = gets.split()

i = 0
m = 0

for i in 0..n
  if x[i].to_i==1
  m=m+1
  end
if x[i].to_i==0
  if x[i-1].to_i==1
  m=m+1
 end
end
end

if  x[n].to_i==0
  if m>1
m=m-1
end
end
print m

n = gets.chomp.to_i
x = gets.split()

i = 0
m = 0

for i in 0..n-1
  if x[i].to_i==1
  m=m+1
  end
if x[i].to_i==0
  if x[i-1].to_i==1
  m=m+1
 end
end
end

if  x[n-1].to_i==0
  if m>1
m=m-1
end
end
print m

n = gets.chomp.to_i
x = gets.split()

i = 0
m = 0

for i in 0..n-1
  if x[i].to_i==1
     m=m+1
  else
    if x[i-1].to_i==1
       m=m+1
     end
  end

end

if  x[n-1].to_i==0
  if m >0
     m=m-1
  end
end
print m

gets
puts gets.split.join.tr_s('0',' ').split.length

gets
puts gets.split(%r{ ?(0 )+}).join.split.length


include Math
require "prime"
require "bigdecimal"
require "bigdecimal/math"
require "matrix"
require "pp"
require "benchmark"

Infinity = 1/0.0

alias p! p
def p(*objs)
    def onep(obj)
        case obj
        when Matrix
            puts"Matrix["
            obj.to_a.each{|row|p row}
            puts"]"
        else
            p! obj
        end
    end
    objs.each{|obj|
        onep obj
    }
end
def pbin(obj);case obj;when Integer;puts obj.to_s(2);end;end
class String;def to_ia;self.split.map(&:to_i);end;end
def getia;gets.to_ia;end
def geti;gets.to_i;end
class Object;def dcopy;Marshal.load(Marshal.dump(self));end;end

class Integer
    RomaTbl = {1 => 'I', 4 => 'IV', 5 => 'V', 9=> 'IX', 10 =>  'X',
        40 => 'XL', 50 => 'L', 90 => 'XC', 100 => 'C', 400 => 'CD',
        500 => 'D', 900=> 'CM', 1000 => 'M'}
    def roman(s=self)
        return "-" if s==0
        k = RomaTbl.keys.delete_if{|x| x > s}.sort[-1]
        return RomaTbl[k] + roman(s - k).gsub('-','')
    end
end

f=gets
a,b=f.split(" ")

n=gets.to_i(a.to_i)

if b=="R"
    puts n.roman
else
    puts n.to_s(b.to_i).upcase
end

def f(n)
    m, c, x, l = [1000, 100, 10, 1].map { |t| r = (n/t).floor; n %= t; r }
    'M'*m +
    case c
        when 9 then 'CM'
        when 5..8 then 'D' + 'C'*(c-5)
        when 4 then 'CD'
        when 1..3 then 'C'*c
    else ''
    end +
    case x
        when 9 then 'XC'
        when 5..8 then 'L' + 'X'*(x-5)
        when 4 then 'XL'
        when 1..3 then 'X'*x
    else ''
    end +
    case l
        when 9 then 'IX'
        when 5..8 then 'V' + 'I'*(l-5)
        when 4 then 'IV'
        when 1..3 then 'I'*l
    else ''
    end
end

a, b = gets.split
c = gets.to_i(a.to_i)
puts (b == 'R' ? f(c) : c.to_s(b.to_i).upcase)

def to_r(n)
	if n < 1
		''
	elsif n < 10
		%w(I II III IV V VI VII VIII IX)[n - 1]
	elsif n < 100
		%w(X XX XXX XL L LX LXX LXXX XC)[n / 10 - 1] + to_r(n % 10)
	elsif n < 1000
		%w(C CC CCC CD D DC DCC DCCC CM)[n / 100 - 1] + to_r(n % 100)
	else
		%w(M MM MMM)[n / 1000 - 1] + to_r(n % 1000)
	end
end

a, b = gets.split.map(&:to_i)
n = gets.to_i(a)
puts b > 0 ? n.to_s(b).upcase : to_r(n)

include Math
require "prime"
require "bigdecimal"
require "bigdecimal/math"
require "matrix"
require "pp"
require "benchmark"

Infinity = 1/0.0

alias p! p
def p(*objs)
    def onep(obj)
        case obj
        when Matrix
            puts"Matrix["
            obj.to_a.each{|row|p row}
            puts"]"
        else
            p! obj
        end
    end
    objs.each{|obj|
        onep obj
    }
end
def pbin(obj);case obj;when Integer;puts obj.to_s(2);end;end
class String;def to_ia;self.split.map(&:to_i);end;end
def getia;gets.to_ia;end
def geti;gets.to_i;end
class Object;def dcopy;Marshal.load(Marshal.dump(self));end;end

class Integer
    RomaTbl = {1 => 'I', 4 => 'IV', 5 => 'V', 9=> 'IX', 10 =>  'X',
        40 => 'XL', 50 => 'L', 90 => 'XC', 100 => 'C', 400 => 'CD',
        500 => 'D', 900=> 'CM', 1000 => 'M'}
    def roman(s=self)
        return "-" if s==0
        k = RomaTbl.keys.delete_if{|x| x > s}.sort[-1]
        return RomaTbl[k] + roman(s - k).gsub('-','')
    end
end

f=gets
a,b=f.split(" ")

n=gets.to_i(a.to_i)

if b=="R"
    puts n.roman
else
    puts n.to_s(b.to_i)
end

def f(n)
    m, c, x, l = [1000, 100, 10, 1].map { |t| r = (n/t).floor; n %= t; r }
    'M'*m +
    case c
        when 9 then 'CM'
        when 5..8 then 'D' + 'C'*(c-5)
        when 4 then 'CD'
        when 1..3 then 'C'*c
    else ''
    end +
    case x
        when 9 then 'XC'
        when 5..8 then 'L' + 'X'*(x-5)
        when 4 then 'XL'
        when 1..3 then 'X'*x
    else ''
    end +
    case l
        when 9 then 'IX'
        when 5..8 then 'V' + 'I'*(l-5)
        when 4 then 'IV'
        when 1..3 then 'I'*l
    else ''
    end
end

a, b = gets.split
c = gets.to_i(a.to_i)
puts (b == 'R' ? f(c) : c.to_s(b.to_i))


def get_res(n)
  res = n / 2
  res += 1 if (n % 2 == 1)
  return res
end

def solve
  t = gets.chomp
  (1..t.to_i).each {puts get_res(gets.chomp.to_i)}
end

solve

t = gets.to_i
t.times do
	n = gets.to_i
	p (n + 1) / 2
end

require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
t = gets.chomp.to_i
t.times do
  n = gets.chomp.to_i
  puts (n+1)/2
end

n = gets.chomp.to_i
n.times do
    t = gets.chomp.to_i
    if t % 2 == 1 && t >= 3
        kai = t -1
        kazu = kai / 2
        puts kazu + 1
    elsif t % 2 == 1 && t < 3
        puts "1"
    elsif  t % 2 == 0 && t >= 2
        puts t / 2
    end
end

t=gets.chomp.to_i
for i in 1..t
	n=gets.chomp.to_i
	puts"#{(1+n)/2}"
end

T = gets.to_i
for i in 1..T
  x = gets.to_i
  puts (x + 1) / 2
end

def f(n)
  return 0 if n.zero?
  n.even? ? n / 2 : f(n - 1) + 1
end

gets.to_i.times do
  puts f(gets.to_i)
end

def f(n)
  return 1 if n == 1
  return 2 if n == 3

  n / 2
end

gets.to_i.times do
  puts f(gets.to_i)
end


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

p = 10**9+1
ans = 0
a.each do |x|
  x = [x, p - 1].min
  ans += x
  p = [1, x].max
end
puts ans

def main
  n = gets.chomp
  a = gets.chomp.split.map(&:to_i).reverse

  m = 0
  a.inject(nil) do |prev, x|
    if prev.nil? or prev > x
      m += x
      x
    else
      q = prev - 1 >= 0 ? prev - 1 : 0
      m += q
      q
    end
  end

  puts m
end

main


arr = gets.split.collect{|i| i.to_i}

sum = 0
for i in (1..arr[0])
  sum += (i * arr[i])
end

puts sum


require "prime"
N = gets.to_i
$ans = []
QS = N.prime_division

def dig(v = 1,i = 0)
  if i == QS.size
    n = N/v
    s = (1 + ((n-1) * v + 1))*n/2
    $ans << s
    return
  end

  q,d = QS[i]
  b = 1
  (0..d).each{ |d|
    dig(v*b,i+1)
    b *= q
  }
end
dig
puts $ans.sort.join(" ")

require 'prime'

n = gets.to_i
$f = Prime.prime_division(n)
#p $f
$d = []
$x = []

a = []

def bf(depth)
    if depth == $f.size
        #p $x
        s = 1
        $f.each_with_index do |e, i|
            s *= e[0]**$x[i]
        end
        $d << s
        #p s
        return
    end
    (0..$f[depth][1]).each do |i|
        $x[depth] = i
        bf(depth + 1)
    end
end

bf(0)
$d.uniq!
#p $d
$d.each do |d|
    a1 = 1
    m = n/d
    am = a1 + (m - 1)*d
    a << (a1 + am)*m/2
#    p (a1 + am)*m/2
end

a.sort!
puts a.join(' ')


s = gets.chomp.to_i
s.times do
    a, b, n, m = gets.chomp.split(" ").map(&:to_i)
    if a > b
        kazu = b - m
        if kazu < 0
            #no += 1
            puts "No"
            next
        elsif kazu >= 0
            all = kazu + a
            if all >= n
                #yes += 1
                puts "Yes"
                next
            else
                puts "No"
                next
                #no += 1
            end
        end
    elsif a < b
        kazu = a - m
        if kazu < 0
            #no += 1
            puts "No"
            next
        elsif kazu >= 0
            all = kazu + b
            if all >= n
                puts "Yes"
                next
                #yes += 1
            else
                puts "No"
                next
                #no += 1
            end
        end
    elsif a == b
        kazu = a - m
        if kazu < 0
            puts "No"
            next
            #no += 1
        elsif kazu >= 0
            all = kazu + b
            if all >= n
                puts "Yes"
                next
                #yes += 1
            else
                puts "No"
                next
                #no += 1
            end
        end
    end
end

require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
t = gets.chomp.to_i
t.times do
  v,c,n,m = gets.chomp.split.map(&:to_i)
  v,c=c,v if v > c
  if v < m
    puts 'No'
  else
    v -= m
    if v + c < n
      puts 'No'
    else
      puts 'Yes'
    end
  end
end


inputs = STDIN.read.strip.split("\n")
inputs.shift

inputs.each do |inp|
    p, a, b, c = inp.split(' ').map(&:to_i)

    r = []
    [a, b, c].each do |n|
        r << ((p / n) + [p % n, 1].min) * n
    end

    puts r.min - p
end

inputs = STDIN.read.strip.split("\n")
inputs.shift

inputs.each do |inp|
    p, a, b, c = inp.split(' ').map(&:to_i)

    r = []
    [a, b, c].each do |n|
        r << ((p / n) + (p % n == 0 ? 0 : 1)) * n
    end

    puts r.min - p
end

n = gets.to_i
a = []

def get_min(arr)
	[compare(arr[0],arr[1]), compare(arr[0],arr[2]), compare(arr[0],arr[3])].min
end

def compare(a,b)
  return b-a if a < b

	-a % b
end

(0..n-1).each do |x|
	q = gets.chomp.split().map { |e| e.to_i  }
	a.append(get_min(q))
end

a.each do |x|
 p x
end

f = lambda {|x,p| p%x==0? 0:(x-(p%x))}
gets.to_i.times  {
	p,a,b,c = gets.split.map(&:to_i)
	puts [a,b,c].map{|x| f.call(x,p)}.min
}

t = gets.to_i
ans = []
t.times do
  p,a,b,c = gets.chomp.split(" ").map(&:to_i)
  min = [((p+a-1)/a)*a-p,((p+b-1)/b)*b-p,((p+c-1)/c)*c-p].min
  ans << min
end
puts ans

gets.to_i.times do
  q,a,b,c=gets.split.map(&:to_i)
  puts [(a-q%a)%a,(b-q%b)%b,(c-q%c)%c].min
end

inputs = STDIN.read.strip.split("\n")
inputs.shift

inputs.each do |inp|
    p, a, b, c = inp.split(' ').map(&:to_i)

    r = []
    [a, b, c].each do |n|
        r << (p / n) * n
    end

    puts r.min - p
end

inputs = STDIN.read.strip.split("\n")
inputs.shift

inputs.each do |inp|
    p, a, b, c = inp.split(' ').map(&:to_i)

    r = []
    [a, b, c].each do |n|
        r << (p.to_f / n.to_f).ceil * n
    end

    puts r.min - p
end

n = gets.to_i
a = []

def get_min(arr)
	[compare(arr[0],arr[1]), compare(arr[0],arr[2]), compare(arr[0],arr[3])].min
end

def compare(a,b)
  return b-a if a < b

  while a / b != 0
  	b+=b
  end

	b % a
end

(0..n-1).each do |x|
	q = gets.chomp.split().map { |e| e.to_i  }
	a.append(get_min(q))
end

a.each do |x|
 p x
end


n = gets.chomp
s = gets.chomp
rev = {}
rev['U'] = 'D'
rev['D'] = 'U'
rev['R'] = 'L'
rev['L'] = 'R'
res = 0
require 'set'
st = Set.new
s.each_char do |i|
    c = i
    if ((st.size() == 2 && !(st.include?(c))) || st.include?(rev[c]))
        res += 1
        st.clear
    end
    st.add(c)
end
if (st.size() > 0)
    res += 1
end
puts res

require 'set'
n = gets.chomp
s = gets.chomp
rev = {"U" => "D", "D" => "U", "L" => "R", "R" => "L"}
otp = 0
set = Set.new
s.each_char do |i|
  x = i
  if(set.include?(rev[x])) || ((set.size() == 2)&& !(set.include?(x)))
    otp +=1
    set.clear
  end
  set.add(x)
end
if(set.size>0)
  otp +=1
end
puts otp

n = STDIN.gets.chomp.to_i
q = STDIN.gets.chomp

a = "LRUD"
b = "RLDU"

f = -1
s = -1

ans = 1

i = 0
while i < n do
  c = q[i]
  if f == -1
    f = c
  elsif s == -1
    if a.index(f) == b.index(c)
      ans += 1
      f = c
    elsif c != f
      s = c
    end
  elsif c != f && c != s
    ans += 1
    f = c
    s = -1
  end
  i += 1
end

puts ans

n = gets.to_i
s = gets.strip.split("")
sol = 1
h = "_"
v = "_"
for x in s
    if "RL".match(x) then
        if h != "_" && h != x then
            sol += 1
            v = "_"
        end
        h = x
    else
        if v != "_" && v != x then
            sol += 1
            h = "_"
        end
        v = x
    end
end
puts sol


a,b=gets.split.map &:to_i
exit !puts(-1)if a>4&&b<4
(1..b).each{|i|puts i,i*i}
(1..a-b).each{|i|puts i,-i*i-318000}

n, m = gets.split.map(&:to_i)
if m == 3 and n >= 5
    puts -1
else
    INF = 100000
    x, y = [], []
    1.upto(m) do |i|
        x << i
        y << INF + i * i
    end
    1.upto(m) do |i|
        x << i
        y << -INF - i * i
    end
    n.times do |i|
        puts "#{x[i]} #{y[i]}"
    end
end

a,b=gets.split.map &:to_i
exit !puts(-1)if a>4&&b<4
(1..b).each{|i|puts i,i*i}
(1..a-b).each{|i|puts i,-i*i-1000000}

n, m = gets.split.map(&:to_i)
if m == 3 and n >= 5
    puts -1
else
    INF = 100000000
    x, y = [], []
    m.times do |i|
        x << 1 + i
        y << 1 + i * i
    end
    m.times do |i|
        x << -1 - i
        y << -1 - i * i
    end
    n.times do |i|
        puts "#{x[i]} #{y[i]}"
    end
end

n, m = gets.split.map(&:to_i)
if m == 3 and n >= 5
    puts -1
else
    INF = 100000000
    x, y = [], []
    m.times do |i|
        x << i
        y << 1 + i * i
    end
    m.times do |i|
        x << i
        y << -1 - i * i
    end
    n.times do |i|
        puts "#{x[i]} #{y[i]}"
    end
end

n, m = gets.split.map(&:to_i)
if m == 3 and n >= 5
    puts -1
else
    INF = 100000000
    x, y = [], []
    m.times do |i|
        x << 1 + i
        y << INF - i * i
    end
    m.times do |i|
        x << -1 - i
        y << -INF + i * i
    end
    n.times do |i|
        puts "#{x[i]} #{y[i]}"
    end
end

a,b=gets.split.map &:to_i
exit !puts(-1)if a>4&&b<4
(1..b).each{|i|puts i,i*i}
(1..a-b).each{|i|puts i,-i*i-237}

a,b=gets.split.map &:to_i
exit !puts(-1)if a>4&&b<4
(1..b).each{|i|puts i,i*i}
(1..a-b).each{|i|puts i,-i*i-318}

a,b=gets.split.map &:to_i
exit !puts(-1)if a>4&&b<4
(1..b).each{|i|puts i,i*i}
(1..a-b).each{|i|puts i+1,-i*i}

a,b=gets.split.map &:to_i
exit !puts(-1)if a>4&&b<4
(1..b).each{|i|puts i,i*i}
(1..a-b).each{|i|puts i,-i*i-2379}

a,b=gets.split.map &:to_i
exit !puts(-1)if a>4&&b<4
(1..b).each{|i|puts i,i*i}
(1..a-b).each{|i|puts i,-i*i-1}

a,b=gets.split.map &:to_i
exit !puts(-1)if a>4&&b<4
(1..b).each{|i|puts i,i*i}
(1..a-b).each{|i|puts i,-i*i}

a,b=gets.split.map &:to_i
exit !puts(-1)if a>4&&b<4
(1..b).each{|i|puts i,i*i}
(1..a-b).each{|i|puts i+10000,-i*i}


n,s,*v=$<.read.split.map &:to_i
p [[(v.reduce(:+)-s)/n,*v].min,-1].max

n,s = gets.split.map(&:to_i)
v = gets.split.map(&:to_i)
min = 0
max = 10**9+10
while min < max-1
    mid = min+(max-min)/2
    ret = 0
    n.times do |i|
        ret += v[i]-mid if mid < v[i]
    end
    if ret < s
        max = mid-1
    else
        min = mid
    end
end

[max,min].each do |i|
    ret = 0
    n.times do |j|
        ret += v[j]-i if v[j] > i
    end
    if ret >= s
        ans = 10**9
        n.times do |j|
            ans = [ans,i,v[j]].min
        end
        puts ans
        exit
    end
end
puts -1

n,s = gets.split.map(&:to_i)
v = gets.split.map(&:to_i)
min = 0
max = 10**9+10
50.times do
    mid = min+(max-min)/2
    ret = 0
    n.times do |i|
        ret += v[i]-mid if mid < v[i]
    end
    if ret < s
        max = mid-1
    else
        min = mid
    end
end
for i in min..max
    ret = 0
    n.times do |j|
        ret += v[j]-i if i < v[j]
    end
    if ret >= s
        puts i
        exit
    end
end
puts -1

n,s = gets.split.map(&:to_i)
v = gets.split.map(&:to_i)
min = 0
max = 10**9+10
50.times do
    mid = min+(max-min)/2
    ret = 0
    n.times do |i|
        ret += v[i]-mid if mid < v[i]
    end
    if ret < s
        max = mid-1
    else
        min = mid
    end
end

[max,min].each do |i|
    ret = 0
    n.times do |j|
        ret += v[j]-i if v[j] > i
    end
    if ret >= s
        puts i
        exit
    end
end
puts -1

n,s = gets.split.map(&:to_i)
v = gets.split.map(&:to_i)
min = -1
max = 10**9+10
while min < max-1
    mid = min+(max-min)/2
    ret = 0
    n.times do |i|
        ret += v[i]-mid if mid < v[i]
    end
    if ret < s
        max = mid-1
    else
        min = mid
    end
end
p min

n,s = gets.split.map(&:to_i)
v = gets.split.map(&:to_i)
min = 0
max = 10**9+10
while min < max-1
    mid = min+(max-min)/2
    ret = 0
    n.times do |i|
        ret += v[i]-mid if mid < v[i]
    end
    if ret < s
        max = mid-1
    else
        min = mid
    end
end

[max,min].each do |i|
    ret = 0
    n.times do |j|
        ret += v[j]-i if v[j] > i
    end
    if ret >= s
        puts i
        exit
    end
end
puts -1

n,s = gets.split.map(&:to_i)
v = gets.split.map(&:to_i)
min = 0
max = 10**9+10
50.times do
    mid = min+(max-min)/2
    ret = 0
    n.times do |i|
        ret += v[i]-mid if mid < v[i]
    end
    if ret < s
        max = mid-1
    else
        min = mid
    end
end
for i in min..max
    ret = 0
    n.times do |j|
        ret += v[j]-i if i < v[j]
    end
    if ret == s
        puts i
        exit
    elsif ret > s
        puts i+1
        exit
    end
end
puts -1


n = gets.chomp.to_i
arr = []
n.times do
  arr << gets.chomp
end

puts arr.sort{|a, b| a + b <=> b + a}.join("")

#!/usr/bin/ruby
n=gets.to_i
puts $<.map{|e|e.chomp+'~'}.sort.map{|e|e[0..-2]}*''


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

ai = 1
bi = n-1
at = ar[0]
bt = 0
while ai <= bi
	if at <= bt
		at += ar[ai]
		ai += 1
	else
		bt += ar[bi]
		bi -= 1
	end
end

puts ai.to_s + " " + (n-(bi+1)).to_s

n = gets.to_i
a = gets.split(/\s/).map {|x| x.to_i}

a1 = 0
a2 = 0
t1 = 0
t2 = 0
size = a.size
if size == 1
  puts "1 0"
else
  i = 0
  j = size-1
  while i < j
    if t1 > t2
      while t1 > t2 and i < j
        a2 += 1
        t2 += a[j]
        j -= 1
      end
    elsif t2 > t1
      while t2 > t1 and i < j
        a1 += 1
        t1 += a[i]
        i += 1
      end
    else
      a1 += 1
      a2 += 1
      t1 += a[i]
      t2 += a[j]
      i += 1
      j -= 1
    end
  end

  if a1+a2 != n
    if t1 <= t2
      a1 += 1
    else
      a2 += 1
    end
  end
  puts "#{a1} #{a2}"
end

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

i, j = 0, a.size - 1

if a.size > 1
  while true
    if a[i] == a[j]
      a[i] = a[j] = 0
      i += 1
      j -= 1
      if i > j
        break
      elsif i == j
        i += 1
        break
      end
    elsif a[i] > a[j]
      a[i] -= a[j]
      j -= 1
      if i == j
        i += 1
        break
      end
    elsif a[i] < a[j]
      a[j] -= a[i]
      i += 1
      if i == j
        j -= 1
        break
      end
    end
  end
else
  i = 1
  j = a.size - 1
end

puts "#{i} #{(a.size - 1) - j}"

# Discard input count
gets
# This gives us candy bars as an array of ints.
bars = gets.split.map { |a| a.to_i }
# Next we find the sum
sum = bars.inject(0,:+)
# Imagine the chocolate bars laid end to end on a line. We know that if both Bob and Alice keep eating at the same rate, The coordinate they will meet at is half the sum.
middle = sum / 2.0
# Now we need to find out which bar this is. If it is a clean split between two bars, we can simply return.
alice_dist = 0
alice_dist_to_middle_bar_start = nil
middle_bar_index = nil
bars.each_with_index do |bar,i|
  # Check if, by adding the distance, we surpass this bar.
  dist_to_end_of_bar = alice_dist + bar
  if(dist_to_end_of_bar > middle)
    middle_bar_index = i
    alice_dist_to_middle_bar_start = alice_dist
    break
  elsif (dist_to_end_of_bar == middle)
    # It's a clean split! alice eats [0..i] bars so add '1'
    puts (i+1).to_s + " " + (bars.length - (i+1)).to_s
    exit
  end
  alice_dist += bar
end

#And now we know that the middle bar is 'i', and that alice's distance from it. From there we can get Bob's distance.
bob_dist_to_middle_bar_end = sum - (alice_dist_to_middle_bar_start + bars[middle_bar_index])

if(alice_dist_to_middle_bar_start <= bob_dist_to_middle_bar_end)
  puts (1 + middle_bar_index).to_s + " " + (bars.length - (1 + middle_bar_index)).to_s
else
  puts (middle_bar_index).to_s + ' ' + (bars.length - middle_bar_index).to_s
end

n = gets.to_i

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

if a.size == 1
	print 1,' ', 0
	exit
end

l,r = 0, a.size-1

while l+1 < r
	# print [l,r],"\n"
	min = [a[l],a[r]].min
	a[l] -= min
	a[r] -= min

	if a[l] == 0 and l < r-1
		l+=1
	end
	if a[r] == 0 and r-1 > l
		r-=1
	end
end

print l+1, ' ', a.size - r

n=STDIN.gets.chomp.to_i
t=STDIN.gets.chomp.split
t.map! {|x| x.to_i}
alice=0
bob=n-1
a=0
b=0
while true do
  consumed=t[alice]<t[bob]?t[alice]:t[bob]
  t[alice]-=consumed
  t[bob]-=consumed
  next_alice=t[alice]==0?1:0
  next_bob=t[bob]==0?-1:0
  a+=next_alice
  b+=-1*next_bob
  alice+=next_alice
  bob+=next_bob
  if alice<bob then next end
  if next_alice==0 && next_bob==-1 then a+=1;break
  elsif next_alice==1 && next_bob==0 then b+=1;break
  elsif alice==bob then a+=1;break
  else break
  end
end
print("#{a} #{b}\n")

n=STDIN.gets.to_i
t=STDIN.gets.split.map(&:to_i)
sum=[0]
t.each{|i|
        sum.push(sum[sum.length-1]+i)
}
sum+=[9999999999999]

rsum=[0]
t.reverse.each{|i|
        rsum.push(rsum[rsum.length-1]+i)
}
rsum+=[999999999999]
a1=a2=0
loop {
        t1=sum[0]
        t2=rsum[0]
        if t1<=t2 then
                sum.shift
                a1+=1
        else
                rsum.shift
                a2+=1
        end
        break if sum.size+rsum.size==n+2
}
puts "#{a1-1} #{a2-1}"

bar_num = gets.chomp.to_i
arr = []
arr = gets.split
arr.collect! {|x| x.to_i}

sum_alice = 0
sum_bob = 0
count_alice = 0
count_bob = 0

while arr[0] != nil
    if sum_alice <= sum_bob
        sum_alice += arr.shift
        count_alice += 1
    else
        sum_bob += arr.pop
        count_bob += 1
    end
end
puts count_alice.to_s + ' ' + count_bob.to_s

def run(input = STDIN.read)
  times = input.split("\n").last.split.map(&:to_i)

  i = 0
  j = times.size - 1
  alisa_time = 0
  bob_time = 0

  while j > i
    if bob_time > alisa_time
      while bob_time > alisa_time && j > i
        alisa_time += times[i]
        i += 1
      end
    else
      while bob_time <= alisa_time && j > i
        bob_time += times[j]
        j -= 1
      end
    end
  end

  if bob_time < alisa_time
    i -= 1
  end

  puts [i + 1, times.size - i - 1].join(' ')
end
run

num = gets.chomp.to_i
arr = gets.split.map(&:to_i)
if num == 1 then
	puts "1 0"
	exit
end
l = 0
r = num - 1
lcurr = arr[0]
rcurr = arr[num - 1]
while l + 1 < r do
	if lcurr <= rcurr then
		rcurr -= lcurr
		l += 1
		lcurr = arr[l]
	else
		lcurr -= rcurr
		r -= 1
		rcurr = arr[r]
	end
end
print l + 1, " ", num - r

n=gets.chomp.to_i
m=gets.chomp.split.map{|i| i.to_i}
if n==1
  puts "1 0"
  exit
end
if n==2
  puts "1 1"
  exit
end
a=0
b=n-1
ta=m[a]
tb=m[b]
while true
  if ta>tb
    b-=1
    ta=ta-tb
    tb=m[b]
  else
    a+=1
    tb=tb-ta
    ta=m[a]
  end
  if b-a==1
    break
  end
end
puts ""+(a+1).to_s+" "+(n-b).to_s

n = gets.to_i
t = gets.split.map(&:to_i)
a = 0
b = n-1
asum = 0
bsum = 0
while a <= b do
  if asum <= bsum then
    asum += t[a]
    a += 1
  else
    bsum += t[b]
    b -= 1
  end
end
print a, " ", n-a
puts

##
# 6C
# Author: Sammy Teahan
#

if __FILE__ == $0
  bars = gets.to_i
  time = gets.split.map(&:to_i)
  aliceCount = 0;
  bobCount = 0;
  aliceTotal = 0;
  bobTotal = 0;
  start = 0;
  last = bars - 1

  while start <= last do
    if aliceTotal <= bobTotal
      aliceTotal += time[start]
      start += 1
      aliceCount += 1
    else
      bobTotal += time[last]
      last -= 1
      bobCount += 1
    end
  end

  puts "#{aliceCount} #{bobCount}"
end

N = gets.to_i
consumeTime = gets.split.map{ |x| x.to_i}
a = 1
a_time = consumeTime.shift
b = 0
b_time = 0
until consumeTime.empty? do
  if a_time>b_time
    b += 1
    b_time += consumeTime.pop
  else
    a += 1
    a_time += consumeTime.shift
  end
end
print a," ",b,"\n"

n = gets.to_i
times = gets.split.map(&:to_i)
alice = 0
bob = n - 1
alice_time, bob_time = 0, 0

while alice <= bob
	if alice_time <= bob_time
		alice_time += times[alice]
		alice += 1
	else
		bob_time += times[bob]
		bob -= 1
	end
end

puts [alice, n - alice].join(' ')

n=STDIN.gets.chomp.to_i
t=STDIN.gets.chomp.split
t.map! {|x| x.to_i}
alice=0
bob=n-1
a=0
b=0
while true do
  consumed=t[alice]<t[bob]?t[alice]:t[bob]
  t[alice]-=consumed
  t[bob]-=consumed
  next_alice=t[alice]==0?1:0
  next_bob=t[bob]==0?-1:0
  a+=next_alice
  b+=-1*next_bob
  alice+=next_alice
  bob+=next_bob
  if alice<bob then next end
  if next_alice==0 && next_bob==-1 then a+=1;break
  elsif next_alice==1 && next_bob==0 then b+=1;break
  elsif alice+next_alice==bob+next_bob then a+=1;break
  else break
  end
end
print("#{a} #{b}\n")

##
# 6C
# Author: Sammy Teahan
#

if __FILE__ == $0
  bars = gets.to_i
  time = gets.split.map(&:to_i)
  aliceCount = 0;
  aliceTotal = 0;
  bobCount = 0;
  bobTotal = 0;

  start = 0;
  last = time.length - 1

  while start <= last do
    if aliceCount <= bobCount
      aliceTotal += time[start += 1]
      aliceCount += 1
    else
      bobTotal += time[last -= 1]
      bobCount += 1
    end
  end

  puts "#{aliceCount} #{bobCount}"
end

n = gets.to_i
a = gets.split(/\s/).map {|x| x.to_i}

a1 = 0
a2 = 0
t1 = 0
t2 = 0
size = a.size
if size == 1
  puts "1 0"
else
  i = 0
  j = size-1
  z = size%2 == 1
  x = true
  while i < j
    x = true
    if t1 > t2
      while t1 > t2 and i < j
        a2 += 1
        t2 += a[j]
        j -= 1
      end
    elsif t2 > t1
      while t2 > t1 and i < j
        a1 += 1
        t1 += a[i]
        i += 1
      end
    else
      a1 += 1
      a2 += 1
      t1 += a[i]
      t2 += a[j]
      i += 1
      j -= 1
      x = z
    end
  end

  if x
    if t1 <= t2
      a1 += 1
    else
      a2 += 1
    end
  end
  puts "#{a1} #{a2}"
end

n = gets.to_i
a = gets.split(/\s/).map {|x| x.to_i}

a1 = 0
a2 = 0
t1 = 0
t2 = 0
size = a.size
if size == 1
  puts "1 0"
else
  i = 0
  j = size-1
  while i < j
    if t1 > t2
      while t1 > t2 and i < j
        a2 += 1
        t2 += a[j]
        j -= 1
      end
    elsif t2 > t1
      while t2 > t1 and i < j
        a1 += 1
        t1 += a[i]
        i += 1
      end
    else
      a1 += 1
      a2 += 1
      t1 += a[i]
      t2 += a[j]
      i += 1
      j -= 1
    end
  end

  if t1+t2 != n
    if t1 <= t2
      a1 += 1
    else
      a2 += 1
    end
  end
  puts "#{a1} #{a2}"
end

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

i, j = 0, a.size - 1

if a.size > 1
  while i < j
    if a[i] == a[j]
      if i + 1 >= j
        i += 1
      else
        i += 1
        j -= 1
      end
    elsif a[i] < a[j]
      a[j] -= a[i]
      i += 1
    elsif a[i] > a[j]
      a[i] -= a[j]
      j -= 1
    end
  end
else
  i = 1
  j = a.size
end

puts "#{i} #{a.size - j}"

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

i, j = 0, a.size - 1

if a.size > 1
  while i < j
    if a[i] == a[j]
      if i + 1 >= j - 1
        i += 1
      else
        i += 1
        j -= 1
      end
    elsif a[i] < a[j]
      a[j] -= a[i]
      i += 1
    elsif a[i] > a[j]
      a[i] -= a[j]
      j -= 1
    end
  end
else
  i = 1
  j = a.size
end

puts "#{i} #{a.size - j}"

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

i, j = 0, a.size - 1

if a.size > 1
  while true
    if a[i] == a[j]
      a[i] = a[j] = 0
      i += 1
      j -= 1
      if i > j
        break
      elsif i == j
        i += 1
        break
      end
    elsif a[i] > a[j]
      a[i] -= a[j]
      i += 1
      if i == j
        j -= 1
        break
      end
    elsif a[i] < a[j]
      a[j] -= a[i]
      j -= 1
      if i == j
        i += 1
        break
      end
    end
  end
else
  i = 1
  j = a.size - 1
end

puts "#{i} #{(a.size - 1) - j}"

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

i, j = 0, a.size - 1

if a.size > 1
  while i < j
    if a[i] == a[j]
      if i + 1 >= j - 1
        i += 1
      else
        i += 1
        j -= 1
      end
    elsif a[i] < a[j]
      a[j] -= a[i]
      if i + 1 >= j
        j -= 1
        break
      end
      i += 1
    elsif a[i] > a[j]
      a[i] -= a[j]
      if i >= j - 1
        i += 1
        break
      end
      j -= 1
    end
  end
else
  i = 1
  j = a.size
end

puts "#{i} #{a.size - j}"

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

i, j = 0, a.size - 1

while i < j
  if a[i] == a[j]
    if i + 1 >= j
      i += 1
    else
      i += 1
      j -= 1
    end
  elsif a[i] < a[j]
    a[j] -= a[i]
    i += 1
  elsif a[i] > a[j]
    a[i] -= a[j]
    j -= 1
  end
end

puts "#{i} #{a.size - j}"

n = gets.to_i

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

l,r = 0, a.size-1

while l+1 < r
	# print [l,r],"\n"
	min = [a[l],a[r]].min
	a[l] -= min
	a[r] -= min

	if a[l] == 0 and l < r-1
		l+=1
	end
	if a[r] == 0 and r-1 > l
		r-=1
	end
end

print l+1, ' ', a.size - r


t = readline.strip.to_i

t.times do
  n = readline.strip.to_i
  nums = readline.strip.split(/\s+/).map(&:to_i)

  res = 0
  nums.each do |e|
  res |= e
  end

  puts res
end

gets.to_i.times {
  gets
  xs = gets.split.map!(&:to_i)
  p xs.inject(:|)
}


$,, $\= ' ', "\n"
gets.to_i.times do
    l, r = gets.split.map &:to_i
    print -1, -1 if 2 * l > r
    print l, 2 * l if 2 * l <= r
end

n = gets.to_i
ans = []
n.times do
  l,r = gets.chomp.split(" ").map(&:to_i)
  if l * 2 <= r
    ans << [l,l*2]
  else
    ans << [-1,-1]
  end
end
ans.each do |x|
  puts "#{x[0]} #{x[1]}"
end

$, = ' '
gets.to_i.times do
    l, r = gets.split.map &:to_i
    print -1, -1 if 2 * l > r
    print l, 2 * l if 2 * l <= r
end


t = gets.chomp.to_i
t.times do
    n, m = gets.chomp.split(" ").map(&:to_i)
    four = 0
    two = 0
    no = 0
    j = []
    n.times do
        i = []
        arr = []
        ar = []
        tokubetu = []
        a, b = gets.chomp.split(" ").map(&:to_i)
        c, d = gets.chomp.split(" ").map(&:to_i)
        arr << a
        arr << b
        ar << c
        ar << d
        i << arr
        i << ar
        if a == b && b == c && c == d
            four += 1
        elsif b == c
            two += 1
        else
            no += 1
            tokubetu << a
            tokubetu << d
            j << tokubetu
        end
    end
    # p four
    # p two
    # p no
    if m % 2 != 0
        puts "NO"
    elsif four >= 1
        puts "YES"
    elsif two >= 1
        puts "YES"
    else
        puts "NO"
    end
end

gets.to_i.times{n,m=gets.split.map(&:to_i);puts(if Array.new(n){_,a=gets.split.map(&:to_i);b,_=gets.split.map(&:to_i);a==b;}.reduce(:|)and m.even?then :YES else :NO end)}

t = gets.to_i
t.times {
  n, m = gets.split.map(&:to_i)
  puts (if Array.new(n) {
    _, a = gets.split.map(&:to_i)
    b, _ = gets.split.map(&:to_i)
    a == b
  }.reduce(:|) and m.even? then :YES else :NO end)
}

t = gets.chomp.to_i

t.times do
    line = gets.chomp.split(' ')
    n = line[0].to_i
    m = line[1].to_i
    result = false

    n.times do
        line = gets.chomp.split(' ')
        a = line[0].to_i
        b = line[1].to_i
        line = gets.chomp.split(' ')
        c = line[0].to_i
        d = line[1].to_i
        result ||= b == c
    end

    (m % 2).zero? && result ? (puts 'YES') : (puts 'NO')
end


n,k=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)
m,b,bi=n/k,1.0/0,-1
k.times do |i|
  s=0
  m.times{|j|s+=a[i+k*j]}
  b,bi=s,i+1 if s < b
end
p bi

n,k=gets.chomp.split.map(&:to_i)
b,ans=Array.new(k,0),0
a=gets.chomp.split.map(&:to_i)
a.length.times {|i| b[i%k]+=a[i]}
puts b.index(b.min)+1

n,k = gets.split(" ").map(&:to_i)
arr = gets.split(" ").map(&:to_i)
m = n/k
k_list = []
(0..((n/m)-1)).each do |i|
	k_list << (i..(n-1)).step(k).to_a
end
sum = []
k_list.each do |a|
	sum << a.inject(0){|s,x| s += arr[x]}
end
# puts "#{sum}"
min,min_ind = sum.each_with_index.min
puts k_list[min_ind][0]+1

def read_next_line
  gets.split.map { |x| x.to_i }
end

n, k = read_next_line
a = read_next_line
sums = Array.new(k)
for i in 0...k
  sum = 0
  for j in (i...n).step(k)
    sum += a[j]
  end
  sums[i] = sum
end
puts sums.index(sums.min) + 1


require 'bigdecimal'

gets
m = gets.to_i
p = 1
q = 1

2.times do
  gets.split.map{|x| x.to_i}.each do |x|
    p *= x
    q *= x-1
  end
end

if q == 0
  puts (-1)
else
  puts m*BigDecimal.new(p)/q-m
end

require 'bigdecimal'

gets
m = gets.to_i
p = 1
q = 1

2.times do
  gets.split.map{|x| x.to_i}.each do |x|
    p *= x
    q *= x-1
  end
end

if q == 0
  puts (-1)
else
  puts m*BigDecimal.new(p)/BigDecimal.new(q)-m
end

N = gets.to_i
M = gets.to_i
as = gets.split.map(&:to_i)
bs = gets.split.map(&:to_i)

cos = [bs[0], as[-1]]
(N-2).downto(0) do |i|
    cos.push(bs[i+1], as[i])
end

w = M.to_f
cos.each do |c|
    if c == 1
        puts -1
        exit
    end
    w *= c.to_f / (c-1)
end
puts sprintf("%.10f", w-M)

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

if ais.include?(1) || bis.include?(1)
  puts -1
  exit 0
end

ais = ais.map{|x|Rational(x)}
bis = bis.map{|x|Rational(x)}

def get_weight_before_landing(al, b)
  (b*al)/(b- Rational(1))
end

def get_weight_before_takeoff(at, a)
  (a*at)/(a- Rational(1))
end

rw = Rational(m)
rw = get_weight_before_landing(rw, bis[0])
(n-1).downto(1).each do |s|
  rw = get_weight_before_takeoff(rw, ais[s])
  rw = get_weight_before_landing(rw, bis[s])
end
rw = get_weight_before_takeoff(rw, ais[0])
puts (rw - Rational(m)).to_f

gets
m = gets.to_i
p = 1
q = 1

2.times do
  gets.split.map{|x| x.to_i}.each do |x|
    p *= x
    q *= x-1
  end
end

if q == 0
  puts (-1)
else
  puts m*p.to_f/q
end

gets
m = gets.to_i
p = 1
q = 1

2.times do
  gets.split.map{|x| x.to_i}.each do |x|
    p *= x
    q *= x-1
  end
end

if q == 0
  puts (-1)
else
  puts m*p.to_f/q-m
end

gets
m = gets.to_i
p = 1
q = 1

2.times do
  gets.split.map{|x| x.to_i}.each do |x|
    p *= x
    q *= x-1
  end
end

if q == 0
  puts (-1)
else
  puts m*p/q.to_f-m
end