a = STDIN.readlines[1].split.map(&:to_i).sort
a[-1] = (a[-1] == 1 ? 2 : 1)
puts a.sort.join ' '

n=gets.to_i;
a=gets.split.map{|x| x.to_i }.sort;
a[n-1]=(a[n-1]==1)?2:1;
a.sort.map{|x| print(x," "); };
puts();

gets()
a = gets().split(' ').map(&:to_i).sort()
if a[-1] == 1 then
  a[-1] = 2
else
  a[-1] = 1
  a.sort!()
end

puts a.join(' ')

#$stdin = File.open("input.txt")
#$stdout = File.open("output.txt","w")

N = gets.chomp.to_i
A = gets.chomp.split.map { |c| c = c.to_i }
A.sort!
if A[-1] == 1
	A[-1] = 2
else
	A[-1] = 1
end
A.sort!
puts A.join(" ")

#!/usr/bin/ruby

def readNextValues
  return gets.chomp.split.collect {|x| x.to_i }
end

n = readNextValues
arr = readNextValues

max_i = 0
max_val = 0

for i in 0..arr.size-1
  if arr[i] > max_val
    max_i = i
    max_val = arr[i]
  end
end

if max_val == 1
  arr[max_i] = 2
else
  arr[max_i] = 1
end

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

#!/usr/bin/ruby
def readNextValues
  return gets.chomp.split.map(&:to_i)
end
n = gets.chomp.to_i
arr = readNextValues

max_val = arr.max
max_i = arr.index(max_val)
arr[max_i] = (max_val == 1) ? 2 : 1

puts arr.sort.join(' ')

n=gets.to_i
a=gets.split.map(&:to_i)
a.sort!
b=1
f=false
a.each{|i|
        if i!=1 then
                f=true
        end
}
cnt=0
a.each{|i|
        r=i
        if i!=b then
                r=b
        end
        if cnt==n-1 && f==false then
                r=2
        end
        print r
        print " "
        b=i
        cnt+=1
}

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

if a.max > 1
  i = a.index a.max
  a[i] = 1
else
  a[0] = 2
end

print a.sort * " "

n=gets.to_i
a=gets.split.map(&:to_i).sort.unshift(1)
puts a.last==1 ? ("1 "*(n-1))+"2" : a.take(n)*" "

#=================================
require 'prime'
require 'set'
require 'matrix'
require 'tsort'
include Math

if ARGV.include?("ONLINE_JUDGE")
	$stdin = File.open("./input.txt", "r")
	ARGV.delete("ONLINE_JUDGE")
end
#=================================

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

data.sort!

if data[-1]!=1
	data[-1]=1
else
	data[-1]=2
end
data.sort!

data.each{|v| print "#{v} "}

n = gets
p = gets
=begin

from = Array.new(n.to_i)
to = p.split(' ')
i = 1
for el in to
  from[el.to_i-1] = i
  i+=1
end
puts from.join(' ').chomp
=end

arr1 = p.chomp.split(' ')
arr2 = []
arr1 = arr1.each{|el| arr2 << el.to_i}
arr1 = arr2.sort
max = arr1[-1]
if max == 1
  puts  arr1[0..-2].join(' ').chomp+" 2"
else
  puts "1 " + arr1.sort[0..-2].join(' ')
end

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

a[-1] = (a[-1]==1) ? 2 : 1

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

n = gets.to_i
a = gets.split.collect{|i| i.to_i}
a = a.sort
if a.pop != 1
    puts ([1]+a).join(" ")
else
    puts (a+[2]).join(" ")
end

n=gets.to_i
a=gets.split.map(&:to_i)
a.sort
b=1
f=false
a.each{|i|
        if i!=1 then
                f=true
        end
}
cnt=0
a.each{|i|
        r=i
        if i!=b then
                r=b
        end
        if cnt==n-1 && f==false then
                r=2
        end
        p r
        b=i
        cnt+=1
}

n=gets.to_i
a=gets.split.map(&:to_i)
a.sort
b=1
f=false
a.each{|i|
        if a[0]!=1 then
                f=true
        end
}
cnt=0
a.each{|i|
        r=i
        if i!=b then
                r=b
        end
        if cnt==n-1 && f==false then
                r=2
        end
        p r
        b=i
}

n=gets.to_i
a=gets.split.map(&:to_i)
a.sort
b=1
f=false
a.each{|i|
        if i!=1 then
                f=true
        end
}
cnt=0
a.each{|i|
        r=i
        if i!=b then
                r=b
        end
        if cnt==n-1 && f==false then
                r=2
        end
        print r
        print " "
        b=i
        cnt+=1
}

n=gets.to_i
a=gets.split.map(&:to_i)
a.sort
b=1
a.each{|i|
        r=i
        if i!=b then
                r=b
        end
        p r
        b=i
}

gets()
a = gets().split(' ').map(&:to_i).sort()
if a[-1] == 1 then
  a[-1] = 2
else
  a[0] = 1
end

puts a.join(' ')

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

if a[-1] == 1
    a[-1] = 2
else
    a[-1] = 1
    a.sort!
end

puts a.join(' ')

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

a[-1] = (a[-1]==1) ? 2 : 1

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

n = gets.to_i
a = gets.split.collect{|i| i.to_i}
a = [1]+a.sort
a.pop
puts a.join(" ")

a = STDIN.readlines[1].split.map(&:to_i).sort
a[-1] = 1
puts a.sort.join ' '

#!/usr/bin/ruby

def readNextValues
  return gets.chomp.split.collect {|x| x.to_i }
end

n = readNextValues
arr = readNextValues

max_i = 0
max_val = 0
for i in 0..arr.size-1
  if arr[i] > max_i
    max_i = i
    max_val = arr[i]
  end
end

if max_val == 1
  arr[max_i] = 2
else
  arr[max_i] = 1
end

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

#!/usr/bin/ruby

def readNextValues
  return gets.chomp.split.collect {|x| x.to_i }
end

n = readNextValues
arr = readNextValues

max_i = 0
max_val = 0
for i in 0..arr.size-1
  if arr[i] > max_i
    max_i = i
    max_val = arr[i]
  end
end

if max_val == 1
  arr[i] = 2
else
  arr[i] = 1
end

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

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

if a.max > 1
  i = a.index a.max
  a[i] = 1
end

print a.sort * " "

#=================================
require 'prime'
require 'set'
require 'matrix'
require 'tsort'
include Math

if ARGV.include?("ONLINE_JUDGE")
	$stdin = File.open("./input.txt", "r")
	ARGV.delete("ONLINE_JUDGE")
end
#=================================

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

data.sort!
data[-1]=1
data.sort!

data.each{|v| print "#{v} "}

n = gets
p = gets
=begin

from = Array.new(n.to_i)
to = p.split(' ')
i = 1
for el in to
  from[el.to_i-1] = i
  i+=1
end
puts from.join(' ').chomp
=end

arr1 = p.chomp.split(' ')
arr1 = arr1.sort
max = arr1[-2]
if max == '1'
  puts  arr1[0..-2].join(' ').chomp+" 2"
else
  puts "1 " + arr1.sort[0..-2].join(' ')
end

n = gets
p = gets
arr1 = p.chomp.split(' ')
arr1 = arr1.sort
max = arr1[-2]
i=1
if max == 1
  i = 2
end
puts "#{i} " + arr1.sort[0..-2].join(' ')

n = gets
p = gets
=begin

from = Array.new(n.to_i)
to = p.split(' ')
i = 1
for el in to
  from[el.to_i-1] = i
  i+=1
end
puts from.join(' ').chomp
=end

arr1 = p.chomp.split(' ')
arr2 = []
arr1 = arr1.each{|el| arr2 << el.to_i}
arr1 = arr2.sort
max = arr1[-1]
if max == '1'
  puts  arr1[0..-2].join(' ').chomp+" 2"
else
  puts "1 " + arr1.sort[0..-2].join(' ')
end

n = gets
p = gets
arr1 = p.chomp.split(' ')
puts '1 ' + arr1.sort[0..-1].join(' ')

n = gets
p = gets
=begin

from = Array.new(n.to_i)
to = p.split(' ')
i = 1
for el in to
  from[el.to_i-1] = i
  i+=1
end
puts from.join(' ').chomp
=end

arr1 = p.chomp.split(' ')
arr1 = arr1.sort
max = arr1[-1]
if max == '1'
  puts  arr1[0..-2].join(' ').chomp+" 2"
else
  puts "1 " + arr1.sort[0..-2].join(' ')
end

n = gets
p = gets
arr1 = p.chomp.split(' ')
puts '1 ' + arr1.sort[0..-2].join(' ')

n = gets
p = gets
=begin

from = Array.new(n.to_i)
to = p.split(' ')
i = 1
for el in to
  from[el.to_i-1] = i
  i+=1
end
puts from.join(' ').chomp
=end

arr1 = p.chomp.split(' ')
arr1 = arr1.sort
max = arr1[-1]
puts max
if max == '1'
  puts  arr1[0..-2].join(' ').chomp+" 2"
else
  puts "1 " + arr1.sort[0..-2].join(' ')
end

n = gets
p = gets
arr1 = p.chomp.split(' ')
arr1 = arr1.sort
max = arr1[-2]
if max == 1
  puts  arr1.sort[0..-2].join(' ')+" 2"
else
  puts "1 " + arr1.sort[0..-2].join(' ')
end

n=gets.to_i
puts ("1 "+gets).split.map(&:to_i).sort.take(n)*" "


a, b, c = gets.split.map(&:to_i)
if a == 0
	if b == 0
		puts c == 0 ? -1 : 0
	else
		puts 1
		puts "%.10f" % (-1.0 * c / b)
	end
else
	d = b * b - 4 * a * c
	if d < 0
		puts 0
	elsif d == 0
		puts 1
		puts "%.10f" % (-b / (2.0 * a))
	else
		dd = Math.sqrt(d)
		puts 2
		[(-b - dd) / (2.0 * a), (-b + dd) / (2.0 * a)].sort.each { |v| puts "%.10f" % v }
	end
end

input=gets.split.map(&:to_i)
a=input[0]
b=input[1]
c=input[2]
if a<0 then
        b=-b
        c=-c
        a=-a
end
d=b*b-4*a*c
if a==0 then
        if b==0 then
                if c==0 then
                        puts -1
                else
                        puts 0
                end
        else
                puts 1
                printf "%.7f\n",-c*1.0/b
        end
elsif d==0 then
        puts 1
        printf "%.7f\n",-b/(2*a)
elsif d>0 then
        puts 2
        printf "%.7f\n",(-b-Math::sqrt(d))/(2*a)
        printf "%.7f\n",(-b+Math::sqrt(d))/(2*a)
else
        puts 0
end

(a,b,c)=gets.split.map{|i|i=i.to_i}
if a==0
  if b==0 then puts c==0?"-1":"0";exit end
  puts "1";p -c.to_f/b;exit
end
if (d=b*b-4*a*c)<0 then puts "0";exit end
if d==0 then puts "1";p -b.to_f/2/a;exit end
puts "2"
if a<0 then a=-a;b=-b;c=-c end
p (-b-Math.sqrt(d))/2/a,(-b+Math.sqrt(d))/2/a

def printAns(num)
  printf("%10.10f\n",num)
end
c=gets.chomp.split.map{|i| i.to_i}
if c[0]==0
  if c[1]==0
    if c[2]==0
      puts(-1)
    else
      puts(0)
    end
  else
    puts(1)
    printAns(-c[2].to_f/c[1].to_f)
  end
else
  D=c[1]*c[1]-4*c[0]*c[2]
  if D<0
    puts(0)
    exit
  elsif D==0
    puts(1)
    ans=-c[1].to_f/(2.0*c[0].to_f)
    printAns(ans)
  else
    puts(2)
    r=Math.sqrt(D)
    if c[0] < 0
      c[0]=-c[0]
      c[1]=-c[1]
    end
    printAns((-c[1].to_f-r)/(2*c[0]))
    printAns((-c[1].to_f+r)/(2*c[0]))
  end
end

def printAns(num)
  printf("%10.10f\n",num)
end
(a,b,c)=gets.chomp.split.map{|i| i.to_i}
if a==0
  if b==0
    if c==0
      puts(-1)
    else
      puts(0)
    end
  else
    puts(1)
    printAns(-c.to_f/b.to_f)
  end
else
  D=b*b-4*a*c
  if D<0
    puts(0)
    exit
  elsif D==0
    puts(1)
    ans=-b.to_f/(2.0*a.to_f)
    printAns(ans)
  else
    puts(2)
    r=Math.sqrt(D)
    if a < 0
      a=-a
      b=-b
    end
    printAns((-b.to_f-r)/(2*a))
    printAns((-b.to_f+r)/(2*a))
  end
end

(a,b,c)=gets.split.map{|i|i=i.to_i}
if a==0&&b==0 then puts c==0?"-1":"0";exit end
if a==0
  puts "1"
  printf "%.9f\n", -c.to_f/b
  exit
end
if (d=b*b-4*a*c)<0 then puts "0";exit end
if d==0
  puts "1"
  printf "%.9f\n", -b.to_f/2/a
  exit
end
puts "2"
if a<0 then a=-a;b=-b;c=-c end
printf "%.9f\n", (-b-Math.sqrt(d))/2/a
printf "%.9f\n", (-b+Math.sqrt(d))/2/a

(a,b,c)=gets.split.map{|i|i=i.to_i}
if a==0&&b==0 then puts c==0?"-1":"0";exit end
if a==0
  puts "1"
  printf "%.9f\n", -c.to_f/b
  exit
end
if (d=b*b-4*a*c)<0 then puts "0";exit end
if d==0
  puts "1"
  printf "%.9f\n", -b.to_f/2/a
  exit
end
puts "2"
if a<0 then a=-a;b=-b;c=-c end
p (-b-Math.sqrt(d))/2/a
p (-b+Math.sqrt(d))/2/a

(a,b,c)=gets.split.map{|i|i=i.to_i}
if a==0&&b==0 then puts c==0?"-1":"0";exit end
if a==0
  puts "1"
  printf "%.9f\n", -b.to_f/c
  exit
end
if (d=b*b-4*a*c)<0 then puts "0";exit end
if d==0
  puts "1"
  printf "%.9f\n", -b.to_f/2/a
  exit
end
puts "2"
if a<0 then a=-a;b=-b;c=-c end
printf "%.9f\n", (-b-Math.sqrt(d))/2/a
printf "%.9f\n", (-b+Math.sqrt(d))/2/a

(a,b,c)=gets.split.map{|i|i=i.to_i}
if a==0&&b==0 then puts c==0?"-1":"0";exit end
if a==0
  puts "1"
  p -b.to_f/c
  exit
end
if (d=b*b-4*a*c)<0 then puts "0";exit end
if d==0
  puts "1"
  p -b.to_f/2/a
  exit
end
puts "2"
p (-b+Math.sqrt(d))/2/a
p (-b-Math.sqrt(d))/2/a

(a,b,c)=gets.split.map{|i|i=i.to_i}
if a==0&&b==0 then puts c==0?"-1":"0";exit end
if a==0
  puts "1"
  printf "%.9f\n", -b.to_f/c
  exit
end
if (d=b*b-4*a*c)<0 then puts "0";exit end
if d==0
  puts "1"
  printf "%.9f\n", -b.to_f/2/a
  exit
end
puts "2"
printf "%.9f\n", (-b-Math.sqrt(d))/2/a
printf "%.9f\n", (-b+Math.sqrt(d))/2/a

(a,b,c)=gets.split.map{|i|i=i.to_i}
if a==0&&b==0 then puts c==0?"-1":"0";exit end
if a==0
  puts "1"
  printf "%.9f\n", -b.to_f/c
  exit
end
if (d=b*b-4*a*c)<0 then puts "0";exit end
if d==0
  puts "1"
  printf "%.9f\n", -b.to_f/2/a
  exit
end
puts "2"
printf "%.9f\n", (-b+Math.sqrt(d))/2/a
printf "%.9f\n", (-b-Math.sqrt(d))/2/a

input=gets.split.map(&:to_i)
a=input[0]
b=input[1]
c=input[2]
d=b*b-4*a*c
if d==0 then
        puts 1
        printf "%.7f\n",-b/(2*a)
elsif d>0 then
        puts 2
        printf "%.7f\n",(-b-Math::sqrt(d))/(2*a)
        printf "%.7f\n",(-b+Math::sqrt(d))/(2*a)
else
        puts 0
end

input=gets.split.map(&:to_i)
a=input[0]
b=input[1]
c=input[2]
if a<0 then
        b=-b
        c=-c
        a=-c
end
d=b*b-4*a*c
if a==0 then
        if b==0 then
                if c==0 then
                        puts -1
                else
                        puts 0
                end
        else
                puts 1
                printf "%.7f\n",-c*1.0/b
        end
elsif d==0 then
        puts 1
        printf "%.7f\n",-b/(2*a)
elsif d>0 then
        puts 2
        printf "%.7f\n",(-b-Math::sqrt(d))/(2*a)
        printf "%.7f\n",(-b+Math::sqrt(d))/(2*a)
else
        puts 0
end

input=gets.split.map(&:to_i)
a=input[0]
b=input[1]
c=input[2]
d=b*b-4*a*c
if a==0 then
        if b==0 then
                if c==0 then
                        puts -1
                else
                        puts 0
                end
        else
                puts 1
                printf "%.7f\n",-c*1.0/b
        end
elsif d==0 then
        puts 1
        printf "%.7f\n",-b/(2*a)
elsif d>0 then
        puts 2
        printf "%.7f\n",(-b-Math::sqrt(d))/(2*a)
        printf "%.7f\n",(-b+Math::sqrt(d))/(2*a)
else
        puts 0
end

input=gets.split.map(&:to_i)
a=input[0]
b=input[1]
c=input[2]
d=b*b-4*a*c
if a==0 then
        puts 1
        printf "%.7f\n",-c*1.0/b
elsif d==0 then
        puts 1
        printf "%.7f\n",-b/(2*a)
elsif d>0 then
        puts 2
        printf "%.7f\n",(-b-Math::sqrt(d))/(2*a)
        printf "%.7f\n",(-b+Math::sqrt(d))/(2*a)
else
        puts 0
end

def printAns(num)
  printf("%10.10f\n",num)
end
c=gets.chomp.split.map{|i| i.to_i}
if c[0]==0
  if c[1]==0
    if c[2]==0
      puts(-1)
    else
      puts(0)
    end
  else
    puts(1)
    printAns(-c[2].to_f/c[1].to_f)
  end
else
  D=c[1]*c[1]-4*c[0]*c[2]
  if D<0
    puts(0)
    exit
  elsif D==0
    puts(1)
    ans=-c[1]/(2*c[0])
    printAns(ans)
  else
    puts(2)
    r=Math.sqrt(D)
    printAns((-c[1]-r)/(2*c[0]))
    printAns((-c[1]+r)/(2*c[0]))
  end
end

def printAns(num)
  printf("%10.10f\n",num)
end
c=gets.chomp.split.map{|i| i.to_i}
if c[0]==0
  if c[1]==0
    if c[2]==0
      puts(-1)
    else
      puts(0)
    end
  else
    puts(1)
    printAns(-c[2]/c[1])
  end
else
  D=c[1]*c[1]-4*c[0]*c[2]
  if D<0
    puts(0)
    exit
  elsif D==0
    puts(1)
    ans=-c[1]/(2*c[0])
    printAns(ans)
  else
    puts(2)
    r=Math.sqrt(D)
    printAns((-c[1]-r)/(2*c[0]))
    printAns((-c[1]+r)/(2*c[0]))
  end
end

def printAns(num)
  printf("%10.10f\n",num)
end
c=gets.chomp.split.map{|i| i.to_i}
if c[0]==0
  if c[1]==0
    if c[2]==0
      puts(-1)
    else
      puts(0)
    end
  else
    puts(1)
    printAns(-c[2].to_f/c[1].to_f)
  end
else
  D=c[1]*c[1]-4*c[0]*c[2]
  if D<0
    puts(0)
    exit
  elsif D==0
    puts(1)
    ans=-c[1].to_f/(2.0*c[0].to_f)
    printAns(ans)
  else
    puts(2)
    r=Math.sqrt(D)
    printAns((-c[1].to_f-r)/(2*c[0]))
    printAns((-c[1].to_f+r)/(2*c[0]))
  end
end

def printAns(num)
  printf("%10.10f\n",num)
end
c=gets.chomp.split.map{|i| i.to_i}
if c[0]==0
  if c[1]==0
    if c[2]==0
      puts(-1)
    else
      puts(0)
    end
  else
    puts(1)
    printAns(-c[2].to_f/c[1].to_f)
  end
else
  D=c[1]*c[1]-4*c[0]*c[2]
  if D<0
    puts(0)
    exit
  elsif D==0
    puts(1)
    ans=-c[1].to_f/(2*c[0].to_f)
    printAns(ans)
  else
    puts(2)
    r=Math.sqrt(D)
    printAns((-c[1]-r)/(2*c[0]))
    printAns((-c[1]+r)/(2*c[0]))
  end
end

def printAns(num)
  printf("%10.10f\n",num)
end
c=gets.chomp.split.map{|i| i.to_i}
if c[0]==0
  if c[1]==0
    if c[2]==0
      puts(-1)
    else
      puts(0)
    end
  else
    puts(1)
    printAns(c[2]/c[1])
  end
else
  D=c[1]*c[1]-4*c[0]*c[2]
  if D<0
    puts(0)
    exit
  elsif D==0
    puts(1)
    ans=-c[1]/(2*c[0])
    printAns(ans)
  else
    puts(2)
    r=Math.sqrt(D)
    printAns((-c[1]-r)/(2*c[0]))
    printAns((-c[1]+r)/(2*c[0]))
  end
end

def printAns(num)
  printf("%10.10f\n",num)
end
c=gets.chomp.split.map{|i| i.to_i}
if c[0]==0
  if c[1]==0
    if c[2]==0
      puts(-1)
    else
      puts(0)
    end
  else
    puts(1)
    printAns(c[2]/c[1])
  end
else
  D=c[1]*c[1]-4*c[0]*c[2]
  if D<0
    puts(0)
    exit
  elsif D==0
    puts(1)
    ans=-c[1]/(2*c[0])
    printAns(ans)
  else
    puts(2)
    r=Math.sqrt(D)
    printAns((-c[1]+r)/(2*c[0]))
    printAns((-c[1]-r)/(2*c[0]))
  end
end

a, b, c = gets.split.map(&:to_i)
if a == 0
	if b == 0
		puts c == 0 ? -1 : 0
	else
		puts 1
		puts "%.10f" % (-c / b)
	end
else
	d = b * b - 4 * a * c
	if d < 0
		puts 0
	elsif d == 0
		puts 1
		puts "%.10f" % (-b / (2 * a))
	else
		dd = Math.sqrt(d)
		puts 2
		[(-b - dd) / (2 * a), (-b + dd) / (2 * a)].sort.each { |v| puts "%.10f" % v }
	end
end

a, b, c = gets.split.map(&:to_i)
if a == 0
	if b == 0
		puts c == 0 ? -1 : 0
	else
		puts 1
		puts -c / b
	end
else
	d = b * b - 4 * a * c
	if d < 0
		puts 0
	elsif d == 0
		puts 1
		puts -b / (2 * a)
	else
		dd = Math.sqrt(d)
		puts 2
		puts [(-b - dd) / (2 * a), (-b + dd) / (2 * a)].sort
	end
end


n = gets.chomp.to_i

def sol_win(n, k, win)
	round = n / 3
	ok = true
	win.each do |i|
		ok = false if i > round
	end
	ok
end

def sol_real(n, k, d1, d2)
	win = []
	if (k - (d1 + d2)) % 3 != 0
		return false
	else
		t = (k - (d1 + d2)) / 3
		if t >= 0 and t + d1 >= 0 and t + d2 >= 0
			win = [t + d1, t, t + d2]
			return sol_win(n, k, win)
		else
			return false
		end
	end
end

# use second team as t
def sol(n, k, d1, d2)
	if n % 3 != 0
		return false
	end
	sol_real(n, k, d1, d2) or sol_real(n, k, -d1, d2) or sol_real(n, k, d1, -d2) or sol_real(n, k, -d1, -d2)
end

n.times do
	n, k, d1, d2 = gets.chomp.split.map{|i| i.to_i}
	if sol(n, k, d1, d2)
		puts "yes"
	elsif
		puts "no"
	end
end


n = STDIN.gets.chomp.to_i
length = STDIN.gets.chomp.split(' ').map{|i| i.to_i}
arr = length.inject(Array.new(101).fill(0)) {|res, i| res[i] += 1; res}
puts arr.reduce(0){|tot, i| tot += (i / 2)} / 2

n=gets.to_i
a=gets.split.map(&:to_i)
cnt=Hash.new
cnt.default=0
a.each{|i| cnt[i]+=1 }
ans=0
1.upto(100){|i| ans+=cnt[i]/2 }
p ans/2

#!/usr/bin/env ruby

n = $stdin.readline().to_i

lens = ($stdin.readline().split().collect {|x| x.to_i})

def uniq(a)
	result = Array.new
	prev = nil
	count = 0
	a.sort.each { |x|
		if x != prev
			result << [prev, count] unless prev == nil
			prev = x
			count = 1
		else
			count += 1
		end
	}
	result << [prev, count]
end

pairs = 0

uniq(lens).each { |r|
	pairs += (r[1]/2).floor
}

puts (pairs/2).floor

n = STDIN.readline.to_i
sticks = STDIN.readline.split.map {|s| s.to_i }
count = {}
sticks.each do |stick|
  if count.include? stick
    count[stick] += 1
  else
    count[stick] = 1
  end
end
pairs = 0
count.values.each {|value| pairs += value/2 }
puts pairs/2

gets
d = {}
d.default = 0
gets.split().map(&:to_i).each{|e| d[e] += 1 }

ret = 0
d.each_value{ |e| ret += e/2 }

p ret / 2

s,n=0,(gets.to_i)
a=gets.split.map &:to_i
0.upto 101 do |i| s+=a.count(i)/2 end
puts s/2

n = gets.to_i
h = Hash.new(0)
gets.split.map(&:to_i).each { |x| h[x] += 1}
puts h.values.map { |x| x/2}.inject(:+) / 2

gets
hs=Hash.new(0)
data=gets.split.map(&:to_i).each{|v| hs[v]+=1}
puts hs.values.map{|_| _%2!=0 ?	_-1	: _ }.inject(:+)/4

n = gets.to_i
a = Array.new(101,0)
vs = gets.split.map(&:to_i)
vs.each do |v|
	a[v] += 1
end
ans = 0
for i in 1..100 do
    ans += (a[i].div(2))
end
p ans.div(2)

n = gets.to_i
a = Hash.new(0)
gets.split.each{|i| a[i]+=1}
cnt = 0
a.each{|key,value| cnt+=value/2}
puts cnt/2

gets
sticks = gets.split.map(&:to_i)
p sticks.uniq.inject(0) {|sumstick, _| sumstick += (sticks.count(_) / 2)}  / 2

gets
puts gets.split.map { |x| x.to_i }.inject(Hash.new(0)) { |h, e| h[e] += 1; h }.values.map { |x| x - x % 2 }.inject(:+) / 4

n = gets.to_i
a = gets().split.map { |elem| elem.to_i }

pairs_count = 0

for i in 1..(n-1)
  for j in 0..(i - 1)
    if (a[i] == a[j])
      a[i] = 0
      a[j] = 0
      pairs_count += 1
      break
    end
  end
end

puts (pairs_count / 2).to_i

n = gets.to_i
a = gets.chomp.split(" ").map{|i| i.to_i}
l = []
dem = 0

(0..n-1).each do |i|
    l[i] = 0
end

(0..n-2).each do |i|
    if l[i] == 0
        (i+1..n-1).each do |j|
            if a[i] == a[j] && l[j] == 0
                l[i] = 1
                l[j] = 1
                dem += 1
                break
            end
        end
    end
end

puts dem/2

gets
a, ans = Array.new(101,0), 0
gets.split.map{ |x| a[x.to_i] += 1 }
a.each{ |x| ans += x/2 }
p ans/2


n = gets.to_i
a = gets.split.map &:to_i
ans = 0
nnegatives = 0
nzeros = 0
a.each do |x|
  if x >= 1
    ans += x - 1
  elsif x <= -1
    ans += -1 - x
    nnegatives += 1
  else
    ans += 1
    nzeros += 1
  end
end
ans += 2 if nnegatives%2 != 0 and nzeros == 0
puts ans

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

ans = 0
neg_c = 0
zero_c = 0
a.each do |v|
  if v < 0
    neg_c += 1
  elsif v == 0
    zero_c += 1
  end

  ans += (v.abs-1).abs
end

if neg_c.odd? && zero_c == 0
  ans += 2
end

puts ans

n = gets.to_i
sum = 0
negOne = 0
posOne = 0
zero = 0
arr = gets.split.map(&:to_i)
arr.each_with_index do |x, i|
    if x < 0
        sum += (x - (-1)).abs
        arr[i] = -1
        negOne += 1
    elsif x > 0
        sum += (x - 1).abs
        arr[i] = 1
        posOne += 1
    else
        zero += 1
    end
end
if negOne %2 != 0
    if zero > 0
        sum += 1
        negOne += 1
        zero -= 1
    else
        sum += 2
        negOne -= 1
        posOne += 1
    end
end
print(sum + zero)

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

negative_count = as.count { |a| a < 0 }
zero_count = as.count { |a| a == 0 }

ans = 0
as.each do |a|
  ans += [(a-(-1)).abs, (a-1).abs].min
end
if negative_count.odd?
  if zero_count > 0
  else
    ans += 2
  end
end

puts ans

# coding: utf-8

# if __FILE__ == $0
# end

n = gets.to_i
a = gets.split.map(&:to_i)
coins = 0
negs, zeroes, poss = 0, 0, 0
a.each { |i|
    if i < 0
        negs += 1
        coins += -1 - i
    elsif i == 0
        zeroes += 1
    else
        poss += 1
        coins += i - 1
    end
}

# not handled zeroes yet!
if negs.odd?
    if zeroes > 0
        zeroes -= 1
        coins += 1 # for zeroes, flipping to -1 or +1 only costs one coin
    else
        coins += 2 # have to pay two coins to flip -1 to +1 or +1 to -1
    end
end

# handle remaining zeroes
coins += zeroes

puts coins

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

cost = 0
plus_sum = 0
minus_sum = 0
plus_cnt = 0
minus_cnt = 0
zero_cnt = 0

aa.each do |a|
  if a<0
    minus_cnt+=1
    minus_sum+=a
  elsif a==0
    zero_cnt+=1
  else
    plus_cnt+=1
    plus_sum+=a
  end
end

cost += (-minus_sum - minus_cnt) + zero_cnt + (plus_sum - plus_cnt)
# マイナスが奇数個の場合はプラスになるように調整する
cost += 2 if minus_cnt%2==1 && zero_cnt==0
puts cost

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

negative_count = as.count { |a| a < 0 }
zero_count = as.count { |a| a == 0 }

ans = 0
as.each do |a|
  ans += [(a-(-1)).abs, (a-1).abs].min
end
if negative_count.odd?
  if zero_count > 0
    ans += 1
  else
    ans += 2
  end
end

puts ans

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

negative_count = as.count { |a| a < 0 }

ans = 0
as.each do |a|
  ans += [(a-(-1)).abs, (a-1).abs].min
end
if negative_count.odd?
  ans += 2
end

puts ans

# coding: utf-8

# if __FILE__ == $0
# end

n = gets.to_i
a = gets.split.map(&:to_i)
coins = 0
negs = 0
min_spent = 10**9 + 1
a.sort.each { |i|
    pending_coins = 0 # keep positive!
    if i < 0
        negs += 1
        pending_coins = -1 - i
    else
        if i == 0
            pending_coins = 1
        else
            pending_coins = i - 1
        end
    end

    coins += pending_coins
    if pending_coins < min_spent
        min_spent = pending_coins
    end
}

if negs.odd?
    if min_spent == 0 # is +1 or -1
        coins += 2
    elsif min_spent == 1 # is zero
        coins += 1
    else
        coins += 2
    end
end

puts coins

n = gets.to_i
a = gets.split.map &:to_i
ans = 0
nnegatives = 0
a.each do |x|
  if x >= 1
    ans += x - 1
  elsif x <= -1
    ans += -1 - x
    nnegatives += 1
  else
    ans += 1
  end
end
ans += 2 if nnegatives%2 != 0
puts ans


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

arr = []
h = Hash.new
(1..n).each { |e|
  arr << gets.strip
  h[arr.last] = 1 if arr.include?(arr.last.reverse) && arr.last != arr.last.reverse
  h[arr.last] = 0 if arr.last == arr.last.reverse
}

an = []
h.each { |k, v|
  if v.zero?
    an << k
    break
  end
}
h.each { |k, v|
  if v == 1
    an.unshift(k)
    an << k.reverse
  end
}

s = ""
an.each { |e| s += e }
puts s.size
puts s

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

strs = []

n.times do
  strs << gets.strip
end

if n == 1
  unless strs[0] == strs[0].reverse
    puts 0
    exit
  end
  puts m
  puts strs[0]
  exit
end

palindroms = {}
palindroms_indexes = []
middle_word = ""

strs.each_with_index do |s, i|
  cur_pal = s.reverse
  p_count = 0
  next if palindroms.keys.include?(s) || palindroms.keys.include?(cur_pal)

  p_hash = {
    similar_count: 1,
    p_count: 0
  }
  strs.each_with_index.map do |ss, ii|
    next if ii == i

    if ss == cur_pal
      p_hash[:p_count] += 1
    else
      if ss == s
        p_hash[:similar_count] += 1
      end
    end
  end

  p_count = if p_hash[:p_count] != p_hash[:similar_count]
    if s == cur_pal
      identical = p_hash[:p_count] + 1
      if identical % 2 == 0
        identical/2
      else
        if s.length > middle_word.length
          middle_word = s
        end
        p_hash[:p_count]/2
      end
    else
      [p_hash[:p_count], p_hash[:similar_count]].min
    end
  else
    p_hash[:p_count]
  end

  if p_count == 0
    if s == cur_pal && s.length > middle_word.length
      middle_word = s
    end
  end

  palindroms[s] = p_count
end

str_begin = ""
str_end = ""
palindroms.each do |k, v|
  v.times do
    str_begin += k
    str_end = k.reverse + str_end
  end
end

pal = str_begin + middle_word + str_end
if pal.empty?
  puts 0
else
  puts pal.length
  puts pal
end

# frozen_string_literal: true

@data = $stdin.read.split

def next_token
  @data.shift
end

def next_int
  next_token.to_i
end

n = next_int
m = next_int
s = n.times.map { next_token }

res = 0
left = String.new
outlier = ''
n.times do |i|
  found = false
  (0...i).each do |j|
    next unless s[i] == s[j].reverse

    found = true
    left << s[i]
    res += 1
  end
  next if found

  outlier = s[i] if s[i] == s[i].reverse
end

res = left + outlier + left.reverse
puts res.size
puts res

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

strs = []

n.times do
  strs << gets.strip
end

if n == 1
  unless strs[0] == strs[0].reverse
    puts 0
    exit
  end
  puts n
  puts strs[0]
  exit
end

palindroms = {}
palindroms_indexes = []
middle_word = ""

strs.each_with_index do |s, i|
  cur_pal = s.reverse
  p_count = 0
  next if palindroms.keys.include?(s) || palindroms.keys.include?(cur_pal)

  p_hash = {
    similar_count: 1,
    p_count: 0
  }
  strs.each_with_index.map do |ss, ii|
    next if ii == i

    if ss == cur_pal
      p_hash[:p_count] += 1
    else
      if ss == s
        p_hash[:similar_count] += 1
      end
    end
  end

  p_count = if p_hash[:p_count] != p_hash[:similar_count]
    if s == cur_pal
      identical = p_hash[:p_count] + 1
      if identical % 2 == 0
        identical/2
      else
        if s.length > middle_word.length
          middle_word = s
        end
        p_hash[:p_count]/2
      end
    else
      [p_hash[:p_count], p_hash[:similar_count]].min
    end
  else
    p_hash[:p_count]
  end

  if p_count == 0
    if s == cur_pal && s.length > middle_word.length
      middle_word = s
    end
  end

  palindroms[s] = p_count
end

str_begin = ""
str_end = ""
palindroms.each do |k, v|
  v.times do
    str_begin += k
    str_end = k.reverse + str_end
  end
end

pal = str_begin + middle_word + str_end
if pal.empty?
  puts 0
else
  puts pal.length
  puts pal
end

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

arr = []
(1..n).each { |e|
  arr << gets.strip
}

an = []
arr.each { |e|
  if arr.include?(e.reverse)
    an.unshift(e)
    an << e.reverse
    arr.delete(e.reverse)
  end
}

s = ""
an.each { |e| s += e }
puts s.size
puts s


SIZES = [ :S, :M, :L, :XL, :XXL ]
OFFSET = [ 0, +1, -1, +2, -2, +3, -3, +4, -4 ]

sizes = {}
gets.split.map { |v| v.to_i }.each_with_index { |how, index| sizes[SIZES[index]] = how }
gets.to_i.times do
  index = SIZES.find_index(gets.strip.to_sym)
  OFFSET.each do |offset|
    cur, size = index + offset, SIZES[index + offset]
   if (0 ... SIZES.size).include?(cur) and sizes[size] > 0
     sizes[size] -= 1
     puts size
     break
    end
  end
end

s = gets.chomp.split(" ")
mas = [s[0].to_i,s[1].to_i, s[2].to_i, s[3].to_i, s[4].to_i]
index = {"S" => 0, "M" => 1, "L" => 2, "XL" => 3, "XXL" => 4}
rindex = ["S","M","L","XL","XXL"]

n = gets.to_i
for i in 1..n
  s = gets.chomp!
  for j in 0..4
    if index[s] + j < 5 && mas[index[s] + j] > 0
      mas[index[s] + j] -= 1
      puts rindex[index[s] + j]
      break
    elsif index[s] - j >= 0 && mas[index[s] - j] > 0
      mas[index[s] - j] -= 1
      puts rindex[index[s] - j]
      break
    end
  end
end

$s=gets.split.map(&:to_i)
size=["S", "M", "L", "XL","XXL"]
def get(x)
        for u in 0..5
                if x+u<5 && $s[x+u]>0 then
                        $s[x+u]-=1
                        return x+u
                end
                if x-u>=0 && $s[x-u]>0 then
                        $s[x-u]-=1
                        return x-u
                end
        end
        return 0
end
k=gets.to_i
k.times{
        puts size[get(size.index(gets.split[0]))]
}

def f(n)
  l = [nil] * 5 + ['S','M','L','XL','XXL'] + [nil] * 5
  i = n+4
  r = []
  r << l[i]
  r << l[i+1]
  r << l[i-1]
  r << l[i+2]
  r << l[i-2]
  r << l[i+3]
  r << l[i-3]
  r << l[i+4]
  r << l[i-4]
  r << l[i+5]
  r << l[i-5]
  r.select {|e| e}
end

pr = []
l = ['S','M','L','XL','XXL']
1.upto(5) {|n| pr << f(n)}

a = gets.split(' ')
a = a.map{|e| e.to_i}

gets.to_i.times do
  size = gets.chomp
  tl = pr[l.index(size)]
  n = 0
  while a[l.index(tl[n])] == 0
    n += 1
  end
  a[l.index(tl[n])] -= 1
  puts tl[n]
end

def f(n)
  l = [nil] * 5 + ['S','M','L','XL','XXL'] + [nil] * 5
  i = n+5
  r = []
  r << l[i]
  r << l[i+1]
  r << l[i-1]
  r << l[i+2]
  r << l[i-2]
  r << l[i+3]
  r << l[i-3]
  r << l[i+4]
  r << l[i-4]
  r << l[i+5]
  r << l[i-5]
  r.select {|e| e}
end

pr = []
l = ['S','M','L','XL','XXL']
1.upto(5) {|n| pr << f(n)}

a = gets.split(' ')
a = a.map{|e| e.to_i}

gets.to_i.times do
  size = gets.chomp
  tl = pr[l.index(size)]
  n = 0
  while a[l.index(tl[n])] == 0
    n += 1
  end
  a[l.index(tl[n])] -= 1
  puts tl[n]
end

s = gets.chomp.split(" ")
mas = [s[0].to_i,s[1].to_i, s[2].to_i, s[3].to_i, s[4].to_i]
index = {"S" => 0, "M" => 1, "L" => 2, "XL" => 3, "XXL" => 4}
rindex = ["S","M","L","XL","XXL"]

n = gets.to_i
for i in 1..n
  s = gets.chomp!
  if mas[index[s]] > 0
    mas[index[s]] -= 1
    puts rindex[index[s]]
  elsif index[s] + 1 < 5 && mas[index[s] + 1] > 0
    mas[index[s] + 1] -= 1
    puts rindex[index[s] + 1]
  elsif index[s] - 1 >= 0 && mas[index[s] - 1] > 0
    mas[index[s] - 1] -= 1
    puts rindex[index[s] - 1]
  elsif index[s] + 2 < 5 && mas[index[s] + 2] > 0
    mas[index[s] + 2] -= 1
    puts rindex[index[s] + 2]
  elsif index[s] - 2 >= 0 && mas[index[s] -2] > 0
    mas[index[s] - 2] -= 1
    puts rindex[index[s] -2]
  end
end


# -*- coding: utf-8 -*-
#require 'awesome_print'

n, m = gets.split.map(&:to_i)
grid = []
n.times {|line|
  s = gets.chomp
  l = s.index 'W'
  r = s.rindex 'W'
  grid << [l, r, line]
}

def f(line, i, n, m, grid)
  cur_l, cur_r, _ = grid[line]
  below_l, below_r, next_i = grid[line+1...n].find { |_, x, _| ! x.nil? }
  count = 0
  if line.even?
    #右へ
    if !cur_r.nil?
      count += cur_r - i
      i = cur_r
    end
  else
    #左へ
    if !cur_l.nil?
      count += i - cur_l
      i = cur_l
    end
  end
  if ! below_r.nil?
    #下にいきます
    if next_i.even?
      #下の方も右
      count += i-below_l if below_l < i
      count += next_i - line + f(next_i, [below_l, i].min, n, m, grid)
    else
      #下は左
      count += below_r-i if i < below_r
      count += next_i - line + f(next_i, [below_r, i].max, n, m, grid)
    end
  end

  count
end
puts f(0, 0, n, m, grid)

n,m = gets.chomp.split(/ /).map!{|x| x.to_i}
a = Array.new(n)
idxs = Array.new(n)
ridxs = Array.new(n)
for i in 0..n-1
  a[i] = gets.chomp
  if i % 2 == 0
    idxs[i] = a[i].rindex("W")
    ridxs[i] = a[i].index("W")
  else
    idxs[i] = a[i].index("W")
    ridxs[i] = a[i].rindex("W")
  end
end
wcnt = 0
curcol = 0
endidx = -1
for i in 0..n-1
  break if idxs[n-1-i] != nil
  endidx = n-1-i
end
for i in 0..n-1
  if idxs[i] != nil
    wcnt += (curcol-idxs[i]).abs
    curcol = idxs[i]
  end
  break if endidx != -1 && i+1 >= endidx
  if i < n-1
    if ridxs[i+1] != nil
      if (i % 2 == 0 && ridxs[i+1] > curcol) || (i % 2 == 1 && ridxs[i+1] < curcol)
        wcnt += (curcol-ridxs[i+1]).abs
        curcol = ridxs[i+1]
      end
    end
    wcnt += 1
  end
end
puts wcnt

# -*- coding: utf-8 -*-
class P < Struct.new(:l, :r)

end
n, m = gets.split.map(&:to_i)
grid = []
n.times {|line|
  s = gets.chomp
  l = s.index 'W'
  r = s.rindex 'W'
  grid << [l, r, line]
}

def f(line, i, n, m, grid)
  cur_l, cur_r, _ = grid[line]
  below_l, below_r, next_i = grid[line+1...m].find { |_, x, _| ! x.nil? }
  count = 0
  if line.even?
    #右へ
    if !cur_r.nil?
      count += cur_r - i
      i = cur_r
    end
  else
    #左へ
    if !cur_l.nil?
      count += i - cur_l
      i = cur_l
    end
  end
  if ! below_r.nil?
    #下にいきます
    if next_i.even?
      #下の方も右
      count += i-below_l if below_l < i
      count += next_i - line + f(next_i, [below_l, i].min, n, m, grid)
    else
      #下は左
      count += below_r-i if i < below_r
      count += next_i - line + f(next_i, [below_r, i].max, n, m, grid)
    end
  end

  count
end
puts f(0, 0, n, m, grid)

n,m = gets.chomp.split(/ /).map!{|x| x.to_i}
a = Array.new(n)
idxs = Array.new(n)
for i in 0..n-1
  a[i] = gets.chomp
  if i % 2 == 0
    idxs[i] = a[i].rindex("W")
  else
    idxs[i] = a[i].index("W")
  end
end
wcnt = 0
curcol = 0
for i in 0..n-1
  if idxs[i] != nil
    wcnt += (curcol-idxs[i]).abs
    curcol = idxs[i]
  end
  if i < n-1
    if idxs[i+1] != nil
      if (i % 2 == 0 && idxs[i+1] > curcol) || (i % 2 == 1 && idxs[i+1] < curcol)
        wcnt += (curcol-idxs[i+1]).abs
        curcol = idxs[i+1]
      end
    end
    wcnt += 1
  end
end
puts wcnt

n,m = gets.chomp.split(/ /).map!{|x| x.to_i}
a = Array.new(n)
idxs = Array.new(n)
ridxs = Array.new(n)
for i in 0..n-1
  a[i] = gets.chomp
  if i % 2 == 0
    idxs[i] = a[i].rindex("W")
    ridxs[i] = a[i].index("W")
  else
    idxs[i] = a[i].index("W")
    ridxs[i] = a[i].rindex("W")
  end
end
wcnt = 0
curcol = 0
for i in 0..n-1
  if idxs[i] != nil
    wcnt += (curcol-idxs[i]).abs
    curcol = idxs[i]
  end
  if i < n-1
    if ridxs[i+1] != nil
      if (i % 2 == 0 && ridxs[i+1] > curcol) || (i % 2 == 1 && ridxs[i+1] < curcol)
        wcnt += (curcol-ridxs[i+1]).abs
        curcol = ridxs[i+1]
      end
    end
    wcnt += 1
  end
end
puts wcnt


#!/usr/bin/ruby
gets
s=0
puts gets.split.map(&:to_i).reverse.map{|e|
	r=[s+1-e,0].max
	s=[s,e].max
	r
}.reverse*' '

n, h = gets.chomp.to_i, gets.chomp.split(" ").map(&:to_i)
a, max_on_the_right, index_of_max_on_the_right =
	 [] << 0, h[n-1], n-1

(n-2).downto 0 do |i|
	if max_on_the_right >= h[i]
		a.unshift(max_on_the_right - h[i] + 1)
	else
		a.unshift 0
		max_on_the_right = h[i]
	end
end

puts a.join " "

n, h = gets.chomp.to_i, gets.chomp.split(" ").map(&:to_i)
a, max_on_the_right = [] << 0, h[n-1]

(n-2).downto 0 do |i|
	if max_on_the_right >= h[i]
		a.unshift(max_on_the_right - h[i] + 1)
	else
		a.unshift 0
		max_on_the_right = h[i]
	end
end

puts a.join " "

n = gets.chomp.to_i;
arr = gets.chomp.split.map(&:to_i);
max = arr[n - 1];
ans = [];
(n-2).downto(0) {|i|
  ans[i] = [max + 1 - arr[i], 0].max;
  max = [max, arr[i]].max;
}
ans[n - 1] = 0;
print ans.join(' ');

n = gets.to_i
h = gets.split.map(&:to_i)
m, a = [0] * (n - 1) + [h[n - 1]], [0] * n
(n - 2).downto(0) do |i|
  if h[i] <= m[i + 1]
    m[i] = m[i + 1]
    a[i] = m[i] - h[i] + 1
  else
    m[i] = h[i]
  end
end
puts a.join(' ')

gets
x=gets.split.map{|e| e.to_i}.reverse
ans=[]
x.inject(0){|m,e|
	if m>=e then
		ans<<(m-e+1)
	else
		ans<<0
	end
	[m,e].max
}
puts ans.reverse*" "

n = gets.to_i
arr = gets.chomp.split(/ /).map(&:to_i)
arr_fin = Array.new
index=n-1
max_l = 0
loop do
	break if index<0
	if arr[index] > max_l
		arr_fin.unshift(0)
		max_l = arr[index]
	else
		arr_fin.unshift(-arr[index]+max_l+1)
	end
	index-=1
end
arr_fin.each_index{ |e|
	if(e!=n-1)
		print "#{arr_fin[e]} "
	else
		print "#{arr_fin[e]}"
	end
}

# читаем первую строку, но нигде не используем
count = STDIN.gets.to_i
# количество этажей в последнем элитном доме
last_elite_floors = 0
input = STDIN.gets
# массив - количество этажей в каждом доме
floors = input.split.map(&:to_i)
# т.к. не знаю как в ruby делать проход
# от последнего элемента к первому
# - просто два раза инвертирую массив
# это первый раз
reverse = floors.reverse
reverse_result = Array.new
reverse.each do |item|
  if item > last_elite_floors
    # если у нас элитный дом - запомнаем количество этажей в нём
    last_elite_floors = item
    reverse_result.push(0)
  elsif item == last_elite_floors
    # если количество этажей такое же как у последнего элитного дома
    # значит нужно достроить всего один этаж
    reverse_result.push(1)
  else
    reverse_result.push(last_elite_floors - item + 1)
  end
end
# тут инвертируем массив второй раз
puts "#{reverse_result.reverse.join(' ')}"

n = gets.to_i
a = gets.split.map(&:to_i)
right_max, ans = 0, []
(n - 1).downto(0) do |i|
  ans << [right_max + 1 - a[i], 0].max
  right_max = [right_max, a[i]].max
end
puts ans.reverse.join(' ')

n = gets.to_i
a = gets.split.map(&:to_i)
right_max, ans = 0, [0]
(n - 1).downto(1) do |i|
  right_max = [right_max, a[i]].max
  ans << [right_max + 1 - a[i - 1], 0].max
end
puts ans.reverse.join(' ')

n, h, a, max_on_the_right, index_of_max_on_the_right =
	gets.chomp.to_i, gets.chomp.split(" ").map(&:to_i), [], 0, 0
h.each_with_index do |e,i|
	break if i == n-1
	if i == index_of_max_on_the_right
		max_on_the_right = h[i+1]
		(i+2).upto (n-1) do |ind|
			if h[ind] > max_on_the_right
				max_on_the_right = h[ind]
				index_of_max_on_the_right = ind
			end
		end
	end

	a << if (max_on_the_right - e) < 1
		0
	else
		(max_on_the_right - e + 1)
	end
end
a << 0
puts a.join " "

n, h = gets.chomp.to_i, gets.chomp.split(" ").map(&:to_i)
a, max_on_the_right, index_of_max_on_the_right =
	 [] << 0, h[n-1], n-1

(n-2).downto 0 do |i|
	if max_on_the_right > h[i]
		a.unshift(max_on_the_right - h[i] + 1)
	else
		a.unshift 0
		max_on_the_right = h[i]
	end
end

puts a.join " "

n = gets.chomp.to_i;
arr = gets.chomp.split.map(&:to_i).reverse;
max = arr[0];
ans = "0";
(1...n).each {|i|
  ans << " #{max + 1 - arr[i]}";
  max = [max, arr[i]].max;
}
print ans.reverse + "\n";

# читаем первую строку, но нигде не используем
count = STDIN.gets.to_i
# количество этажей в последнем элитном доме
last_elite_floors = 0
input = STDIN.gets
# массив - количество этажей в каждом доме
floors = input.split.map(&:to_i)
# т.к. не знаю как в ruby делать проход
# от последнего элемента к первому
# - просто два раза инвертирую массив
# это первый раз
reverse = floors.reverse
reverse_result = Array.new
reverse.each do |item|
  if item >= last_elite_floors
    last_elite_floors = item
    reverse_result.push(0)
  else
    reverse_result.push(last_elite_floors - item + 1)
  end
end
# тут инвертируем массив второй раз
puts "#{reverse_result.reverse.join(' ')}"


n,s = gets.split.map {|x| x.to_i}
m = n*n/2+(n % 2)
map = Array.new(n) {"S"*n}
if s <= m
  puts "YES"
  n.times do |y|
    offset = y % 2
    x = offset
    while (x < n) do
      break if s == 0
      map[y][x] = 'L'
      s -= 1
      x += 2
    end
    break if s == 0
  end
  map.each do |line|
    puts line
  end

else
  puts "NO"
end

n, k = gets.chomp.split("\s").map(&:to_i)
if n % 2 == 0
  if (n / 2) * n < k
    puts 'NO'
    exit
  end
else
  if (n / 2 + 1) ** 2 + (n / 2) ** 2  < k
    puts 'NO'
    exit
  end
end

puts 'YES'
count = 0
n.times do |i|
  n.times do |j|
    if count < k && i % 2 == 0 && j % 2 == 0
      count += 1
      print 'L'
    elsif count < k && i % 2 == 1 && j % 2 == 1
      count += 1
      print 'L'
    else
      print 'S'
    end
  end
  puts
end

n,@k=gets.split.map(&:to_i)
(puts :NO;exit)if @k > (n*n+1)/2
puts :YES
def ne
  ((@k-=1)<0)?'S':'L'
end

n.times do |i|
  n.times do |j|
    print (i+j)%2==0 ? ne : 'S'
  end
  puts
end

input = gets.chomp
input2 = input.split(" ")
n = input2[0].to_i
k = input2[1].to_i

if n % 2 == 1
  max = (n/2+1) ** 2 + (n/2) ** 2
else
  max = (n/2) * n
end

if max >= k
  puts "YES"
  (n**2).times do |num|

    if num % n == 0 && num != 0
      print "\n"
    end

    if  (num / n) % 2 == 0 || (n % 2 == 1)
      if num % 2 == 0 && k != 0
        print "L"
        k -= 1
      else
        print "S"
      end
    else
      if num % 2 == 1 && k != 0
        print "L"
        k -= 1
      else
        print "S"
      end
    end
  end
else
  puts "NO"
end

def getMaxAmountOfIslands(n)
    n ** 2 / 2 + (n % 2 == 0 ? 0 : 1)
end

def makeIslands(k, n)
    res = ""
    n.times do |i|
        n.times {|j| res += (i + j) % 2 == 0  && k > 0? (k-=1; "L") : "S"}
        res += "\n"
    end
    return res
end

n, k = *gets.split(' ')
            .map {|x| x.to_i}
            .to_a

if k <= getMaxAmountOfIslands(n) then
    puts "YES"
    puts makeIslands(k, n)
else
    puts "NO"
end

n, k = gets.split.collect{|i| i.to_i}
s = Array.new(n){Array.new(n,"S")}
if n.odd?
    if k > n*n/2+1
        puts "NO"
        exit
    end
else
    if k > n*n/2
        puts "NO"
        exit
    end
end
i = 0
j = 0
k.times do
    s[i][j] = "L"
    j += 2
    if j >= n
        i += 1
        j = i%2
    end
end
puts "YES"
s.each{|str| puts str.join}

n, k = gets.split.map(&:to_i)
ans = Array.new(n){Array.new(n, 'S')}

def adjcent?(i, j, n, ans)
  if ((i > 0 && ans[i - 1][j] == 'L') ||
    (j > 0 && ans[i][j - 1] == 'L') ||
    (i < n - 1 && ans[i + 1][j] == 'L') ||
    (j < n - 1 && ans[i][j + 1] == 'L'))
    true
  else
    false
  end
end

if k > (n * n + 1) / 2
  puts 'NO'
else
  puts 'YES'
  count = 0
  n.times do |i|
    n.times do |j|
      if !adjcent?(i, j, n, ans) && count < k
        ans[i][j] = 'L'
        count += 1
      end
    end
  end
  puts ans.map{|x| x.join}
end

n, k = gets.split.map {|x| x.to_i}

if (n*n + 1)/2 < k
  puts "NO"
else
  puts "YES"
  b = []
  n.times do
    b.push("S" * n)
  end

  for i in 0...n
    for j in 0...n
      if (i + j) % 2 == 0 && k > 0
        b[i][j] = 'L'
        k -= 1
      end
    end
  end
  b.each {|str| puts str}
end

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

# b.rb

def main()
    n, k = gets.chomp.split(" ").map{|s| next s.to_i }
    m = (n * n / 2) + (n % 2 == 1 ? 1 : 0)
    if m < k then
        puts("NO")
        return
    end

    puts("YES")
    r = 0
    n.times do |i|
        s = "S" * n
        t = i % 2
        while r < k && t < n do
            s[t] = "L"
            t += 2
            r += 1
        end
        puts(s)
    end
end

if __FILE__ == $0 then
    main()
end

n,s = gets.split.map {|x| x.to_i}
m = n*n/2+(n % 2)
map = Array.new(n) {"L"*n}
if s <= m
  puts "YES"
  n.times do |y|
    offset = y % 2
    x = offset
    while (x < n) do
      break if s == 0
      map[y][x] = 'S'
      s -= 1
      x += 2
    end
    break if s == 0
  end
  map.each do |line|
    puts line
  end

else
  puts "NO"
end

n, k = gets.chomp.split("\s").map(&:to_i)
if n % 2 == 0
  if n / 2 < k
    puts 'NO'
    exit
  end
else
  if n / 2 + 1 < k
    puts 'NO'
    exit
  end
end

puts 'YES'
count = 0
n.times do |i|
  if count < k && i % 2 == 0
    count += 1
    puts 'L' * n
  else
    puts 'S' * n
  end
end

n, k = gets.chomp.split("\s").map(&:to_i)
if n % 2 == 0
  if n / 2 < k
    puts 'NO'
    exit
  end
else
  if n / 2 + 1 < k
    puts 'NO'
    exit
  end
end

count = 0
n.times do |i|
  if count < k && i % 2 == 0
    count += 1
    puts 'L' * n
  else
    puts 'S' * n
  end
end

n, k = gets.chomp.split("\s").map(&:to_i)
if n % 2 == 0
  if n / 2 < k
    puts 'NO'
    exit
  end
else
  if n / 2 + 1 < k
    puts 'NO'
    exit
  end
end

if k == 0
  puts 'NO'
  exit
end

puts 'YES'
count = 0
n.times do |i|
  if count < k && i % 2 == 0
    count += 1
    puts 'L' * n
  else
    puts 'S' * n
  end
end

n, k = gets.chomp.split("\s").map(&:to_i)
if n % 2 == 0
  if (n / 2) * n < k
    puts 'NO'
    exit
  end
else
  if (n / 2 + 1) * n < k
    puts 'NO'
    exit
  end
end

puts 'YES'
count = 0
n.times do |i|
  n.times do |j|
    if count < k && i % 2 == 0 && j % 2 == 0
      count += 1
      print 'L'
    elsif count < k && i % 2 == 1 && j % 2 == 1
      count += 1
      print 'L'
    else
      print 'S'
    end
  end
  puts
end

input = gets.chomp
input2 = input.split(" ")
n = input2[0].to_i
k = input2[1].to_i

if n % 2 == 1
  max = (n/2+1) ** 2 + (n/2) ** 2
else
  max = (n/2) * n
end

if max >= k

  (n**2).times do |num|

    if num % n == 0 && num != 0
      print "\n"
    end

    if  (num / n) % 2 == 0 || (n % 2 == 1)
      if num % 2 == 0 && k != 0
        print "L"
        k -= 1
      else
        print "S"
      end
    else
      if num % 2 == 1 && k != 0
        print "L"
        k -= 1
      else
        print "S"
      end
    end
  end
else
  puts "NO"
end

input = gets.chomp
input2 = input.split(" ")
n = input2[0].to_i
k = input2[1].to_i

if n % 2
  max = (n/2+1) ** 2 + (n/2) ** 2
else
  max = (n/2) * n
end

if max >= k
  puts "YES"

  (n**2).times do |num|

    if num % n == 0 && num != 0
      print "\n"
    end

    if num % 2 == 0 && k != 0
      print "L"
      k -= 1
    else
      print "S"
    end

  end
else
  puts "NO"
end

input = gets.chomp
input2 = input.split(" ")
n = input2[0].to_i
k = input2[1].to_i

if n % 2
  max = (n/2+1) ** 2 + (n/2) ** 2
else
  max = (n/2) * n
end

if max >= k
  puts "YES"

  (n**2).times do |num|

    if num % n == 0 && num != 0
      print "\n"
    end

    if  (num / n) % 2 == 0
      if num % 2 == 0 && k != 0
        print "L"
        k -= 1
      else
        print "S"
      end
    else
      if num % 2 == 1 && k != 0
        print "L"
        k -= 1
      else
        print "S"
      end
    end

  end
else
  puts "NO"
end

input = gets.chomp
input2 = input.split(" ")
n = input2[0].to_i
k = input2[1].to_i

if n % 2
  max = (n/2+1) ** 2 + (n/2) ** 2
else
  max = (n/2) * n
end

if max >= k
  puts "YES"

  (n**2).times do |num|

    if num % n == 0 && num != 0
      print "\n"
    end

    if  (num / n) % 2 == 0 || (n % 2 == 1)
      if num % 2 == 0 && k != 0
        print "L"
        k -= 1
      else
        print "S"
      end
    else
      if num % 2 == 1 && k != 0
        print "L"
        k -= 1
      else
        print "S"
      end
    end
  end
else
  puts "NO"
end

def getMaxAmountOfIslands(n)
    n ** 2 / 2 + (n % 2 == 0 ? 0 : 1)
end

def makeIslands(k, n)
    res = ""
    (n ** 2).times do |i|
        shift = (i / n) % 2
        res += (i + shift) % 2 == 0 && i / 2 < k ? "L" : "S"
        res += "\n" if (i+1) % n == 0  && i > 0
    end

    return res
end

n, k = *gets.split(' ')
            .map {|x| x.to_i}
            .to_a

if k <= getMaxAmountOfIslands(n) then
    puts "YES"
    puts makeIslands(k, n)
else
    puts "NO"
end

def getMaxAmountOfIslands(n)
    n ** 2 / 2 + (n % 2 == 0 ? 0 : 1)
end

def makeIslands(k, n)
    res = ""
    (n ** 2).times do |i|
        res += i % 2 == 0 && i / 2 < k ? "L" : "S"
        res += "\n" if (i+1) % n == 0  && i > 0
    end

    return res
end

n, k = *gets.split(' ')
            .map {|x| x.to_i}
            .to_a

if k <= getMaxAmountOfIslands(n) then
    puts "YES"
    puts makeIslands(k, n)
else
    puts "NO"
end

n, k = gets.split.collect{|i| i.to_i}
s = Array.new(n){Array.new(n,"S")}
if n.odd?
    if k > n*n/2+1
        puts "NO"
        exit
    end
else
    if k > n*n/2
        puts "NO"
        exit
    end
end
i = 0
j = 0
k.times do
    s[i][j] = "L"
    j += 2
    if j >= n
        i += 1
        j = i%2
    end
end
puts "YES"
s.each{|str| puts str.join(" ")}

n, k = gets.split.map(&:to_i)
ans = Array.new(n){Array.new(n, 'S')}

def adjcent?(i, j, n, ans)
  if ((i > 0 && ans[i - 1][j] == 'L') ||
    (j > 0 && ans[i][j - 1] == 'L') ||
    (i < n - 1 && ans[i + 1][j] == 'L') ||
    (j < n - 1 && ans[i][j + 1] == 'L'))
    true
  else
    false
  end
end

if k > (n + 1) / 2
  puts 'NO'
else
  puts 'YES'
  count = 0
  n.times do |i|
    n.times do |j|
      if !adjcent?(i, j, n, ans) && count < k
        ans[i][j] = 'L'
        count += 1
      end
    end
  end
  puts ans.map{|x| x.join}
end


gets.strip.to_i.times do
    p = gets.split('').reject { |e| e == "\n" };
    h = gets.split('').reject { |e| e == "\n" };
    if p.length > h.length
        puts "NO"
        next
    end
    done = false
    (0...h.length).each { |i|
        frq = Array.new(27, 0);
        sm = p.length
        p.each { |e| frq[e.ord - ?a.ord] += 1 }
        flg = true
        for j in i ... h.length
            if frq[h[j].ord - ?a.ord] == 0
                flg = false
                break
            else
                frq[h[j].ord - ?a.ord] -= 1
                break if frq.count(0) == frq.length
            end
        end
        if flg && frq.count(0) == frq.length
            puts "YES"
            done = true
            break
        end
    }
    puts "NO" if !done
end

gets.strip.to_i.times do
    p = gets.strip
    h = gets.strip
    if p.length > h.length
        puts "NO"
        next
    end
    p = p.chars.sort.join
    ck = false
    (0...h.length).each { |i|
        break if i + p.length > h.length
        s = h[i, p.length]
        s = s.chars.sort.join
        if s == p
            ck = true
            break
        end
    }
    puts ck ? "YES" : "NO"
end

t = gets.chomp.to_i

t.times do |ti|
  s = gets.chomp
  pnew = gets.chomp
  letter_count = {}
  s.each_char do |i|
    letter_count[i] = letter_count[i].to_i + 1
  end

  window_len = (s.length) -1
  count = 0
  found = false

  while count < pnew.length
    new_s = pnew[count..window_len]
    new_h = {}
    new_s.each_char do |i|
      new_h[i] = new_h[i].to_i + 1
    end
    count+=1
    window_len+=1
    if new_h == letter_count
      found = true
      puts "YES"
      break;
    end
  end

  if !found
    puts "NO"
  end
end

t = gets.chomp.to_i

t.times do |ti|
  p = gets.chomp
  h = gets.chomp
  i = 0
  j = i + p.length - 1
  found = false
  while j < h.length
    if h[i..j].chars.sort == p.chars.sort
      found = true
      puts "YES"
      break
    else
      i += 1
      j += 1
    end
  end
  unless found
    puts "NO"
  end
end

t = gets.chomp.to_i

t.times do |ti|
  p = gets.chomp
  h = gets.chomp
  i = 0
  j = i + p.length - 1
  found = false
  while j < h.length
    if (h[i..j].split('') - p.split('')).length == 0 && (p.split('') - h[i..j].split('')).length == 0
      found = true
      puts "YES"
      break
    else
      i += 1
      j += 1
    end
  end
  unless found
    puts "NO"
  end
end

t = gets.chomp.to_i

t.times do |ti|
  p = gets.chomp
  h = gets.chomp
  i = 0
  j = i + p.length - 1
  while j < h.length
    if (h[i..j].split('') - p.split('')).length == 0 && (p.split('') - h[i..j].split('')).length == 0
      puts "YES"
      break
    else
      i += 1
      j += 1
    end
  end
  if j == h.length - 1
    puts "NO"
  end
end

gets.strip.to_i.times do
    p = gets.split('').reject { |e| e == "\n" };
    h = gets.split('').reject { |e| e == "\n" };
    done = false
    (0...h.length).each { |i|
        sm = p.length
        frq = Array.new(27, 0);
        p.each { |e| frq[e.ord - ?a.ord] += 1 }
        flg = true
        for j in i ... h.length
            if frq[h[j].ord - ?a.ord] == 0
                flg = false
                break
            else
                sm -= 1

                frq[h[j].ord - ?a.ord] -= 1
                break if sm == 0
            end
        end
        if flg
            puts "YES"
            done = true
            break
        end
    }
    puts "NO" if !done
end

gets.strip.to_i.times do
    p = gets.strip
    h = gets.strip
    if p.length > h.length
        puts "NO"
        next
    end
    p = p.chars.sort.join
    ck = false
    (0...p.length).each { |i|
        break if i + p.length > h.length
        s = h[i, p.length]
        s = s.chars.sort.join
        if s == p
            ck = true
            break
        end
    }
    puts ck ? "YES" : "NO"
end

gets.strip.to_i.times do
    frq = Array.new(27, 0);
    p = gets.split('').reject { |e| e == "\n" };
    h = gets.split('').reject { |e| e == "\n" };
    done = false
    (0...h.length).each { |i|
        sm = p.length
        p.each { |e| frq[e.ord - ?a.ord] += 1 }
        flg = true
        for j in i ... h.length
            if frq[h[j].ord - ?a.ord] == 0
                flg = false
                break
            else
                sm -= 1
                frq[h[j].ord - ?a.ord] -= 1
                break if sm == 0
            end
        end
        if flg
            puts "YES"
            done = true
        end
    }
    puts "NO" if !done
end

gets.strip.to_i.times do
    p = gets.split('').reject { |e| e == "\n" };
    h = gets.split('').reject { |e| e == "\n" };
    if p.length > h.length
        puts "NO"
        next
    end
    done = false
    (0...h.length).each { |i|
        frq = Array.new(27, 0);
        sm = p.length
        p.each { |e| frq[e.ord - ?a.ord] += 1 }
        flg = true
        for j in i ... h.length
            if frq[h[j].ord - ?a.ord] == 0
                flg = false
                break
            else
                sm -= 1
                frq[h[j].ord - ?a.ord] -= 1
                break if sm == 0
            end
        end
        if flg
            puts "YES"
            done = true
            break
        end
    }
    puts "NO" if !done
end

gets.strip.to_i.times do
    p = gets.strip
    h = gets.strip
    if p.length > h.length
        puts "NO"
        next
    end
    p.chars.sort.join
    ck = false
    (0...p.length).each { |i|
        break if i + p.length > h.length
        s = h[i, p.length]
        s.chars.sort.join
        if s == p
            ck = true
            break
        end
    }
    puts ck ? "YES" : "NO"
end

gets.strip.to_i.times do
    frq = Array.new(27, 0);
    p = gets.split('').reject { |e| e == "\n" };
    h = gets.split('').reject { |e| e == "\n" };
    done = false
    (0...h.length).each { |i|
        sm = p.length
        p.each { |e| frq[e.ord - ?a.ord] += 1 }
        flg = true
        for j in i ... h.length
            if frq[h[j].ord - ?a.ord] == 0
                flg = false
                break
            else
                sm -= 1
                frq[h[j].ord - ?a.ord] -= 1
                break if sm == 0
            end
        end
        if flg
            puts "YES"
            done = true
            break
        end
    }
    puts "NO" if !done
end

gets.strip.to_i.times do
    p = gets.split('').reject { |e| e == "\n" };
    h = gets.split('').reject { |e| e == "\n" };
    if p.length > h.length
        puts "NO"
        next
    end
    p.sort
    ck = false
    (0...p.length).each { |i|
        break if i + p.length > h.length
        s = h[i, p.length - 1]
        s.sort
        if s == p
            ck = true
            break
        end
    }
    puts ck ? "YES" : "NO"
end

gets.strip.to_i.times do
    p = gets.split('').reject { |e| e == "\n" };
    h = gets.split('').reject { |e| e == "\n" };
    done = false
    (0...h.length).each { |i|
        sm = p.length
        frq = Array.new(27, 0);
        p.each { |e| frq[e.ord - ?a.ord] += 1 }
        flg = true
        for j in i ... h.length
            if frq[h[j].ord - ?a.ord] == 0
                flg = false
                break
            else
                frq[h[j].ord - ?a.ord] -= 1
                if frq.uniq.length == 1
                    frq.uniq.each { |e|
                        if e.nonzero?
                            flg = false
                            break
                        end
                    }
                end
            end
        end
        if flg
            puts "YES"
            done = true
            break
        end
    }
    puts "NO" if !done
end

gets.strip.to_i.times do
    p = gets.strip
    h = gets.strip
    if p.length > h.length
        puts "NO"
        next
    end
    p = p.chars.sort.join
    ck = false
    (0...h.length).each { |i|
        break if i + p.length > h.length
        s = h[i, p.length]
        s = s.chars.sort.join
        puts "#{s} + #{p}"
        if s == p
            ck = true
            break
        end
    }
    puts ck ? "YES" : "NO"
end


y,k,n = gets.split(" ").map(&:to_i)
i = (y/k.to_f).ceil
start = k * i

arr = []
(start..n).step(k).each do |a|

	arr << a - y if a - y != 0
end
if arr.empty?
	puts -1
else
	puts arr.join(" ")
end

y,k,n=gets.chomp.split(' ').map(&:to_i)
i=y/k +1
while (k*i)<=n
	print (k*i-y).to_s+' '
	i+=1
end
if i==y/k+1
	puts "-1"
else
	puts
end

y, k, n = gets.split.map(&:to_i)
min = k-y%k
if min+y > n
  puts(-1)
else
  while min+y <= n do
    $><<"#{min} "
    min += k
  end
end

y , k, n = gets.split.map {|x| x.to_i }
i = 1
ans = []
while i * k <= n do
    ans << (i * k - y) if i * k - y >= 1
    i = i + 1
end
if ans.size != 0 then
    puts ans.join " "
else
    puts -1
end

y, k, n = gets.chomp.split(/ /).map(&:to_i)
if y >= n
    puts "-1"
else
    if k == 1
        puts "#{(1..(n - y)).to_a.join(" ")}"
    else
        ans = []
        limit = (n / k) * k
        index = 0
        while index < limit
            index += k
            next if index < y
            x = index - y
            ans << x if x > 0
        end
        if ans.length == 0
            puts "-1"
        else
            puts ans.join(" ")
        end
    end
end

y,k,n=gets.split.collect{|e| e.to_i}
fl=0
i=k;
while (i<y && i<=n) do i+=k end
j=i;
if (j==y) then j+=k end
while (j<=n) do
  if (j!=i) then print " " end
  print j-y
  fl=1
  j+=k
end
if (fl==0) then print -1 end
puts

s = gets.split

y = s[0].to_i
k = s[1].to_i
n = s[2].to_i

if y >= n then
    puts "-1"
elsif k == n then
    if n - y > 0 then
        puts n - y
    else
        puts "-1"
    end
else
    maybe = []
    if k > y then
        i = k - y
    else
        i = 1
        t = i * k
        while t < y do
            i += 1
            t = i * k
        end
        i = i * k - y
#       i = 0
#       while (y + i) % k != 0 do
#           i += 1
#       end
    end

    if y + i > n then
        puts "-1"
    else
        if i != 0 then
            maybe << i
        end
        j = 1
        while y + i + j*k <= n do
            maybe << i + j*k
            j += 1
        end
        if maybe.empty? then
            puts "-1"
        else
            puts maybe.join(" ")
        end
    end
end

y, k, n = gets.split.map { |x| x.to_i }
xs = ((y / k) * k + k..n).step(k).map { |x| x - y }.to_a
puts(xs.empty? ? -1 : xs * ' ')

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

opts = (k - (y % k)).step(n-y,k)

if opts.any?
	puts opts.map(&:to_s).join(' ')
else
	puts "-1"
end

y, k, n = gets.split.map { |x| x.to_i }

x = (y / k + 1) * k - y
ans = []
while x + y <= n
	ans << x
	x += k
end
if ans.size > 0
	puts ans.join ' '
else
	puts -1
end

y, k, n = gets.chomp.split(" ").map{|e| e.to_i}
ans = []

min = nil
idx = 1
loop do
  if idx * k > n
    break
  elsif idx * k >= y and (idx * k - y) > 0
    min = idx * k - y
    break
  end
  idx += 1
end
if not min.nil?
  ans << min
  tmp = min + k
  loop do
    if tmp > n - y
      break
    else
      ans << tmp
    end
    tmp += k
  end
end

ans << -1 if ans.length == 0

puts ans.join(" ")

y, k, n = gets.split.map(&:to_i)
all = Array.new
i = y
i -= y%k
i += k
while i <= n do
  all << i-y
  i += k
end
if all.count == 0
  print -1
else
  all.each {|x| print x, " "}
end

y, k, n = gets.split(' ').map(&:to_i)
res = (((y / k) + 1)..(n / k)).to_a.map { |x| x * k - y }
puts res.empty? ? -1 : res

s = gets.split

y = s[0].to_i
k = s[1].to_i
n = s[2].to_i
if k == n then
    puts n - y
else
    maybe = []
    if k > y then
        i = k - y
    else
        i = 0
        while (y + i) % k != 0 do
            i += 1
        end
    end

    if y + i > n then
        puts "-1"
    else
        if i != 0 then
            maybe << i
        end
        j = 1
        while y + i + j*k <= n do
            maybe << i + j*k
            j += 1
        end
        puts maybe.join(" ")
    end
end

s = gets.split

y = s[0].to_i
k = s[1].to_i
n = s[2].to_i

maybe = []

sum = y
i = 1
while (y + i) % k != 0 do
    i += 1
end

if y + i > n then
    puts "-1"
else
    maybe << i
    j = 1
    while y + i + j*k < n do
        maybe << i + j*k
        j += 1
    end
    puts maybe.join(" ")
end

s = gets.split

y = s[0].to_i
k = s[1].to_i
n = s[2].to_i
if k == n then
    puts n - y
elsif n/k == 1 then
    puts k - y
else
    maybe = []
    if k > y then
        i = k
    else
        i = 1
        while (y + i) % k != 0 do
            i += 1
        end
    end

    if y + i > n then
        puts "-1"
    else
        maybe << i
        j = 1
        while y + i + j*k <= n do
            maybe << i + j*k
            j += 1
        end
        puts maybe.join(" ")
    end
end

s = gets.split

y = s[0].to_i
k = s[1].to_i
n = s[2].to_i
if k == n then
    puts n - y
elsif n/k == 1 then
    puts k - y
else
    maybe = []
    if k > y then
        i = k - y
    else
        i = 1
        while (y + i) % k != 0 do
            i += 1
        end
    end

    if y + i > n then
        puts "-1"
    else
        maybe << i
        j = 1
        while y + i + j*k <= n do
            maybe << i + j*k
            j += 1
        end
        puts maybe.join(" ")
    end
end

s = gets.split

y = s[0].to_i
k = s[1].to_i
n = s[2].to_i
if k >= n then
    puts "-1"
else
    maybe = []
    i = 1
    while (y + i) % k != 0 do
        i += 1
    end

    if y + i > n then
        puts "-1"
    else
        maybe << i
        j = 1
        while y + i + j*k <= n do
            maybe << i + j*k
            j += 1
        end
        puts maybe.join(" ")
    end
end

s = gets.split

y = s[0].to_i
k = s[1].to_i
n = s[2].to_i

if k == n then
    puts n - y
else
    maybe = []
    if k > y then
        i = k - y
    else
        i = 0
        while (y + i) % k != 0 do
            i += 1
        end
    end

    if y + i > n then
        puts "-1"
    else
        if i != 0 then
            maybe << i
        end
        j = 1
        while y + i + j*k <= n do
            maybe << i + j*k
            j += 1
        end
        if maybe.empty? then
            puts "-1"
        else
            puts maybe.join(" ")
        end
    end
end

y, k, n = gets.chomp.split(" ").map{|e| e.to_i}
ans = []

min = nil
idx = 1
loop do
  if idx * k >= n
    break
  elsif idx * k >= y
    min = idx * k - y
    break
  end
  idx += 1
end

if not min.nil?
  tmp = min
  loop do
    if tmp >= n - y
      break
    else
      ans << tmp
    end
    tmp += k
  end
end

ans << -1 if ans.length == 0

puts ans.join(" ")

y, k, n = gets.chomp.split(" ").map{|e| e.to_i}
ans = []

min = nil
idx = 1
loop do
  if idx * k >= n
    break
  elsif idx * k >= y and (idx * k - y) > 0
    min = idx * k - y
    break
  end
  idx += 1
end

if not min.nil?
  tmp = min
  loop do
    if tmp > n - y
      break
    else
      ans << tmp
    end
    tmp += k
  end
end

ans << -1 if ans.length == 0

puts ans.join(" ")

y, k, n = gets.chomp.split(" ").map{|e| e.to_i}
ans = []

min = nil
idx = 0
loop do
  if idx * k >= n
    break
  elsif idx * k >= y
    min = idx * k - y
    break
  end
  idx += 1
end

if not min.nil?
  tmp = min
  loop do
    if tmp >= n - y
      break
    else
      ans << tmp
    end
    tmp += k
  end
end

ans << -1 if ans.length == 0

puts ans.join(" ")

y, k, n = gets.split.map(&:to_i)
max = (n-n%k)-y
if max < 1
  puts -1
  exit
end
while max >= 1 do
  puts max
  max -= k
end

y, k, n = gets.chomp.split(/ /).map(&:to_i)
if y >= n || (n - y) % k != 0
    puts "-1"
else
    if k == 1
        puts "#{(1..(n - y)).to_a.join(" ")}"
    else
        ans = []
        limit = (n / k) * k
        index = 0
        while index < limit
            index += k
            next if index < y
            x = index - y
            ans << x
        end
        puts ans.join(" ")
    end
end

y, k, n = gets.chomp.split(/ /).map(&:to_i)
if y >= n
    puts "-1"
else
    ans = []
    (1..(n - y)).each do |x|
        ans << x if x + y < n && (x + y) % k == 0
    end
    puts ans.join(" ")
end

y, k, n = gets.chomp.split(/ /).map(&:to_i)
if y >= n
    puts "-1"
else
    if k == 1
        puts "#{(1..(n - y)).to_a.join(" ")}"
    else
        ans = []
        limit = (n / k) * k
        index = 0
        while index < limit
            index += k
            next if index < y
            x = index - y
            ans << x
        end
        if ans.length == 0
            puts "-1"
        else
            puts ans.join(" ")
        end
    end
end

y, k, n = gets.chomp.split(/ /).map(&:to_i)
if y >= n
    puts "-1"
else
    if k == 1
        puts "#{(1..(n - y)).to_a.join(" ")}"
    else
        ans = []
        limit = (n / k) * k
        index = 0
        while index < limit
            index += k
            next if index < y
            x = index - y
            ans << x
        end
        puts ans.join(" ")
    end
end

y,k,n = gets.split(" ").map(&:to_i)
i = (y/k.to_f).ceil
start = k * i
if start >= n
	puts -1
else
	arr = []
	(start..n).step(k).each do |a|
		arr << a - y
	end
	puts arr.join(" ")
end

y,k,n = gets.split(" ").map(&:to_i)
i = (y/k.to_f).ceil
start = k * i
if start >= n
	puts -1
else
	arr = []
	(start..n).step(k).each do |a|

		arr << a - y if a - y != 0
	end
	puts arr.join(" ")
end

y,k,n=gets.split.collect{|e| e.to_i}
fl=0
if (y<=k) then
  i=k;
  if (i<=n) then fl=1 end
else
  i=y+1
  while (i<=n) do
    if (i%k==0) then
      fl=1
      break
    end
    i+=1
  end
end
j=i;
while (j<=n) do
  if (j!=i) then print " " end
  print j-y
  j+=k
end
if (fl==0) then print -1 end
puts


t = gets.to_i
t.times do
  puts((gets.chomp!.split('') + gets.chomp!.split('')).uniq.size - 1)
end

gets.to_i.times {
	p gets.chomp.chars.append(*gets.chomp.chars).group_by{|i|i}.values.map{|i|(i.length+1)/2}.sort{|a,b|b-a}.drop(1).sum
}

gets.to_i.times {
	a = gets.chomp.chars.append(*gets.chomp.chars).group_by{|i|i}.values.map{|i|(i.length+1)/2}
	p (a.count>1? a.sum - 1: 0)
}


t = gets.to_i
t.times do
	a, b = gets.split.map(&:to_i)
	puts a + b
end

n = gets.chomp.to_i
for i in 1..n do
    x,y  = gets.chomp.split(' ')
    puts x.to_i + y.to_i
end

$n = gets.to_i
$i = 1
until $i > $n  do
   a, b, * = gets.split.map(&:to_i)
   sum = a + b
   puts( sum )
   $i +=1;
end

gets.to_i.times do
    puts gets.split.map(&:to_i).inject(:+)
end

t=gets.to_i
t.times{
a,b=gets.split(" ")
puts a.to_i+b.to_i
}

count_number = gets.to_i
result = []
count_number.times do |n|
  input_numbers = gets.chomp.split(' ').map(&:to_i)
  sum_numbers = input_numbers.inject(0){|sum,x| sum + x }
  result.push(sum_numbers)
end
puts result

gets.to_i.times { puts gets.split(' ').map(&:to_i).reduce(:+) }

gets.to_i.times{puts eval gets.gsub(' ', '+')}

gets.to_i.times do
  a, b = gets.split
  a, b = a.to_i, b.to_i
  puts a+b
end

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

  puts a + b
end

1.upto(gets.chomp.to_i) do
  a,b = gets.chomp.split.map(&:to_i)
  s = 0
  a.times { s += 1 }
  b.times { s += 1 }

  puts s
end

$n = gets.to_i
$i = 1
until $i > $n  do
   a = gets.to_i
   b = gets.to_i
   sum = a + b
   puts( sum )
   $i +=1;
end


n, t1, t2, k = gets.split.map(&:to_i)
abs = n.times.map{gets.split.map(&:to_i)}
abs.map.with_index do |(a, b), i|
  [i, [a * t1 * (1 - k.to_f / 100) + b * t2, b * t1 * (1 - k.to_f / 100) + a * t2].max]
end.sort_by{|i, max| [-max, i]}.each do |i, max|
  puts "#{i+1} #{"%.2f" % max}"
end

def main

    n, t1, t2, k = STDIN.gets.split.collect {|s| s.to_i}

    a = []

    n.times do |i|
        v1, v2 = STDIN.gets.split.collect {|s| s.to_i}
        h1 = v1 * t1 * (1 - k / 100.0) + v2 * t2
        h2 = v2 * t1 * (1 - k / 100.0) + v1 * t2
        a.push([i, [h1, h2].max])
    end

    a.sort! do |x, y|
        if x[1] < y[1]
            1
        elsif x[1] > y[1]
            -1
        else
            x[0] <=> y[0]
        end
    end

    a.each {|e| puts "%d %.2f" % [e[0] + 1, e[1]]}
end

main

def calcmax(a,b,t1,t2,k)
    f = (100 - k).to_f / 100
    c1 = a*t1*f + b*t2
    c2 = b*t1*f + a*t2
    return [c1,c2].max
end

n,t1,t2,k = gets.chomp.split(/ /).map!{|x| x.to_i}
ar = Array.new()
for i in 0..n-1
    a,b = gets.chomp.split(/ /).map!{|x| x.to_i}
    ar << [i+1, calcmax(a,b,t1,t2,k)]
end
ar.sort!{|ar1, ar2|
    if ar2[1] == ar1[1]
        ar1[0] <=> ar2[0]
    else
        ar2[1] <=> ar1[1]
    end
}
for i in 0..n-1
    puts ar[i][0].to_s + " " + sprintf('%.2f', ar[i][1])
end

def calcmax(a,b,t1,t2,k)
    f = (100 - k).to_f / 100
    c1 = a*t1*f + b*t2
    c2 = b*t1*f + a*t2
    return [c1,c2].max
end

n,t1,t2,k = gets.chomp.split(/ /).map!{|x| x.to_i}
ar = Array.new()
for i in 0..n-1
    a,b = gets.chomp.split(/ /).map!{|x| x.to_i}
    ar << [i+1, calcmax(a,b,t1,t2,k)]
end
ar.sort!{|ar1, ar2|
    ar2[1] <=> ar1[1]
}
for i in 0..n-1
    puts ar[i][0].to_s + " " + sprintf('%.2f', ar[i][1])
end

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

if t1*0.01*k >= t2
  a = n.times.map{|i| gets.split.map(&:to_i).sort.reverse.push(i) }
else
  a = n.times.map{|i| gets.split.map(&:to_i).sort.push(i) }
end

a.map!{|m| [m[0]*t1*(1-0.01*k) + m[1]*t2, m[2]] }.sort!{|b,a| (a[0] <=> b[0]).nonzero? or b[1] <=> a[1] }.each{|m| puts "%d %.02f"% [m[1]+1,m[0]]}

n, t1, t2, k = gets.split.map(&:to_i)
abs = n.times.map{gets.split.map(&:to_i)}
abs.map.with_index do |(a, b), i|
  [i, [a * t1 * (1 - k.to_f / 100) + b * t2, b * t2 * (1 - k.to_f / 100) + a * t2].max]
end.sort_by{|i, max| [-max, i]}.each do |i, max|
  puts "#{i+1} #{"%.2f" % max}"
end


n, c = gets, Hash.new(0)
gets.split.each {|a| c[a] += 1}
p c.values.max

_ = $stdin.gets

bxs = $stdin.gets.chomp.split(" ").map{ |a| a.to_i }
ns = {};
bxs.each{ |a|
  ns[a] = (ns[a] || 0) + 1
}
puts ns.values.max

#!/usr/bin/env ruby

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

$ans = 0
last = -1
streak = 0
arr.each do |x|
	if x != last then
		last = x
		$ans = streak unless streak <= $ans
		streak = 1
	else
		streak += 1
	end
end
$ans = streak unless streak <= $ans

puts $ans

#!/usr/bin/env ruby

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

$ans = 1
(n-1).times do |x|
	if arr[x] == arr[x+1] then
		$ans += 1
	end
end
puts $ans

#!/usr/bin/env ruby

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

$ans = 0
last = -1
streak = 0
arr.each do |x|
	puts x
	if x != last then
		last = x
		$ans = streak unless streak <= $ans
		streak = 1
	else
		streak += 1
	end
end
$ans = streak unless streak <= $ans

puts $ans


n = gets.to_i
b, total = 100, 0
n.times do
  a, p = gets.split.map(&:to_i)
  b = p if p < b
  total += a * b
end
puts total

n = gets.to_i
money = 0
less = 99999999999999999999
n.times do
	x,y= *gets.split(" ").map(&:to_i)
	less = y if less > y
	money += less*x
end

p money

n, total_cost, min_so_far = gets.chomp.to_i, 0, 101
n.times do |t|
	a,p = gets.chomp.split(" ").map(&:to_i)
	min_so_far = p if p < min_so_far
	total_cost += a*min_so_far
end

puts total_cost

n = gets.to_i
total = 0
mn = 1000
for i in 1..n
    a,b = gets.split().map(&:to_i)
    mn = [mn,b].min
    total+= a*mn
end
puts total

# http://codeforces.com/contest/588/problem/A
# A. Duff and Meat

n = gets.chomp.to_i

sum = 0
min = 1000
n.times do
  a, c = gets.chomp.split.map(&:to_i)
  min = c if min > c

  sum += min * a
end

puts sum

n = gets.chomp.to_i;
min = 0x7fffffff;
cost = 0;
n.times do |x|
  a, p = gets.chomp.split.map(&:to_i);
  min = [min, p].min;
  cost += a * min;
end
puts cost;

n = gets.strip.to_i
a = []
p = []
n.times do |i|
  a[i], p[i] = gets.strip.split(" ").map(&:to_i)
end
i = 0
money = 0
while i < n do
  money += a[i] * p[i]
  j = i + 1
  while j < n && p[j] > p[i] do
    money += a[j] * p[i]
    j += 1
  end
  i = j
end
puts money

#! ruby
# Try Codeforces Round 326 div2
# author: Leonardone @ NEETSDKASU

n = gets.to_i

pMin = 100
total = 0

n.times do
    ai, pi = gets.chomp.split.map(&:to_i)
    pMin = [pi, pMin].min
    total += ai * pMin
end

puts total

n = gets.to_i
a = []
n.times{
  x, y = gets.split(" ").map(&:to_i)
  a << [x,y]
}
ans = 0
cur = a[0][1]
a.each{ |x|
  cur = [cur,x[1]].min
  ans += cur*x[0]
}
puts ans

n = readline.to_i
p = 100; ans = 0; num = 0
n.times do
  a, b = readline.split().map(&:to_i)
  p = b if p > b
  ans += p * a
end
puts ans

n=gets.chomp.to_i

a=0
b=[]

while a<n
	c=gets.chomp.split(' ')
	c.each do |item|
		b.push(item.to_i)
	end
	a+=1
end

sum=0
for i in (0..b.length-2).step(2)
	sum+=b[i]*b[i+1]
	if (b.length)>3 and i<b.length-3
		if b[i+1]<b[i+3]
			b[i+3]=b[i+1]
		end
	end
end

puts sum

n=gets.to_i
a1,p1=gets.split.map{|e| e.to_i}
ans=a1*p1
n-=1
n.times{
	ai,pi=gets.split.map{|e| e.to_i}
	if pi<p1 then
		p1=pi
	end
	ans=ans+p1*ai
}
puts ans

n = gets.to_i
money = 0
price = 101
while n > 0 do
	n -= 1
	a,p = gets.chomp.split(' ').map!{ |o| o.to_i }
	price = p if price > p
	money += price * a
end

puts money

n = gets.to_i
r,m = 0,1000
n.times do |i|
	a,b = gets.split.map(&:to_i)
	m = [ b , m ].min
	r += m * a
end
p r

numDays = gets.chomp.to_i

minPrice = 100 # max price
totalCost = 0

for i in 0..numDays-1

    inStr = gets.chomp.split(" ")
    neededOnDay = inStr[0].to_i
    priceOnDay = inStr[1].to_i

    if priceOnDay < minPrice
        minPrice = priceOnDay
    end

    totalCost += minPrice * neededOnDay

end

puts totalCost

numDays = gets.chomp.to_i
neededOnDay = [] # Array.new(numDays)
priceOnDay = [] # Array.new(numDays)

minPrice = 100 # max price
totalCost = 0

for i in 0..numDays-1

    inStr = gets.chomp.split(" ")
    neededOnDay.push(inStr[0].to_i)
    priceOnDay.push(inStr[1].to_i)

    if priceOnDay[i] < minPrice
        minPrice = priceOnDay[i]
    end

    totalCost += minPrice * neededOnDay[i]

end

puts totalCost

n = gets.to_i

eat = Array.new
price = Array.new
(1..n).each do
  tokens = gets.split ' '
  eat.push tokens[0].to_i
  price.push tokens[1].to_i
end

index = 0
total = 0

while index < n do
  pp = price[index]
  store = eat[index]

  while index+1 < n and pp < price[index + 1] do
    index += 1
    store += eat[index]
  end
  total += store * pp
  index += 1
end

puts total

# coding: utf-8

# if __FILE__ == $0
# end

n = gets.to_i
spent = 0
lowest_price = 100
n.times {
    meat, price = gets.split.map(&:to_i)

    if price < lowest_price
        lowest_price = price
    end

    # this would be enough.
    # knowing the lowest price, count required amount and multiply it by currently known lowest price
    spent += meat*lowest_price
}

puts spent

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

m = 0
minp = ps[0]
for i in 0..n-1
  a = as[i]
  p = ps[i]
  minp = [minp, p].min
  m += a * minp
end

puts m

days = gets.chomp.to_i
data = []
for i in (0..days-1)
	data[i] = gets.chomp
	data[i] = data[i].split
end

cost = 0
for i in (0..days-1)
	if i == 0
		cost += (data[i][0].to_i * data[i][1].to_i)
	else
		if data[i-1][1].to_i <= data[i][1].to_i
			data[i][1] = data[i-1][1].to_i
			cost += (data[i][0].to_i * data[i][1].to_i)
		else
			cost += (data[i][0].to_i * data[i][1].to_i)
		end
	end
end

print cost

n = gets.to_i
b, ans = 100, 0
n.times do
  a, p = gets.split.map(&:to_i)
  b = p if p < b
  ans += a * b
end
puts ans

n = gets.to_i
a, p = [], []
n.times.each{|i| a[i], p[i] = gets.split.map(&:to_i)}
buy, i, total = 0, 0, 0
n.times do |j|
  buy += a[j]
  if j == n - 1 || p[j + 1] < p[i]
    total += p[i] * buy
    i = j + 1
    buy = 0
  end
end
p total

n = gets.chomp.to_i

a = []
p = []

n.times do |i|
  aa, pp = gets.chomp.split(" ").map(&:to_i)
  a << aa
  p << pp
end

def lowest_cost(a, p)
  if a.size == 0
    0
  elsif a.size == 1
    a[0] * p[0]
  else
    low_cost = p.min
    low_cost_day = p.index(low_cost)

    kg = 0
    a[low_cost_day..-1].each do |k|
      kg += k
    end
    cost = kg * low_cost + lowest_cost(a[0...low_cost_day], p[0...low_cost_day])
  end
end

puts lowest_cost(a, p)

n = gets.to_i
min = 109
sum = 0
n.times do
    a, b = gets.split(' ').map(&:to_i)
    if b < min
        min = b
    end
    sum += min * a
end
print sum, "\n"

min = 1000
sum = 1.upto(gets.to_i).inject(0) do |sum, idx|
  a, p = gets.split(' ').map(&:to_i)

  min = [min, p].min

  sum + a*min
end

puts sum

n = gets.to_i
a1,b1 = gets.split.map(&:to_i)
s = a1 * b1
for i in(2..n)
    a,b = gets.split.map(&:to_i)
    if(b>b1)
        s = s + (a*b1)

    else
        s = s + (a*b)
        b1=b
    end
end
p s

n = gets.to_i

last_min = 0x3f3f3f3f

ans = 0
n.times do
	a, p = gets.split.map { |s| s.to_i }
	last_min = [last_min, p].min
	ans += last_min * a
end

puts ans

totalDay = gets.chomp.to_i
meatHash ||= {}
cheapestPrice ||= 500
neededMoney = 0

totalDay.times do
	line = gets.chomp.split(' ').map {|item| item.to_i}
	needed, price = line[0], line[1]

	cheapestPrice = price if cheapestPrice > price
	neededMoney += cheapestPrice * needed
end

puts neededMoney

# http://codeforces.com/contest/588/problem/A
# A. Duff and Meat

n = gets.chomp.to_i

sum = 0
min = 100.0
n.times do
  a, c = gets.chomp.split.map(&:to_i)
  min = c if min > c

  sum += min * a
end

puts sum

# http://codeforces.com/contest/588/problem/A
# A. Duff and Meat

n = gets.chomp.to_i

amounts = []
costs = []
min = 100.0
n.times do
  a, c = gets.chomp.split.map(&:to_i)
  min = c if min > c
  amounts << a
  costs << c
end

arr = []
amounts.zip(costs).each.with_index do |v, idx|
  a, c = v
  if c == min
    arr << amounts[idx..-1].map { |e| e * min }
    break
  else
    arr << a * c
  end
end
puts arr.flatten.inject(0, :+)

n = gets.to_i
a1,b1 = gets.split.map(&:to_i)
s = a1 * b1
for i in(2..n)
    a,b = gets.split.map(&:to_i)
    if(b>b1)
        s = s + (a*b1)
    else
        s = s + (a*b)
    end
    b1=b
end
p s


n = gets.to_i
arr = Array.new(n,false)
gets.split(" ").map(&:to_i).drop(1).each{ |i|
  arr[i-1] = true if i > 0
}

gets.split(" ").map(&:to_i).drop(1).each{ |i|
  arr[i-1] = true if i > 0
}

puts arr.all? ? "I become the guy." : "Oh, my keyboard!"

g=->{gets.split[1..-1]};require 'set';puts gets.to_i==Set.new(g[]+g[]).size ? 'I become the guy.':'Oh, my keyboard!'

g=->{gets.split[1..-1]};puts gets.to_i==(g[]+g[]).uniq.size ? 'I become the guy.':'Oh, my keyboard!'

levels = gets.chomp.to_i
x = gets.chomp
x = x.split
y = gets.chomp
y = y.split

array = []
x_levels = x[0].to_i
y_levels = y[0].to_i
for i in (1..x.size-1)
	if array.include?(x[i].to_i) == false && x[i].to_i != 0
		array << x[i].to_i
	end
end
for i in (1..y.size-1)
	if array.include?(y[i].to_i) == false && y[i].to_i != 0
		array << y[i].to_i
	end
end

if levels == array.size
	print "I become the guy."
else
	print "Oh, my keyboard!"
end

#puts "Enter the number of levels\n"
n = gets.to_i
#puts "Enter number of level x can pass then level number in a single line and same for y\n"
x = gets.chomp.to_s.split(" ")
y = gets.chomp.to_s.split(" ")
a = []
l = x.length
m = 0
for i in 1...l do
    a[m] = x[i].to_i
    m += 1
end
for j in 1...y.length do
    a[m+j-1] = y[j].to_i
end
a = a.sort
w = a.length
v = 1
r = [n]
for h in 1..n do
    c = 0
    d = 0
    for k in 0...w do
        if h != a[k]
            c += 0
        else
            c += 1
        end
    end
    r[h-1] = c
end
r = r.sort
#p r
if r[0] == 0
    puts "Oh, my keyboard!"
else
    puts "I become the guy."
end

n = gets.to_i
p1, p2 = gets.split(/ /).drop(1).map(&:to_i), gets.split(/ /).drop(1).map(&:to_i)
puts (p1 | p2).count == n ? "I become the guy." : "Oh, my keyboard!"

a = gets.to_i
b = gets.split.map &:to_i
c = gets.split.map &:to_i
puts (c[1..-1] | b[1..-1]).size == a ? "I become the guy." : "Oh, my keyboard!"

n = gets.to_i
if (gets.split[1..-1].map(&:to_i) | gets.split[1..-1].map(&:to_i)).size == n
	puts "I become the guy."
else
	puts "Oh, my keyboard!"
end

n = gets.to_i
x = gets.split(' ').map(&:to_i)
y = gets.split(' ').map(&:to_i)
l = []

x.drop(1).each do |i|
  if i > 0 && !l.include?(i)
    l.push(i)
  end
end

y.drop(1).each do |j|
  if j > 0 && !l.include?(j)
    l.push(j)
  end
end

puts l.length == n ? 'I become the guy.' : 'Oh, my keyboard!'

n = gets.to_i
a=gets.split.map(&:to_i)[1..-1];b=gets.split.map(&:to_i)[1..-1]
puts (a+b).uniq.size==n ? "I become the guy." : "Oh, my keyboard!"

level_count = gets.to_i
x_levels = gets.split.map &:to_i
x_levels.shift
y_levels = gets.split.map &:to_i
y_levels.shift

levels = Array.new level_count, false

x_levels.each do |element|
  levels[element - 1] = true
end

y_levels.each do |element|
  levels[element - 1] = true
end

incomplete_level = false

level_count.times do |i|
  unless levels[i]
    puts "Oh, my keyboard!"
    incomplete_level = true
    break
  end
end

puts "I become the guy." unless incomplete_level

require 'set'
n = gets.chomp.to_i
line = gets.chomp.split
set = Set.new

p = line[0].to_i
for i in 1..p
    set.add(line[i].to_i)
end

line = gets.chomp.split
p = line[0].to_i
for i in 1..p
    set.add(line[i].to_i)
end

if set == (1..n).to_a.to_set
    puts "I become the guy."
else
    puts "Oh, my keyboard!"
end

#!/usr/bin/ruby
n=gets.to_i
a=gets.split.map(&:to_i)[1..-1]+gets.split.map(&:to_i)[1..-1]
puts (1..n).all?{|i|a.include?(i)} ? 'I become the guy.' : 'Oh, my keyboard!'

n = gets.to_i
a = gets.split.map(&:to_i)[1..-1]
b = gets.split.map(&:to_i)[1..-1]

puts a.concat(b).uniq.size == n ? 'I become the guy.' : 'Oh, my keyboard!'

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

puts((a[1..-1]+b[1..-1]).sort.uniq.size == n ? 'I become the guy.' : 'Oh, my keyboard!')

require 'set'

def read_next_line
  gets.chomp.split.map(&:to_i)
end

n = gets.chomp.to_i
puts (Set.new(read_next_line[1..-1]) + read_next_line[1..-1]).size == n ? 'I become the guy.' : 'Oh, my keyboard!'

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

if ((p[1..-1] + q[1..-1]).uniq).size == n
	puts "I become the guy."
else
	puts "Oh, my keyboard!"
end

n = gets.chomp.to_i
p = gets.chomp.split(" ").map(&:to_i)
q = gets.chomp.split(" ").map(&:to_i)
p.delete_at(0)
q.delete_at(0)
res = p | q
puts res.size == n ? "I become the guy." : "Oh, my keyboard!"

n = gets.to_i
a = gets.chomp.split(' ').map(&:to_i)[1..-1]
b = gets.chomp.split(' ').map(&:to_i)[1..-1]
puts (a | b).size == n ? "I become the guy." : "Oh, my keyboard!"

n = gets.to_i

input = gets
p = input.split
p.shift

input = gets
q = input.split
q.shift

# puts pn
n.times

p.each { |elem| q.push(elem) }

q.uniq!

puts q.count == n ? "I become the guy." : "Oh, my keyboard!"

#! /usr/bin/env ruby
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2014 Szymon Sliwa <knight.erraunt@gmail.com>
#
# Distributed under terms of the MIT license.

n = gets.to_i
p, *tab_p = gets.split.map(&:to_i)
q, *tab_q = gets.split.map(&:to_i)

tab = tab_p + tab_q
tab.sort!.uniq!

if tab == (1..n).to_a
    puts "I become the guy."
else
    puts "Oh, my keyboard!"
end

n = STDIN.gets.to_i
levels_of_x = STDIN.gets.to_s.split(' ').map(&:to_i)
levels_of_x.shift
levels_of_y = STDIN.gets.to_s.split(' ').map(&:to_i)
levels_of_y.shift

result = (1..n).to_a.all? do |i|
  levels_of_x.include?(i) || levels_of_y.include?(i)
end

puts result ? 'I become the guy.' : 'Oh, my keyboard!'

g=->{gets.split[1..-1]};puts gets.to_i==(g[]+g[]).uniq.size ? 'I become the guy.':'Oh, my keyboard!'

n = gets.chomp.to_i
xPass = gets.chomp.split(' ').map {|item| item.to_i}
yPass = gets.chomp.split(' ').map {|item| item.to_i}
xPass.delete_at(0)
yPass.delete_at(0)
xPass.sort!
yPass.sort!
xPass.uniq!
yPass.uniq!
flag = true

(1..n).each do |stage|
	flag = false if xPass.count(stage) == 0 && yPass.count(stage) == 0
end

puts "I become the guy." if flag
puts "Oh, my keyboard!" if !flag

n = STDIN.readline.to_i
ps = STDIN.readline.split.map {|s| s.to_i }[1..-1]
qs = STDIN.readline.split.map {|s| s.to_i }[1..-1]
mark = {}
[ps, qs].each do |xs|
	xs.each {|x| mark[x] = true }
end
(1..n).each do |i|
	if mark[i] == nil
		puts 'Oh, my keyboard!'
		exit
	end
end
puts "I become the guy."

level = gets.chomp.to_i
input_x, input_y = gets.chomp.split(" "), gets.chomp.split(" ")
counter = {}
game = []
for i in 1..input_x[0].to_i
  game << input_x[i]
end
for i in 1..input_y[0].to_i
  game << input_y[i]
end
for i in 0...game.length
  counter[game[i]] = 1
end
sum = 0
counter.each do |key, value|
  sum += value
end
if sum == level
  puts "I become the guy."
else
  puts "Oh, my keyboard!"
end

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

a.shift
b.shift

t = (a+b).uniq
t.sort!

puts (1..n).to_a==t ? "I become the guy." : "Oh, my keyboard!"

arr = []
n = gets.to_i
2.times do
  arr.push(gets.chomp.split[1..-1].map &:to_i)
end
arr = arr.inject(:+).uniq
puts arr.size == n ? "I become the guy." : "Oh, my keyboard!"

n = gets.to_i
a = gets.split.map(&:to_i)[1..-1]
b = gets.split.map(&:to_i)[1..-1]
m = Array.new(n, 0)

a.each { |x|
	m[x-1] = 1
}

b.each { |x|
	m[x-1] = 1
}

sum = 0
for i in 0...n
	sum += m[i]
end
if (sum == n)
	puts "I become the guy."
else
	puts "Oh, my keyboard!"
end

k = gets.to_i
a = gets.split(" ").map(&:to_i)
b = gets.split(" ").map(&:to_i)
a << k+2
b << k+2
n = a[0]
m = b[0]
a[0]=b[0]=0
a.sort!
b.sort!
i = j = cur = 1
while i<=n || j<=m
  while cur > a[i] do
    i+=1;
  end
  while cur > b[j] do
    j+=1;
  end
  if cur == a[i] || cur == b[j]
    cur+=1;
  else
    break
  end
end
if cur == k+1
  puts "I become the guy."
else
  puts "Oh, my keyboard!"
end

levels = gets.chomp.to_i
x = gets.chomp.split(/ /).map(&:to_i)
y = gets.chomp.split(/ /).map(&:to_i)
p, q = x[0], y[0]
x_levels = x[1..p]
y_levels = y[1..q]
total_levels = x_levels + y_levels
total_levels.uniq!
total_levels.sort!
passed = true
(1..levels).each do |level|
    next if total_levels[level - 1] == level
    passed = false
    break
end
if passed
    puts "I become the guy."
else
    puts "Oh, my keyboard!"
end

n=(1..gets.to_i).to_a
x=gets.split.map{|e| e.to_i}
y=gets.split.map{|e| e.to_i}
x[0]=0
y[0]=0
puts (n-x-y).size==0?"I become the guy.":"Oh, my keyboard!"

n = gets.chomp.to_i

levels1 = gets.chomp.split(' ').map{|a| a.to_i}
levels2 = gets.chomp.split(' ').map{|a| a.to_i}

levels1.shift
levels2.shift

if levels1.concat(levels2).uniq.sort == (1..n).to_a
  puts "I become the guy."
else
  puts "Oh, my keyboard!"
end

levels = [false] * gets.to_i
x = gets.split.map(&:to_i)
x.shift
y = gets.split.map(&:to_i)
y.shift

x.each { |l| levels[l - 1] = true }
y.each { |l| levels[l - 1] = true }

if levels.all?
  puts 'I become the guy.'
else
  puts 'Oh, my keyboard!'
end

n = gets.to_i
x = gets.split.map(&:to_i)
y = gets.split.map(&:to_i)
x.delete_at(0)
y.delete_at(0)
for i in x
	y.delete_at(y.index(i)) if !y.index(i).nil?
end
s = (1+n)/2.0*n
x = x+y
sum = 0
for i in x
	sum+=i
end
puts sum == s ? "I become the guy." : "Oh, my keyboard!"

n=gets.chomp.to_i
a = gets.chomp.strip.split
b = gets.chomp.strip.split
a=a[1..-1]
b=b[1..-1]
puts ((a+b).uniq-['0']).length == n ? "I become the guy." : "Oh, my keyboard!"

n = gets.chomp.to_i
x = gets.chomp.split(' ').map(&:to_i).drop(1)
y = gets.chomp.split(' ').map(&:to_i).drop(1)

s = (x + y).uniq

if s.size == n
  puts "I become the guy."
else
  puts "Oh, my keyboard!"
end

require 'set';puts gets.to_i==Set.new(gets.split[1..-1]+gets.split[1..-1]).size ? 'I become the guy.':'Oh, my keyboard!'

g=->{gets.split[1..-1]};puts gets.to_i==(g[]+g[]).uniq ? 'I become the guy.':'Oh, my keyboard!'

levels = gets.chomp.to_i
x = gets.chomp
x = x.split
y = gets.chomp
y = y.split

array = []
for i in (0..x.size-1)
	if array.include?(x[i].to_i) == false && x[i].to_i != 0
		array << x[i].to_i
	end
end
for i in (0..y.size-1)
	if array.include?(y[i].to_i) == false && y[i].to_i != 0
		array << y[i].to_i
	end
end

if levels == array.size
	print "I become the guy."
else
	print "Oh, my keyboard!"
end

n = gets.to_i
arr = Array.new(n,false)
gets.split(" ").map(&:to_i).each{ |i|
  arr[i-1] = true if i > 0
}

gets.split(" ").map(&:to_i).each{ |i|
  arr[i-1] = true if i > 0
}

puts arr.all? ? "I become the guy." : "Oh, my keyboard!"

n = gets.to_i
arr = Array.new(n,false)
gets.split(" ").map(&:to_i).each{ |i|
  arr[i-1] = true
}

gets.split(" ").map(&:to_i).each{ |i|
  arr[i-1] = true
}

puts arr.all? ? "I become the guy." : "Oh, my keyboard!"

a = gets.to_i
b = gets.split.map &:to_i
c = gets.split.map &:to_i
d = (b.uniq + c.uniq).sort
f = true
(1..a).map {|x| f = d.include?(x)}
puts f ? "I become the guy." : "Oh, my keyboard!"

a = gets.to_i
b = gets.split.map &:to_i
c = gets.split.map &:to_i
puts (b + c).uniq.size == a ? "I become the guy." : "Oh, my keyboard!"

a = gets.to_i
b = gets.split.map &:to_i
c = gets.split.map &:to_i
puts (c | b).size == a ? "I become the guy." : "Oh, my keyboard!"

n = gets.to_i
x = gets.split(' ').map(&:to_i)
# x.shift
y = gets.split(' ').map(&:to_i)
l = []

x.drop(1).each do |i|
  if i > 0 && !l.include?(i)
    l.push(i)
  end
end

y.each do |j|
  if j > 0 && !l.include?(j)
    l.push(j)
  end
end

puts l.length == n ? 'I become the guy.' : 'Oh, my keyboard!'

n = gets.to_i
a=gets.split.map(&:to_i);b=gets.split.map(&:to_i)
p (a+b).uniq.size==4?"I become the guy.":"Oh, my keyboard!"

n = gets.to_i
a=gets.split.map(&:to_i);b=gets.split.map(&:to_i)
puts (a+b).uniq.size==n ? "I become the guy." : "Oh, my keyboard!"

n = gets.to_i
a=gets.split.map(&:to_i);b=gets.split.map(&:to_i)
puts (a+b).uniq.size==4?"I become the guy.":"Oh, my keyboard!"

n = gets.to_i
a=gets.split.map(&:to_i);b=gets.split.map(&:to_i);a.delete(0);b.delete(0)
puts a.concat(b).uniq.size==n ? "I become the guy." : "Oh, my keyboard!"

require 'set'
n = gets.chomp.to_i
line = gets.chomp.split
p = line[0].to_i
set = Set.new

for i in 1..p
    set.add(line[i].to_i)
end

line = gets.chomp.split
for i in 0..p-1
    set.add(line[i].to_i)
end

if set == (1..n).to_a.to_set
    puts "I become the guy."
else
    puts "Oh, my keyboard!"
end

n = STDIN.gets.to_i
levels_of_x = STDIN.gets.to_s.split(' ').map(&:to_i)
levels_of_x.shift
levels_of_y = STDIN.gets.to_s.split(' ').map(&:to_i)
levels_of_y.shift

result = (1..n).to_a.all? do |i|
  levels_of_x.include?(i) || levels_of_y.include?(i)
end

puts result ? 'I became the guy.' : 'Oh, my keyboard!'

n = gets.chomp.to_i
xPass = gets.chomp.split(' ').map {|item| item.to_i}
yPass = gets.chomp.split(' ').map {|item| item.to_i}
xPass.sort!
yPass.sort!
xPass.uniq!
yPass.uniq!
flag = true

(1..n).each do |stage|
	flag = false if xPass.count(stage) == 0 && yPass.count(stage) == 0
end

puts "I become the guy." if flag
puts "Oh, my keyboard!" if !flag

n = gets.to_i
x = gets.split.map(&:to_i)
y = gets.split.map(&:to_i)
x.delete_at(0)
y.delete_at(0)
for i in x
	y.delete_at(y.index(i)) if y.index(i)
end
s = (1+n)/2.0*n
x = x+y
sum = 0
for i in x
	sum+=i
end
puts sum == s ? "I become the guy" : "Oh, my keyboard!"

level = gets.chomp.to_i
little_x, little_y = gets.chomp.split(" "), gets.chomp.split(" ")
game = little_x + little_y
game.map! {|i| i.to_i}
if game.max >= level
  puts "I become the guy."
else
  puts "Oh, my keyboard!"
end

level = gets.chomp.to_i
little_x, little_y = gets.chomp.split(" "), gets.chomp.split(" ")
game = (little_x + little_y)
if game.max.to_i == level
  puts "I become the guy."
else
  puts "Oh, my keyboard!"
end

level = gets.chomp.to_i
little_x, little_y = gets.chomp.split(" "), gets.chomp.split(" ")
game = little_x + little_y
counter = {}
for i in 0...game.length
  counter[game[i]] = 1
end
sum = 0
counter.each do |key, value|
  sum += value
end
if sum == level
  puts "I become the guy."
else
  puts "Oh, my keyboard!"
end

level = gets.chomp.to_i
little_x, little_y = gets.chomp.split(" "), gets.chomp.split(" ")
game = little_x + little_y
counter = {}
for i in 0...game.length
  if game[i] != '0'
    counter[game[i]] = 1
  end
end
sum = 0
counter.each do |key, value|
  sum += value
end
if sum == level
  puts "I become the guy."
else
  puts "Oh, my keyboard!"
end

arr = []
n = gets.to_i
2.times do
  arr.push(gets.chomp.split.map &:to_i)
end
arr = arr.inject(:+)
arr = arr - [0]
puts arr.uniq.size == n ? "I become the guy." : "Oh, my keyboard!"

arr = []
n = gets.to_i
2.times do
  arr.push(gets.chomp[1..-1])
end
arr = arr.inject(:+)
arr = arr.split.map &:to_i
puts arr.uniq.size == n ? "I become the guy." : "Oh, my keyboard!"

arr = []
n = gets.to_i
2.times do
  arr.push(gets.chomp.split.map &:to_i)
end
arr = arr.inject(:+)
puts arr.uniq.size == n ? "I become the guy." : "Oh, my keyboard!"

n = gets.to_i
a = gets.split(" ").map(&:to_i)
b = gets.split(" ").map(&:to_i)
a << n+2
b << n+2
n = a[0]
m = b[0]
i = j = cur = 1
while i<=n || j<=m
  while cur > a[i] do
    i+=1;
  end
  while cur > b[j] do
    j+=1;
  end
  if cur == a[i] || cur == b[j]
    cur+=1;
  else
    break
  end
end
if cur = n+1
  puts "I become the guy."
else
  puts "Oh, my keyboard!"
end

k = gets.to_i
a = gets.split(" ").map(&:to_i)
b = gets.split(" ").map(&:to_i)
a << k+2
b << k+2
n = a[0]
m = b[0]
i = j = cur = 1
while i<=n || j<=m
  while cur > a[i] do
    i+=1;
  end
  while cur > b[j] do
    j+=1;
  end
  if cur == a[i] || cur == b[j]
    cur+=1;
  else
    break
  end
end
if cur == k+1
  puts "I become the guy."
else
  puts "Oh, my keyboard!"
end

levels = gets.chomp.to_i
x = gets.chomp.split(/ /).map(&:to_i)
y = gets.chomp.split(/ /).map(&:to_i)
if x.include?( levels ) || y.include?( levels )
    puts "I become the guy."
else
    puts "Oh, my keyboard!"
end

levels = gets.chomp.to_i
x = gets.chomp.split(/ /).map(&:to_i)
y = gets.chomp.split(/ /).map(&:to_i)
p, q = x[0], y[0]
x_levels = x[1..p]
y_levels = y[1..q]
if x_levels.include?( levels ) || y_levels.include?( levels )
    puts "I become the guy."
else
    puts "Oh, my keyboard!"
end

n = gets.chomp.to_i

levels1 = gets.chomp.split(' ').map{|a| a.to_i}
levels2 = gets.chomp.split(' ').map{|a| a.to_i}

levels1.delete(0)
levels2.delete(0)

if levels1.concat(levels2).uniq.sort == (1..n).to_a
  puts "I become the guy."
else
  puts "Oh, my keyboard!"
end

n = gets.chomp.to_i

levels1 = gets.chomp.split(' ').map{|a| a.to_i}
levels2 = gets.chomp.split(' ').map{|a| a.to_i}

if levels1.concat(levels2).uniq.count >= n
  puts "I become the guy."
else
  puts "Oh, my keyboard!"
end

n = gets.chomp.to_i

levels1 = gets.chomp.split(' ').map{|a| a.to_i}
levels2 = gets.chomp.split(' ').map{|a| a.to_i}

if (levels1.concat(levels2).uniq.count == n)
  puts "I become the guy."
else
  puts "Oh, my keyboard!"
end

levels = [false] * gets.to_i
x = gets.split.map(&:to_i)
x.shift
y = gets.split.map(&:to_i)
y.shift

x.each { |l| levels[l - 1] = true }
y.each { |l| levels[l - 1] = true }

if x.all?
  puts 'I become the guy.'
else
  puts 'Oh, my keyboard!'
end

n=gets.chomp.to_i
a = gets.chomp.strip.split
b = gets.chomp.strip.split
puts ((a+b).uniq-['0']).length == n ? "I become the guy." : "Oh, my keyboard!"

n=gets.chomp.to_i
a = gets.chomp.strip.split
b = gets.chomp.strip.split
puts (a+b).uniq.length == n ? "I become the guy." : "Oh, my keyboard!"

n=gets.chomp.to_i
a = gets.chomp.strip.split
b = gets.chomp.strip.split
puts (a+b).uniq.length == 4? "I become the guy." : "Oh, my keyboard!"

n = gets.chomp.to_i
x = gets.chomp.split(' ').map(&:to_i).drop(1)
y = gets.chomp.split(' ').map(&:to_i)

s = (x + y).uniq

if s.size == n
  puts "I become the guy."
else
  puts "Oh, my keyboard!"
end


class Widget
	def initialize(type, width = 0, height = 0)
		@type = type.to_sym
		@border = @spacing = 0
		@lazy = false
		@width = width.to_i
		@height = height.to_i
		@elements = []
	end
	def process
		@lazy = true
		return if @type == :W
		@height = @width = 0
		return if @elements.size == 0
		@elements.each{|e|
			if @type == :V
				@height += e.height
				@width = [@width, e.width].max
			else
				@height = [@height, e.height].max
				@width += e.width
			end
		}
		if @type == :V
			@height += 2 * @border + (@elements.size - 1) * @spacing
			@width += 2 * @border
		else @type == :H
			@height += 2 * @border
			@width += 2 * @border + (@elements.size - 1) * @spacing
		end
	end

	def height
		process unless @lazy
		@height
	end

	def width
		process unless @lazy
		@width
	end

	def pack(w)
		@elements.push $w[w.to_sym]
	end

	def set_border(v)
		@border = v.to_i
	end

	def set_spacing(v)
		@spacing = v.to_i
	end
end
$w = {}
gets.to_i.times{|x|
	cmd = gets
	if (cmd[0]>='a' and cmd[0] <= 'z')
		name, fc = cmd.split '.'
		#puts name, fc
		fc,arg = fc.split '('
		arg = arg.split(')')[0]
		#puts fc
		$w[name.to_sym].send fc.to_sym, *arg.split(',')
	else
		if (cmd[0]=='W')
			cmd = cmd.split(' ')[1]
			name,arg = cmd.split '('
			arg = arg.split(')')[0]
			$w[name.to_sym] = Widget.new(:W, *(arg.split(',')))
		else
		if (cmd[0]=='V' || cmd[0] == 'H')
			name = cmd.split(' ')[1]
			$w[name.to_sym] = Widget.new(cmd[0].to_sym)
		end
	end
	end
}

$w.keys.sort.each{|k|
	puts "#{k} #{$w[k].width} #{$w[k].height}"
}

class Box
	attr_accessor :border, :spacing

	def initialize(type, width, height)
		@type = type
		@border = 0
		@spacing = 0
		@repaint = false
		@width = width
		@height = height
		@element = []
	end

	def repaint
		@repaint = true
		return if @type == 'W'
		@height = @width = 0
		if @element.size > 0
			if @type == 'V'
				@element.each do |e|
					@height += e.height
					@width = [@width, e.width].max
				end
				@height += 2 * border + (@element.size - 1) * spacing
				@width += 2 * border
			elsif @type == 'H'
				@element.each do |e|
					@height = [@height, e.height].max
					@width += e.width
				end
				@height += 2 * border
				@width += 2 * border + (@element.size - 1) * spacing
			end
		end
	end

	def height
		repaint unless @repaint
		@height
	end

	def width
		repaint unless @repaint
		@width
	end

	def pack(w)
		@element << w
	end
end

w = {}

gets.to_i.times do
	$_ = gets.chomp
	if /Widget (\w+)\((\d+),(\d+)\)/
		w[$1] = Box.new('W', $2.to_i, $3.to_i)
	elsif /(V|H)Box (\w+)/
		w[$2] = Box.new($1, 0, 0)
	elsif /(\w+)\.set_border\((\d+)\)/
		w[$1].border = $2.to_i
	elsif /(\w+)\.set_spacing\((\d+)\)/
		w[$1].spacing = $2.to_i
	elsif /(\w+)\.pack\((\w+)\)/
		w[$1].pack(w[$2])
	else
		puts "ERROR: $_\n"
	end
end

w.keys.sort.each do |k|
	puts "#{k} #{w[k].width} #{w[k].height}"
end