You have a garden consisting entirely of grass and weeds. Your garden is described by an n × m grid, with rows numbered 1 to n from top to bottom, and columns 1 to m from left to right. Each cell is identified by a pair (r, c) which means that the cell is located at row r and column c. Each cell may contain either grass or weeds. For example, a 4 × 5 garden may look as follows (empty cells denote grass):  You have a land-mower with you to mow all the weeds. Initially, you are standing with your lawnmower at the top-left corner of the garden. That is, at cell (1, 1). At any moment of time you are facing a certain direction — either left or right. And initially, you face right.In one move you can do either one of these:1) Move one cell in the direction that you are facing.  if you are facing right: move from cell (r, c) to cell (r, c + 1)     if you are facing left: move from cell (r, c) to cell (r, c - 1)    2) Move one cell down (that is, from cell (r, c) to cell (r + 1, c)), and change your direction to the opposite one.  if you were facing right previously, you will face left     if you were facing left previously, you will face right    You are not allowed to leave the garden. Weeds will be mowed if you and your lawnmower are standing at the cell containing the weeds (your direction doesn't matter). This action isn't counted as a move.What is the minimum number of moves required to mow all the weeds?

The first line contains two integers n and m (1 ≤ n, m ≤ 150) — the number of rows and columns respectively. Then follow n lines containing m characters each — the content of the grid. "G" means that this cell contains grass. "W" means that this cell contains weeds.  It is guaranteed that the top-left corner of the grid will contain grass.

Print a single number — the minimum number of moves required to mow all the weeds.

NoteFor the first example, this is the picture of the initial state of the grid:  A possible solution is by mowing the weeds as illustrated below:

# -*- 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


You are given a rectangular grid with $$$n$$$ rows and $$$m$$$ columns. The cell located on the $$$i$$$-th row from the top and the $$$j$$$-th column from the left has a value $$$a_{ij}$$$ written in it.You can perform the following operation any number of times (possibly zero):  Choose any two adjacent cells and multiply the values in them by $$$-1$$$. Two cells are called adjacent if they share a side. Note that you can use a cell more than once in different operations.You are interested in $$$X$$$, the sum of all the numbers in the grid. What is the maximum $$$X$$$ you can achieve with these operations?

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first line of each test case contains two integers $$$n$$$,$$$m$$$ ($$$2 \le n$$$, $$$m \le 10$$$).  The following $$$n$$$ lines contain $$$m$$$ integers each, the $$$j$$$-th element in the $$$i$$$-th line is $$$a_{ij}$$$ ($$$-100\leq a_{ij}\le 100$$$).

For each testcase, print one integer $$$X$$$, the maximum possible sum of all the values in the grid after applying the operation as many times as you want.

NoteIn the first test case, there will always be at least one $$$-1$$$, so the answer is $$$2$$$. In the second test case, we can use the operation six times to elements adjacent horizontally and get all numbers to be non-negative. So the answer is: $$$2\times 1 + 3\times2 + 3\times 3 + 2\times 4 + 1\times 5 = 30$$$.

t = gets.chomp.to_i
t.times do
  n, m = gets.chomp.split(' ').map(&:to_i)
  arr = []
  n.times do
    arr << gets.chomp.split(' ').map(&:to_i)
  end
  arr = arr.flatten
  mn = arr.count {|el| el < 0}
  if arr.find{|el| el == 0}
    puts arr.map{|el| el.abs}.sum
  else
    arr = arr.map{|el| el.abs}
    arr = arr.sort
    if mn % 2 == 0
      puts arr.sum
    else
      puts arr[1..].sum - arr[0]
    end
  end
end

t = gets.chomp.to_i
t.times do
  n, m = gets.chomp.split(' ').map(&:to_i)
  arr = []
  n.times do
    arr << gets.chomp.split(' ').map(&:to_i)
  end
  arr = arr.flatten
  if arr.find{|el| el == 0}
    puts arr.map{|el| el.abs}.sum
  else
    arr = arr.map{|el| el.abs}
    arr = arr.sort
    puts (arr[0] * -1) + arr[1..].sum
  end
end

t = gets.chomp.to_i
t.times do
  n, m = gets.chomp.split(' ').map(&:to_i)
  arr = []
  n.times do
    arr << gets.chomp.split(' ').map(&:to_i)
  end
  arr = arr.flatten
  if arr.find{|el| el == 0}
    puts arr.map{|el| el.abs}.sum
  else
    arr = arr.map{|el| el.abs}
    arr = arr.sort
    mn = arr.count {|el| el < 0}
    puts (arr[0..mn].sum * -1) + arr[(mn + 1)..].sum
  end
end

t = gets.chomp.to_i
t.times do
  n, m = gets.chomp.split(' ').map(&:to_i)
  arr = []
  n.times do
    arr << gets.chomp.split(' ').map(&:to_i)
  end
  arr = arr.flatten
  if arr.find{|el| el == 0}
    puts arr.map{|el| el.abs}.sum
  else
    arr = arr.map{|el| el.abs}
    arr = arr.sort
    mn = arr.count {|el| el < 0}
    if mn % 2 == 0
      puts arr.sum
    else
      puts arr[1..].sum - arr[0].sum
    end
  end
end


The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row.Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all the houses with larger numbers. In other words, a house is luxurious if the number of floors in it is strictly greater than in all the houses, which are located to the right from it. In this task it is assumed that the heights of floors in the houses are the same.The new architect is interested in n questions, i-th of them is about the following: "how many floors should be added to the i-th house to make it luxurious?" (for all i from 1 to n, inclusive). You need to help him cope with this task.Note that all these questions are independent from each other — the answer to the question for house i does not affect other answers (i.e., the floors to the houses are not actually added).

The first line of the input contains a single number n (1 ≤ n ≤ 105) — the number of houses in the capital of Berland. The second line contains n space-separated positive integers hi (1 ≤ hi ≤ 109), where hi equals the number of floors in the i-th house.

Print n integers a1, a2, ..., an, where number ai is the number of floors that need to be added to the house number i to make it luxurious. If the house is already luxurious and nothing needs to be added to it, then ai should be equal to zero. All houses are numbered from left to right, starting from one.

#!/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(' ')}"


A map of some object is a rectangular field consisting of n rows and n columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly k islands appear on the map. We will call a set of sand cells to be island if it is possible to get from each of them to each of them by moving only through sand cells and by moving from a cell only to a side-adjacent cell. The cells are called to be side-adjacent if they share a vertical or horizontal side. It is easy to see that islands do not share cells (otherwise they together form a bigger island).Find a way to cover some cells with sand so that exactly k islands appear on the n × n map, or determine that no such way exists.

The single line contains two positive integers n, k (1 ≤ n ≤ 100, 0 ≤ k ≤ n2) — the size of the map and the number of islands you should form.

If the answer doesn't exist, print "NO" (without the quotes) in a single line. Otherwise, print "YES" in the first line. In the next n lines print the description of the map. Each of the lines of the description must consist only of characters 'S' and 'L', where 'S' is a cell that is occupied by the sea and 'L' is the cell covered with sand. The length of each line of the description must equal n. If there are multiple answers, you may print any of them. You should not maximize the sizes of islands.

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.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, 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,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


Polycarp has built his own web service. Being a modern web service it includes login feature. And that always implies password security problems.Polycarp decided to store the hash of the password, generated by the following algorithm:  take the password $$$p$$$, consisting of lowercase Latin letters, and shuffle the letters randomly in it to obtain $$$p'$$$ ($$$p'$$$ can still be equal to $$$p$$$);  generate two random strings, consisting of lowercase Latin letters, $$$s_1$$$ and $$$s_2$$$ (any of these strings can be empty);  the resulting hash $$$h = s_1 + p' + s_2$$$, where addition is string concatenation. For example, let the password $$$p =$$$ "abacaba". Then $$$p'$$$ can be equal to "aabcaab". Random strings $$$s1 =$$$ "zyx" and $$$s2 =$$$ "kjh". Then $$$h =$$$ "zyxaabcaabkjh".Note that no letters could be deleted or added to $$$p$$$ to obtain $$$p'$$$, only the order could be changed.Now Polycarp asks you to help him to implement the password check module. Given the password $$$p$$$ and the hash $$$h$$$, check that $$$h$$$ can be the hash for the password $$$p$$$.Your program should answer $$$t$$$ independent test cases.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains a non-empty string $$$p$$$, consisting of lowercase Latin letters. The length of $$$p$$$ does not exceed $$$100$$$. The second line of each test case contains a non-empty string $$$h$$$, consisting of lowercase Latin letters. The length of $$$h$$$ does not exceed $$$100$$$.

For each test case print the answer to it — "YES" if the given hash $$$h$$$ could be obtained from the given password $$$p$$$ or "NO" otherwise.

5
abacaba
zyxaabcaabkjh
onetwothree
threetwoone
one
zzonneyy
one
none
twenty
ten

NoteThe first test case is explained in the statement.In the second test case both $$$s_1$$$ and $$$s_2$$$ are empty and $$$p'=$$$ "threetwoone" is $$$p$$$ shuffled.In the third test case the hash could not be obtained from the password.In the fourth test case $$$s_1=$$$ "n", $$$s_2$$$ is empty and $$$p'=$$$ "one" is $$$p$$$ shuffled (even thought it stayed the same). In the fifth test case the hash could not be obtained from the password.

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

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

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

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


Valera had two bags of potatoes, the first of these bags contains x (x ≥ 1) potatoes, and the second — y (y ≥ 1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains x potatoes) Valera lost. Valera remembers that the total amount of potatoes (x + y) in the two bags, firstly, was not gerater than n, and, secondly, was divisible by k.Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order.

The first line of input contains three integers y, k, n (1 ≤ y, k, n ≤ 109;   ≤ 105).

Print the list of whitespace-separated integers — all possible values of x in ascending order. You should print each possible value of x exactly once. If there are no such values of x print a single integer -1.

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.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

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(" ").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.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

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

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


You have an image file of size $$$2 \times 2$$$, consisting of $$$4$$$ pixels. Each pixel can have one of $$$26$$$ different colors, denoted by lowercase Latin letters.You want to recolor some of the pixels of the image so that all $$$4$$$ pixels have the same color. In one move, you can choose no more than two pixels of the same color and paint them into some other color (if you choose two pixels, both should be painted into the same color).What is the minimum number of moves you have to make in order to fulfill your goal?

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. Each of these lines contains two lowercase letters of Latin alphabet without any separators, denoting a row of pixels in the image.

For each test case, print one integer — the minimum number of moves you have to make so that all $$$4$$$ pixels of the image have the same color.

5

rb

br

cc

wb

aa

aa

ab

cd

yy

xx

NoteLet's analyze the test cases of the example.In the first test case, you can paint the bottom left pixel and the top right pixel (which share the same color) into the color r, so all pixels have this color.In the second test case, two moves are enough:  paint both top pixels, which have the same color c, into the color b;  paint the bottom left pixel into the color b. In the third test case, all pixels already have the same color.In the fourth test case, you may leave any of the pixels unchanged, and paint all three other pixels into the color of that pixel in three moves.In the fifth test case, you can paint both top pixels into the color x.

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
}

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

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)
}


Today, Marin is at a cosplay exhibition and is preparing for a group photoshoot!For the group picture, the cosplayers form a horizontal line. A group picture is considered beautiful if for every contiguous segment of at least $$$2$$$ cosplayers, the number of males does not exceed the number of females (obviously).Currently, the line has $$$n$$$ cosplayers which can be described by a binary string $$$s$$$. The $$$i$$$-th cosplayer is male if $$$s_i = 0$$$ and female if $$$s_i = 1$$$. To ensure that the line is beautiful, you can invite some additional cosplayers (possibly zero) to join the line at any position. You can't remove any cosplayer from the line.Marin wants to know the minimum number of cosplayers you need to invite so that the group picture of all the cosplayers is beautiful. She can't do this on her own, so she's asking you for help. Can you help her?

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases.  The first line of each test case contains a positive integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of cosplayers in the initial line. The second line of each test case contains a binary string $$$s$$$ of length $$$n$$$ — describing the cosplayers already in line. Each character of the string is either 0 describing a male, or 1 describing a female. Note that there is no limit on the sum of $$$n$$$.

For each test case, print the minimum number of cosplayers you need to invite so that the group picture of all the cosplayers is beautiful.

NoteIn the first test case, for each pair of adjacent cosplayers, you can invite two female cosplayers to stand in between them. Then, $$$000 \rightarrow 0110110$$$.In the third test case, you can invite one female cosplayer to stand next to the second cosplayer. Then, $$$010 \rightarrow 0110$$$.

t = gets.to_i
while t > 0
    t = t - 1
    n = gets.to_i
    s = gets
    ans = 0
    for index in 0..n - 1

        if index  < n - 1 && s[index] == s[index + 1] && s[index] == '0'
           ans += 2
        end
        if(index < n - 2 && s[index] == s[index + 2] && s[index] != s[index + 1] && s[index + 1] == '1')
            ans += 1
        end
    end

    puts ans
end

t = gets.to_i
while t > 0
    t = t - 1
    n = gets.to_i
    s = gets
    ones , zeros , ans = 0 , 0 , 0
    for index in 0..n - 1
        if s[index] == '0'
           zeros = zeros + 1
        else
            ones = ones + 1
        end
        if index  < n - 1 && s[index] == s[index + 1] && s[index] == '0'
           ans += 2
           ones += 2
        end
        if(index < n - 2 && s[index] == s[index + 2] && s[index] != s[index + 1] && s[index + 1] == '1')
            ans += 1
            ones += 1
        end
    end
    if zeros > ones
        ans = ans + (zeros - ones)
    end
    puts ans
end


You are given two integers $$$a$$$ and $$$b$$$. Print $$$a+b$$$.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is given as a line of two integers $$$a$$$ and $$$b$$$ ($$$-1000 \le a, b \le 1000$$$).

Print $$$t$$$ integers — the required numbers $$$a+b$$$.

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

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

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

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

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


This is an interactive problem.The jury has a permutation $$$p$$$ of length $$$n$$$ and wants you to guess it. For this, the jury created another permutation $$$q$$$ of length $$$n$$$. Initially, $$$q$$$ is an identity permutation ($$$q_i = i$$$ for all $$$i$$$).You can ask queries to get $$$q_i$$$ for any $$$i$$$ you want. After each query, the jury will change $$$q$$$ in the following way:   At first, the jury will create a new permutation $$$q'$$$ of length $$$n$$$ such that $$$q'_i = q_{p_i}$$$ for all $$$i$$$.  Then the jury will replace permutation $$$q$$$ with pemutation $$$q'$$$. You can make no more than $$$2n$$$ queries in order to quess $$$p$$$.

The first line of input contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases.

NoteIn the first test case the hidden permutation $$$p = [4, 2, 1, 3]$$$.Before the first query $$$q = [1, 2, 3, 4]$$$ so answer for the query will be $$$q_3 = 3$$$.Before the second query $$$q = [4, 2, 1, 3]$$$ so answer for the query will be $$$q_2 = 2$$$.Before the third query $$$q = [3, 2, 4, 1]$$$ so answer for the query will be $$$q_4 = 1$$$.In the second test case the hidden permutation $$$p = [1, 3, 4, 2]$$$.Empty strings are given only for better readability. There will be no empty lines in the testing system.

gets.to_i.times do
  n = gets.to_i
  p = Array.new(n + 1)

  (1..n).each do |i|
    next if p[i]

    prev = nil
    loop do
      puts "? #{i}"
      $stdout.flush

      x = gets.to_i

      if prev
        p[prev] = x
      end

      break if p[x]
      prev = x
    end
  end

  p[0] = '!'
  puts p.join(' ')
  $stdout.flush
end


Each year in the castle of Dwarven King there is a competition in growing mushrooms among the dwarves. The competition is one of the most prestigious ones, and the winner gets a wooden salad bowl. This year's event brought together the best mushroom growers from around the world, so we had to slightly change the rules so that the event gets more interesting to watch.Each mushroom grower has a mushroom that he will grow on the competition. Under the new rules, the competition consists of two parts. The first part lasts t1 seconds and the second part lasts t2 seconds. The first and the second part are separated by a little break.After the starting whistle the first part of the contest starts, and all mushroom growers start growing mushrooms at once, each at his individual speed of vi meters per second. After t1 seconds, the mushroom growers stop growing mushrooms and go to have a break. During the break, for unexplained reasons, the growth of all mushrooms is reduced by k percent. After the break the second part of the contest starts and all mushrooms growers at the same time continue to grow mushrooms, each at his individual speed of ui meters per second. After a t2 seconds after the end of the break, the competition ends. Note that the speeds before and after the break may vary.Before the match dwarf Pasha learned from all participants, what two speeds they have chosen. However, the participants did not want to disclose to him all their strategy and therefore, did not say in what order they will be using these speeds. That is, if a participant chose speeds ai and bi, then there are two strategies: he either uses speed ai before the break and speed bi after it, or vice versa.Dwarf Pasha really wants to win the totalizer. He knows that each participant chooses the strategy that maximizes the height of the mushroom. Help Dwarf Pasha make the final table of competition results.The participants are sorted in the result table by the mushroom height (the participants with higher mushrooms follow earlier in the table). In case of equal mushroom heights, the participants are sorted by their numbers (the participants with a smaller number follow earlier).

The first input line contains four integer numbers n, t1, t2, k (1 ≤ n, t1, t2 ≤ 1000; 1 ≤ k ≤ 100) — the number of participants, the time before the break, the time after the break and the percentage, by which the mushroom growth drops during the break, correspondingly. Each of the following n lines contains two integers. The i-th (1 ≤ i ≤ n) line contains space-separated integers ai, bi (1 ≤ ai, bi ≤ 1000) — the speeds which the participant number i chose.

Print the final results' table: n lines, each line should contain the number of the corresponding dwarf and the final maximum height of his mushroom with exactly two digits after the decimal point. The answer will be considered correct if it is absolutely accurate.

Note  First example: for each contestant it is optimal to use firstly speed 2 and afterwards speed 4, because 2·3·0.5 + 4·3 > 4·3·0.5 + 2·3.

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

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|
    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


Mishka has got n empty boxes. For every i (1 ≤ i ≤ n), i-th box is a cube with side length ai.Mishka can put a box i into another box j if the following conditions are met:  i-th box is not put into another box;  j-th box doesn't contain any other boxes;  box i is smaller than box j (ai < aj). Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it is not put into some another box.Help Mishka to determine the minimum possible number of visible boxes!

The first line contains one integer n (1 ≤ n ≤ 5000) — the number of boxes Mishka has got. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the side length of i-th box.

Print the minimum possible number of visible boxes.

NoteIn the first example it is possible to put box 1 into box 2, and 2 into 3.In the second example Mishka can put box 2 into box 3, and box 4 into box 1.

_ = $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

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

#!/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


Robot Bender decided to make Fray a birthday present. He drove n nails and numbered them from 1 to n in some order. Bender decided to make a picture using metal rods. The picture is a closed polyline, which vertices should be nails (in the given order). The segments of the polyline should be parallel to the coordinate axes. Polyline is allowed to have self-intersections. Bender can take a rod and fold it exactly once in any place to form an angle of 90 degrees. Then he can attach the place of the fold to some unoccupied nail and attach two ends of this rod to adjacent nails. A nail is considered unoccupied if there is no rod attached to it (neither by it's end nor the by the fold place). No rod could be used twice. It is not required to use all the rods.Help Bender to solve this difficult task.

The first line contains two positive integers n and m (4 ≤ n ≤ 500, 2 ≤ m ≤ 500, n is even) — the amount of nails and the amount of rods. i-th of the following n lines contains a pair of integers, denoting the coordinates of the i-th nail. Nails should be connected in the same order as they are given in the input. The last line contains m integers — the lenghts of the rods. All coordinates do not exceed 104 by absolute value. Lengths of the rods are between 1 and 200 000. No rod can be used twice. It is guaranteed that all segments of the given polyline are parallel to coordinate axes. No three consecutive nails lie on the same line.

If it is impossible to solve Bender's problem, output NO. Otherwise, output YES in the first line, and in the second line output n numbers — i-th of them should be the number of rod, which fold place is attached to the i-th nail, or -1, if there is no such rod. If there are multiple solutions, print any of them.

def length(a,b)
	(a[0]-b[0]).abs+(a[1]-b[1]).abs
end

def diff_list(pts)
	result=pts.each_cons(2).map{|a,b|length(a,b)}
	result<<length(pts[-1],pts[0])
	result
end

def solve(diff,rods,flag)
	result=[]
	diff.each_slice(2){|x,y|
		if idx=rods.index(x+y)
			rods[idx]=nil
			if flag
				result << -2 << idx
			else
				result<< idx << -2
			end
		else
			return nil
		end
	}
	result
end
n,m=gets.split.map(&:to_i)
nails=[]
n.times{nails<<gets.split.map(&:to_i)}
rods=gets.split.map(&:to_i)
diff=diff_list(nails)
ans=solve(diff,rods.dup,true)
unless ans
	diff.unshift diff.pop
	ans=solve(diff,rods,false)
end

if ans
	puts "YES"
	puts ans.map{|_|_+1}*" "
else
	puts "NO"
end


Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat.  There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ..., an and p1, ..., pn. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future.Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for n days.

The first line of input contains integer n (1 ≤ n ≤ 105), the number of days. In the next n lines, i-th line contains two integers ai and pi (1 ≤ ai, pi ≤ 100), the amount of meat Duff needs and the cost of meat in that day.

Print the minimum money needed to keep Duff happy for n days, in one line.

NoteIn the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day.

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.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.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


There is a game called "I Wanna Be the Guy", consisting of n levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.Little X can pass only p levels of the game. And Little Y can pass only q levels of the game. You are given the indices of levels Little X can pass and the indices of levels Little Y can pass. Will Little X and Little Y pass the whole game, if they cooperate each other?

The first line contains a single integer n (1 ≤  n ≤ 100).  The next line contains an integer p (0 ≤ p ≤ n) at first, then follows p distinct integers a1, a2, ..., ap (1 ≤ ai ≤ n). These integers denote the indices of levels Little X can pass. The next line contains the levels Little Y can pass in the same format. It's assumed that levels are numbered from 1 to n.

If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes).

NoteIn the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.In the second sample, no one can pass level 4.

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!"

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!"

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!"

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

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

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

#!/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 = 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."

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

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!"

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!"

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.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


Vasya writes his own library for building graphical user interface. Vasya called his creation VTK (VasyaToolKit). One of the interesting aspects of this library is that widgets are packed in each other. A widget is some element of graphical interface. Each widget has width and height, and occupies some rectangle on the screen. Any widget in Vasya's library is of type Widget. For simplicity we will identify the widget and its type. Types HBox and VBox are derivatives of type Widget, so they also are types Widget. Widgets HBox and VBox are special. They can store other widgets. Both those widgets can use the pack() method to pack directly in itself some other widget. Widgets of types HBox and VBox can store several other widgets, even several equal widgets — they will simply appear several times. As a result of using the method pack() only the link to the packed widget is saved, that is when the packed widget is changed, its image in the widget, into which it is packed, will also change. We shall assume that the widget a is packed in the widget b if there exists a chain of widgets a = c1, c2, ..., ck = b, k ≥ 2, for which ci is packed directly to ci + 1 for any 1 ≤ i < k. In Vasya's library the situation when the widget a is packed in the widget a (that is, in itself) is not allowed. If you try to pack the widgets into each other in this manner immediately results in an error.Also, the widgets HBox and VBox have parameters border and spacing, which are determined by the methods set_border() and set_spacing() respectively. By default both of these options equal 0.    The picture above shows how the widgets are packed into HBox and VBox. At that HBox and VBox automatically change their size depending on the size of packed widgets. As for HBox and VBox, they only differ in that in HBox the widgets are packed horizontally and in VBox — vertically. The parameter spacing sets the distance between adjacent widgets, and border — a frame around all packed widgets of the desired width. Packed widgets are placed exactly in the order in which the pack() method was called for them. If within HBox or VBox there are no packed widgets, their sizes are equal to 0 × 0, regardless of the options border and spacing. The construction of all the widgets is performed using a scripting language VasyaScript. The description of the language can be found in the input data. For the final verification of the code Vasya asks you to write a program that calculates the sizes of all the widgets on the source code in the language of VasyaScript.

The first line contains an integer n — the number of instructions (1 ≤ n ≤ 100). Next n lines contain instructions in the language VasyaScript — one instruction per line. There is a list of possible instructions below.   "Widget [name]([x],[y])" — create a new widget [name] of the type Widget possessing the width of [x] units and the height of [y] units.  "HBox [name]" — create a new widget [name] of the type HBox.  "VBox [name]" — create a new widget [name] of the type VBox.  "[name1].pack([name2])" — pack the widget [name2] in the widget [name1]. At that, the widget [name1] must be of type HBox or VBox.  "[name].set_border([x])" — set for a widget [name] the border parameter to [x] units. The widget [name] must be of type HBox or VBox.  "[name].set_spacing([x])" — set for a widget [name] the spacing parameter to [x] units. The widget [name] must be of type HBox or VBox.  All instructions are written without spaces at the beginning and at the end of the string. The words inside the instruction are separated by exactly one space. There are no spaces directly before the numbers and directly after them.  The case matters, for example, "wiDget x" is not a correct instruction. The case of the letters is correct in the input data. All names of the widgets consist of lowercase Latin letters and has the length from 1 to 10 characters inclusive. The names of all widgets are pairwise different. All numbers in the script are integers from 0 to 100 inclusive It is guaranteed that the above-given script is correct, that is that all the operations with the widgets take place after the widgets are created and no widget is packed in itself. It is guaranteed that the script creates at least one widget.

For each widget print on a single line its name, width and height, separated by spaces. The lines must be ordered lexicographically by a widget's name.  Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use cout stream (also you may use %I64d specificator)

12
Widget me(50,40)
VBox grandpa
HBox father
grandpa.pack(father)
father.pack(me)
grandpa.set_border(10)
grandpa.set_spacing(20)
Widget brother(30,60)
father.pack(brother)
Widget friend(20,60)
Widget uncle(100,20)
grandpa.pack(uncle)

15
Widget pack(10,10)
HBox dummy
HBox x
VBox y
y.pack(dummy)
y.set_border(5)
y.set_spacing(55)
dummy.set_border(10)
dummy.set_spacing(20)
x.set_border(10)
x.set_spacing(10)
x.pack(pack)
x.pack(dummy)
x.pack(pack)
x.set_border(0)

brother 30 60
father 80 60
friend 20 60
grandpa 120 120
me 50 40
uncle 100 20

NoteIn the first sample the widgets are arranged as follows:

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

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}"
}