You are given an integer $$$n$$$. Check if $$$n$$$ has an odd divisor, greater than one (does there exist such a number $$$x$$$ ($$$x > 1$$$) that $$$n$$$ is divisible by $$$x$$$ and $$$x$$$ is odd).For example, if $$$n=6$$$, then there is $$$x=3$$$. If $$$n=4$$$, then such a number does not exist.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case contains one integer $$$n$$$ ($$$2 \le n \le 10^{14}$$$). Please note, that the input for some test cases won't fit into $$$32$$$-bit integer type, so you should use at least $$$64$$$-bit integer type in your programming language.

For each test case, output on a separate line:    "YES" if $$$n$$$ has an odd divisor, greater than one;  "NO" otherwise.  You can output "YES" and "NO" in any case (for example, the strings yEs, yes, Yes and YES will be recognized as positive).

def is_power_of_two(n)
  while n
    if n % 2 == 0
      n /= 2
    elsif (n % 2 == 1) && (n > 1)
      return false
    elsif n == 1
      return true
    end
  end
  return true
end

test_case = gets().to_i
test_case.times do
  n = gets().to_i
  if is_power_of_two(n)
    puts "NO"
  else
    puts "YES"
  end
end

gets.to_i.times do
  n = gets.to_i
  n /= 2 while n%2 == 0
  puts n == 1 ? 'NO' : 'YES'
end

gets.to_i.times do
	n = gets.to_i
	puts n.to_s(2).count(?1) == 1 ? "NO" : "YES"
end

gets.to_i.times do
  n = gets.to_i
  puts n & (n - 1) == 0 ? "NO": "YES"
end

gets.to_i.times do
  n = gets.to_i
  n /= 2 while n % 2 == 0
  puts n == 1 ? "NO" : "YES"
end

t = gets.chomp.to_i
t.times do
    n = gets.chomp.to_i
    ok = false
    if n == 1
        puts "NO"
    else
        while true
            amari = n % 2
            if amari == 0
                n = n / 2
            else
                break
            end
        end
        if n == 1
            puts "NO"
        else
            puts "YES"
        end
    end
end

gets.to_i.times do
  n=gets.to_i
  while n%2==0
    n/=2
  end
  if n.odd?&&n>1
    puts "YES"
  else
    puts "NO"
  end
end

def method(n)
  while n % 2 == 0
    n /= 2
  end
  n != 1
end

t = gets.to_i
t.times do
  n = gets.to_i
  puts method(n) ? "YES" : "NO"
end

n = gets.chomp.to_i;
while n != 0
    n = n-1;
    value = gets.chomp.to_i;
   # puts value.class
#=begin
    while value%2 == 0
        value = value/2;
    end
    if value > 1
     puts "YES"
    else
     puts "NO"
    end
#=end
end

def is_power_of_two(n)
  loG = Math.log(n)/Math.log(2.0)
  if loG-loG.to_i === 0
    return true
  end
  return false
end

test_case = gets().to_i
test_case.times do
  n = gets().to_f
  if is_power_of_two(n)
    puts "NO"
  else
    puts "YES"
  end
end

def is_power_of_two(n)
  loG = Math.log(n)/Math.log(2.0)
  if loG-loG.to_i === 0
    return true
  end
  return false
end

test_case = gets().to_i
test_case.times do
  n = gets().to_f
  if n % 2.0 == 0.0 && is_power_of_two(n)
    puts "NO"
  else
    puts "YES"
  end
end

def is_power_of_two(n)
  loG = Math.log(n)/Math.log(2)
  if loG-loG.to_i === 0
    return true
  end
  return false
end

test_case = gets().to_i
test_case.times do
  n = gets().to_i
  if n % 2 == 0 && is_power_of_two(n)
    puts "NO"
  else
    puts "YES"
  end
end

def is_power_of_two(n)
  if n === 2
    return true
  end
  while n
    n /= 2
    if n % 2 == 1
      return false
    end
  end
  return true
end

test_case = gets().to_i
test_case.times do
  n = gets().to_i
  if n % 2 == 0 && is_power_of_two(n)
    puts "NO"
  else
    puts "YES"
  end
end

gets.to_i.times do
  puts gets.to_i%2 == 0 ? 'NO' : 'YES'
end

gets.to_i.times do
  n=gets.to_i
  if n.odd?&&n>1
    puts "YES"
  else
    puts "NO"
  end
end


Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like walls, he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid.Roger Waters has a square grid of size $$$n\times n$$$ and he wants to traverse his grid from the upper left ($$$1,1$$$) corner to the lower right corner ($$$n,n$$$). Waters can move from a square to any other square adjacent by a side, as long as he is still in the grid. Also except for the cells ($$$1,1$$$) and ($$$n,n$$$) every cell has a value $$$0$$$ or $$$1$$$ in it.Before starting his traversal he will pick either a $$$0$$$ or a $$$1$$$ and will be able to only go to cells values in which are equal to the digit he chose. The starting and finishing cells ($$$1,1$$$) and ($$$n,n$$$) are exempt from this rule, he may go through them regardless of picked digit. Because of this the cell ($$$1,1$$$) takes value the letter 'S' and the cell ($$$n,n$$$) takes value the letter 'F'.For example, in the first example test case, he can go from ($$$1, 1$$$) to ($$$n, n$$$) by using the zeroes on this path: ($$$1, 1$$$), ($$$2, 1$$$), ($$$2, 2$$$), ($$$2, 3$$$), ($$$3, 3$$$), ($$$3, 4$$$), ($$$4, 4$$$)The rest of the band (Pink Floyd) wants Waters to not be able to do his traversal, so while he is not looking they will invert at most two cells in the grid (from $$$0$$$ to $$$1$$$ or vice versa). They are afraid they will not be quick enough and asked for your help in choosing the cells.  Note that you cannot invert cells $$$(1, 1)$$$ and $$$(n, n)$$$.We can show that there always exists a solution for the given constraints.Also note that Waters will pick his digit of the traversal after the band has changed his grid, so he must not be able to reach ($$$n,n$$$) no matter what digit he picks.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 50$$$). Description of the test cases follows. The first line of each test case contains one integers $$$n$$$ ($$$3 \le n \le 200$$$). The following $$$n$$$ lines of each test case contain the binary grid, square ($$$1, 1$$$) being colored in 'S' and square ($$$n, n$$$) being colored in 'F'. The sum of values of $$$n$$$ doesn't exceed $$$200$$$.

For each test case output on the first line an integer $$$c$$$ ($$$0 \le c \le 2$$$)  — the number of inverted cells. In $$$i$$$-th of the following $$$c$$$ lines, print the coordinates of the $$$i$$$-th cell you inverted. You may not invert the same cell twice.  Note that you cannot invert cells $$$(1, 1)$$$ and $$$(n, n)$$$.

NoteFor the first test case, after inverting the cell, we get the following grid:S01000011001111F

t = gets.chomp.to_i
t.times do
  n = gets.chomp.to_i
  arr = []
  n.times do
    arr << gets.chomp.split('').map(&:to_s)
  end
  i_f = n - 1
  inv = []
  case
    when arr[0][1] == arr[1][0]
      if arr[i_f][i_f - 1] == arr[0][1]
        inv << [i_f + 1, i_f]
      end
      if arr[i_f - 1][i_f] == arr[0][1]
        inv << [i_f, i_f + 1]
      end
    when arr[i_f][i_f - 1] == arr[i_f - 1][i_f]
      if arr[1][0] == arr[i_f][i_f - 1]
        inv << [2, 1]
      end
      if arr[0][1] == arr[i_f][i_f - 1]
        inv << [1, 2]
      end
    when arr[0][1] == arr[i_f - 1][i_f]
      inv << [1, 2]
      inv << [i_f + 1, i_f]
    when arr[0][1] == arr[i_f][i_f - 1]
      inv << [1, 2]
      inv << [i_f, i_f + 1]
  end
  puts inv.size
  inv.map{|x| puts x.join(' ')}
end


On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains n different items numbered from 1 to n. The i-th item has base cost ai Egyptian pounds. If Sagheer buys k items with indices x1, x2, ..., xk, then the cost of item xj is axj + xj·k for 1 ≤ j ≤ k. In other words, the cost of an item is equal to its base cost in addition to its index multiplied by the factor k.Sagheer wants to buy as many souvenirs as possible without paying more than S Egyptian pounds. Note that he cannot buy a souvenir more than once. If there are many ways to maximize the number of souvenirs, he will choose the way that will minimize the total cost. Can you help him with this task?

The first line contains two integers n and S (1 ≤ n ≤ 105 and 1 ≤ S ≤ 109) — the number of souvenirs in the market and Sagheer's budget. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 105) — the base costs of the souvenirs.

On a single line, print two integers k, T — the maximum number of souvenirs Sagheer can buy and the minimum total cost to buy these k souvenirs.

NoteIn the first example, he cannot take the three items because they will cost him [5, 9, 14] with total cost 28. If he decides to take only two items, then the costs will be [4, 7, 11]. So he can afford the first and second items.In the second example, he can buy all items as they will cost him [5, 10, 17, 22].In the third example, there is only one souvenir in the market which will cost him 8 pounds, so he cannot buy it.

N, S = gets.split.map &:to_i
A = gets.split.map &:to_i
l, u, c = 0, N + 1, 0
until l + 1 == u
  m = l + u >> 1
  f = (0...N).collect { |i| A[i] + (i + 1) * m }.sort[0, m].reduce :+
  f <= S ? (l, c = m, f) : u = m
end
p l, c

_N, _S = gets.split.map &:to_i
_A = gets.split.map &:to_i
lb, ub, cost = 0, _N + 1, 0
until lb + 1 == ub
  mb = lb + ub >> 1
  _C = (0..._N).collect { |i| _A[i] + (i + 1) * mb }.sort
  mc = _C[0, mb].reduce :+
  if mc <= _S
    lb, cost = mb, mc
  else
    ub = mb
  end
end
print [lb, cost].join " "; puts


There is a special offer in Vasya's favourite supermarket: if the customer buys $$$a$$$ chocolate bars, he or she may take $$$b$$$ additional bars for free. This special offer can be used any number of times.Vasya currently has $$$s$$$ roubles, and he wants to get as many chocolate bars for free. Each chocolate bar costs $$$c$$$ roubles. Help Vasya to calculate the maximum possible number of chocolate bars he can get!

The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of testcases. Each of the next $$$t$$$ lines contains four integers $$$s, a, b, c~(1 \le s, a, b, c \le 10^9)$$$ — the number of roubles Vasya has, the number of chocolate bars you have to buy to use the special offer, the number of bars you get for free, and the cost of one bar, respectively.

Print $$$t$$$ lines. $$$i$$$-th line should contain the maximum possible number of chocolate bars Vasya can get in $$$i$$$-th test.

NoteIn the first test of the example Vasya can buy $$$9$$$ bars, get $$$3$$$ for free, buy another bar, and so he will get $$$13$$$ bars.In the second test Vasya buys $$$1000000000$$$ bars and gets $$$1000000000000000000$$$ for free. So he has $$$1000000001000000000$$$ bars.

def max(s,a,b,c)
    r = (s/c)
    return r+(r/a)*b
end

t = gets.to_i
t.times{
    s,a,b,c = gets.split.map(&:to_i)
    puts max(s,a,b,c)
}

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

for i in 1..Integer(gets)
    s,a,b,c = gets.split.map{|x| Integer(x)}
    n = s/c;
    puts n + (n / a * b)
end

t = gets.to_i
t.times do
  s, a, b, c = gets.split.map(&:to_i)
  num = s / c
  num += (num/a) * b
  puts num
end

gets.to_i.times do
    s,a,b,c=gets.split.map &:to_i
    x=s/c
    puts x+x/a*b
end

t = gets.to_i
for i in 0...t
  s, a, b, c = gets.split.map(&:to_i)
  q = s / c
  puts b * (q / a) + q
end

t = gets.to_i
t.times do
    s, a, b, c = gets.split.map(&:to_i)
    x = s / c
    x = (x / a) * (a + b) + (x % a)
    puts x
end

t = gets.to_i
t.times do
    s,a,b,c = gets.chomp.split.map(&:to_i)
    p (s/(a*c))*(a+b)+(s-(s/(a*c))*a*c)/c
end

t = gets.to_i
t.times do
  s, a, b, c = gets.split.map &:to_i
  n = s/c
  puts n + n/a*b
end

for i in 1..Integer(gets)
    s,a,b,c = gets.split.map{|x| Integer(x)}
    n = s/c;
    puts n + (n * b / a)
end


Vladik is a competitive programmer. This year he is going to win the International Olympiad in Informatics. But it is not as easy as it sounds: the question Vladik face now is to find the cheapest way to get to the olympiad.Vladik knows n airports. All the airports are located on a straight line. Each airport has unique id from 1 to n, Vladik's house is situated next to the airport with id a, and the place of the olympiad is situated next to the airport with id b. It is possible that Vladik's house and the place of the olympiad are located near the same airport. To get to the olympiad, Vladik can fly between any pair of airports any number of times, but he has to start his route at the airport a and finish it at the airport b.Each airport belongs to one of two companies. The cost of flight from the airport i to the airport j is zero if both airports belong to the same company, and |i - j| if they belong to different companies.Print the minimum cost Vladik has to pay to get to the olympiad.

The first line contains three integers n, a, and b (1 ≤ n ≤ 105, 1 ≤ a, b ≤ n) — the number of airports, the id of the airport from which Vladik starts his route and the id of the airport which he has to reach.  The second line contains a string with length n, which consists only of characters 0 and 1. If the i-th character in this string is 0, then i-th airport belongs to first company, otherwise it belongs to the second.

Print single integer — the minimum cost Vladik has to pay to get to the olympiad.

NoteIn the first example Vladik can fly to the airport 2 at first and pay |1 - 2| = 1 (because the airports belong to different companies), and then fly from the airport 2 to the airport 4 for free (because the airports belong to the same company). So the cost of the whole flight is equal to 1. It's impossible to get to the olympiad for free, so the answer is equal to 1. In the second example Vladik can fly directly from the airport 5 to the airport 2, because they belong to the same company.

n, a, b = gets.split.map( &:to_i )
s = gets
p ( s[ a - 1 ] != s[ b - 1 ] ? 1 : 0 )

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

airports = gets.chomp

if (airports[a - 1] == '0' && airports[b - 1] == '0') || (airports[a - 1] == '1' && airports[b - 1] == '1')
	puts 0
else
	puts 1
end

n, a, b = gets.split.map(&:to_i)
str = gets.chomp
puts str[a - 1] != str[b - 1] ? 1 : 0

n,s,e = gets.split.map(&:to_i)
route = gets
if route[s-1] == route[e-1] then puts "0" else puts "1" end

n, a, b = gets.split(" ").map(&:to_i)
s = gets
a -= 1
b -= 1
puts s[a] == s[b] ? 0 : 1

n, a, b = gets.strip.split.map(&:to_i)
airports = gets.strip.split("").map(&:to_i)
a -= 1
b -= 1
puts airports[a] ^ airports[b]

n,a,b=gets.split.map{|e| e.to_i-1}
x=gets.chomp
puts (x[a]!=x[b])?1:0

n,a,b = gets.chomp.split(" ").map(&:to_i)
s = gets.split("")
puts s[a-1] == s[b-1] ? 0 : 1

n,a,b=gets.split.map &:to_i
s=" "<< gets
puts (s[a]==s[b] ? 0 : 1)

input = Array.new
while i = $stdin.gets
  input << i.strip
end

n_airports, start_id, target_id = input.shift.split.map(&:to_i)
airports_companies = input.shift

cost = airports_companies[start_id - 1].to_i - airports_companies[target_id - 1].to_i
puts cost.abs

n, a, b = gets.split.map{|x| x.to_i}
s = gets.strip.split('')
puts(s[a - 1] == s[b - 1] ? 0 : 1)

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

airports = gets.chomp

if (airports[a - 1] == 0 && airports[b - 1] == 0) || (airports[a - 1] == 1 && airports[b - 1] == 1)
	puts 0
else
	puts 1
end

n, a, b = gets.strip.split.map(&:to_i)
airports = gets.strip.split("").map(&:to_i)
ans = 0
a -= 1
b -= 1
if a != b && airports[a] != airports[b]
    j = a
    if a < b
        while airports[j] != airports[b]
            j += 1
        end
    else
        while airports[j] != airports[b]
            j -= 1
        end
    end
    ans += (a - j).abs
end
puts ans

n, a, b = gets.strip.split.map(&:to_i)
airports = gets.strip.split("").map(&:to_i)
first = airports.each_index.select { |i| airports[i] == 0 }.sort
second = airports.each_index.select { |i| airports[i] == 1 }.sort
ans = 0
a -= 1
b -= 1
if a != b && airports[a] != airports[b]
    j = 0
    if a < b
        j = second.shift if airports[a] == 0
        j = first.shift if airports[a] == 1
    else
        j = second.pop if airports[a] == 0
        j = first.pop if airports[a] == 1
    end
    ans += (a - j).abs
end
puts ans

n, a, b = gets.strip.split.map(&:to_i)
airports = gets.strip.split("").map(&:to_i)
first = airports.each_index.select { |i| airports[i] == 0 }.sort
second = airports.each_index.select { |i| airports[i] == 1 }.sort
ans = 0
a -= 1
b -= 1
if airports[a] != airports[b]
    if airports[a] == 0
        ans += (a - second.shift).abs
    else
        ans += (a - first.shift).abs
    end
end
puts ans


Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime:  Find two consecutive characters in the string, such that the first of them equals "y", and the second one equals "x" and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string.  Find in the string two consecutive characters, such that the first of them equals "x" and the second one equals "y". Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string. The input for the new algorithm is string s, and the algorithm works as follows:  If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string.  If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm. Now Vitaly wonders, what is going to be printed as the result of the algorithm's work, if the input receives string s.

The first line contains a non-empty string s.  It is guaranteed that the string only consists of characters "x" and "y". It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm's execution won't be an empty string.

In the only line print the string that is printed as the result of the algorithm's work, if the input of the algorithm input receives string s.

NoteIn the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won't change.In the second test the transformation will be like this:  string "yxyxy" transforms into string "xyyxy";  string "xyyxy" transforms into string "xyxyy";  string "xyxyy" transforms into string "xxyyy";  string "xxyyy" transforms into string "xyy";  string "xyy" transforms into string "y". As a result, we've got string "y". In the third test case only one transformation will take place: string "xxxxxy" transforms into string "xxxx". Thus, the answer will be string "xxxx".

s=gets.to_s.chomp
s.count('x')>s.count('y')? (print 'x'*(s.count('x')-s.count('y'))) : (print 'y'*(s.count('y')-s.count('x')))

# -*- encoding: utf-8 -*-
# $stdin = File.open("input.txt")
# $stdout = File.open("output.txt", "w")

s = gets.chomp

x = s.count('x')
y = s.count('y')

if x > y
  puts "x" * (x - y)
else
  puts "y" * (y - x)
end

#!/usr/bin/ruby

s = STDIN.readline.strip

x, y = s.count('x'), s.count('y')

if x > y
	puts 'x'*(x-y)
else
	puts 'y'*(y-x)
end

s = gets.chomp
x = s.count("x")
y = s.count("y")

if x > y
  puts "x"*(x-y)
else
  puts "y"*(y-x)
end

def run
  line = ARGF.readline.chomp

  x = 0; y = 0
  line.split(//).each do |c|
    x += 1 if c == 'x'
    y += 1 if c == 'y'
  end

  if x > y
    puts "x" * (x - y)
  else
    puts "y" * (y - x)
  end
end

run if $0 == __FILE__

s = gets
puts s.count("x") > s.count("y") ? "x" * (s.count("x")-s.count("y")) : "y" * (s.count("y")-s.count("x"))

input = gets.chomp

x = input.count 'x'
y = input.count 'y'

if x > y
  puts 'x'*(x-y)
else
  puts 'y'*(y-x)
end

s=gets.split(//)

a = 0
b = 0

s.each do |i|
	a += 1 if i == 'x'
	b += 1 if i == 'y'
end

puts 'x'*(a-b) if a > b
puts 'y'*(b-a) if b > a

e=gets
x=e.count("x")
y=e.count("y")
puts x>y ? 'x'*(x-y) : 'y'*(y-x)

s = gets.chomp
cntx = s.count("x")
cnty = s.count("y")
if cntx > cnty
    puts "x"*(cntx-cnty)
else
    puts "y"*(cnty-cntx)
end

a=gets.chomp

x=a.count('x')
y=a.count('y')

if x>y
  puts 'x'*(x-y)
else
  puts 'y'*(y-x)
end

a=gets.chomp.chars.to_a

x=a.count('x')
y=a.count('y')

if x>y
  puts 'x'*(x-y)
else
  puts 'y'*(y-x)
end

text = STDIN.gets
x_count, y_count = 0, 0
text.length.times{|i|
	case text[i,1]
	when "x"
		x_count += 1
	when "y"
		y_count += 1
	end
}
if x_count > y_count
	puts "x" * (x_count - y_count)
elsif y_count > x_count
	puts "y" * (y_count - x_count)
end

s = gets.strip.split //
y = 0
x = 0
0.upto(s.size-1) do |i|
  if s[i] == 'y'
    y += 1
  else
    x +=1
  end
end

y
if y>x
  puts "y"*(y-x)
else
  puts "x"*(x-y)
end

o=gets.chomp
k=0
l=0
o.length.times do |i|
if o[i]=='x'
    k+=1
else
    l+=1
end
end
j=k-l
g=l-k
if k>l
    j.times do
    print "x"
    end
elsif l>k
    g.times do
    print "y"
    end
else
    print "\n"
end

count = [0, 0]
gets.strip.each_char do |c|
    count[c == 'x' ? 0 : 1] += 1
end
if count[0] > count[1]
    puts "x" * (count[0] - count[1])
else
    puts "y" * (count[1] - count[0])
end

# -*- encoding: utf-8 -*-
# $stdin = File.open("input.txt")
# $stdout = File.open("output.txt", "w")

s = gets.chomp

s.gsub!(/yx/, "xy")
s.gsub!(/xy/, "")

puts s

# -*- encoding: utf-8 -*-
# $stdin = File.open("input.txt")
# $stdout = File.open("output.txt", "w")

def op1(s)
  s.sub(/yx/, "xy")
end

def op2(s)
  s.sub(/xy/, "")
end

s = gets.chomp

s.gsub!(/yx/, "")
s.gsub!(/xy/, "")

puts s

# -*- encoding: utf-8 -*-
# $stdin = File.open("input.txt")
# $stdout = File.open("output.txt", "w")

def op1(s)
  s.sub(/yx/, "xy")
end

def op2(s)
  s.sub(/xy/, "")
end

s = gets.chomp
loop do
  tmp = s
  s1 = op1(s)
  if s = s1
    s = s1
  else
    s = op2(s)
  end

  break if tmp == s
end

puts s

s = gets
s = s.gsub("xy", "")
s = s.gsub("yx", "xy")
s = s.gsub("xy", "")
puts s

o=gets.chomp
x=0
y=0
o.length.times do |i|
if o[i]=='x'
    x+=1
else
    y+=1
end
end
if x>y
    x-y.times do
    print x
    end
elsif y>x
    y-x.times do
    print y
    end
else
    print "\n"
end


For the New Year, Polycarp decided to send postcards to all his $$$n$$$ friends. He wants to make postcards with his own hands. For this purpose, he has a sheet of paper of size $$$w \times h$$$, which can be cut into pieces.Polycarp can cut any sheet of paper $$$w \times h$$$ that he has in only two cases:   If $$$w$$$ is even, then he can cut the sheet in half and get two sheets of size $$$\frac{w}{2} \times h$$$;  If $$$h$$$ is even, then he can cut the sheet in half and get two sheets of size $$$w \times \frac{h}{2}$$$; If $$$w$$$ and $$$h$$$ are even at the same time, then Polycarp can cut the sheet according to any of the rules above.After cutting a sheet of paper, the total number of sheets of paper is increased by $$$1$$$.Help Polycarp to find out if he can cut his sheet of size $$$w \times h$$$ at into $$$n$$$ or more pieces, using only the rules described above.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of one line containing three integers $$$w$$$, $$$h$$$, $$$n$$$ ($$$1 \le w, h \le 10^4, 1 \le n \le 10^9$$$) — the width and height of the sheet Polycarp has and the number of friends he needs to send a postcard to.

For each test case, output on a separate line:    "YES", if it is possible to cut a sheet of size $$$w \times h$$$ into at least $$$n$$$ pieces;  "NO" otherwise.  You can output "YES" and "NO" in any case (for example, the strings yEs, yes, Yes and YES will be recognized as positive).

NoteIn the first test case, you can first cut the $$$2 \times 2$$$ sheet into two $$$2 \times 1$$$ sheets, and then cut each of them into two more sheets. As a result, we get four sheets $$$1 \times 1$$$. We can choose any three of them and send them to our friends.In the second test case, a $$$3 \times 3$$$ sheet cannot be cut, so it is impossible to get two sheets.In the third test case, you can cut a $$$5 \times 10$$$ sheet into two $$$5 \times 5$$$ sheets.In the fourth test case, there is no need to cut the sheet, since we only need one sheet.In the fifth test case, you can first cut the $$$1 \times 4$$$ sheet into two $$$1 \times 2$$$ sheets, and then cut each of them into two more sheets. As a result, we get four sheets $$$1 \times 1$$$.

a = gets.to_i
for i in 1..a do
    b = gets.chop
    c = b.split(/ /).map(&:to_i)
    w = c[0]
    h = c[1]
    n = c[2]
    i = 0
    j = 0
    while w % 2 == 0
        i += 1
        w = w / 2
    end
    while h % 2 == 0
        j += 1
        h = h / 2
    end
    if 2 ** (i+j) >= n
        print("YES", "\n")
    else
        print("NO", "\n")
    end
end

def zeros(n)
  n.even? ? zeros(n >> 1) * 2 : 1
end

gets.to_i.times {
  w, h, n = gets.split.map!(&:to_i)
  puts n <= zeros(w) * zeros(h) ? "YES" : "NO"
}

def solve
  w, h, n = gets.split.map(&:to_i)
  x = 1
  while w > 0 and w.even?
    x <<= 1
    w >>= 1
  end
  while h > 0 and h.even?
    x <<= 1
    h >>= 1
  end
  puts (x >= n) ? "YES" : "NO"
end

t = gets.to_i
t.times do
  solve
end

def method(v)
  res = 1
  res *= 2 while v % (2 * res) == 0
  res
end

t = gets.to_i
t.times do
  w, h, n = gets.split.map { |x| x.to_i }
  puts n <= method(w) * method(h) ? "YES" : "NO"
end

gets.to_i.times do
	a, b, n = gets.split.map(&:to_i)
	x, y = a, b
	x /= 2 while x.even?
	y /= 2 while y.even?

	puts (a / x) * (b / y) >= n ? 'YES' : 'NO'
end

require 'prime'
t = gets.chomp.to_i
t.times do
  w, h, n = gets.chomp.split(' ').map(&:to_i)
  res = 1
  while w % 2 == 0 || h % 2 == 0
    res *= 2
    if w % 2 == 0
      w /= 2
    else
      h /= 2
    end
  end
  puts n <= res ? "YES" : "NO"
end

n = $stdin.gets.to_i

n.times do
  w, h, x = $stdin.gets.split.map &:to_i
  wc = 1
  while w % 2 == 0
    wc *= 2
    w /= 2
  end

  hc = 1
  while h % 2 == 0
    hc *= 2
    h /= 2
  end

  if hc * wc >= x
    puts 'yes'
  else
    puts 'no'
  end
end

#!/usr/bin/env ruby

def count_num(len)
    res = 1
    while len.even? do
        res *= 2
        len /= 2
    end
    return res
end

tests_count = gets.to_i
tests_count.times {
    w, h, n = gets.split.map &:to_i
    res = count_num(w) * count_num(h)
    puts res >= n ? "YES" : "NO"
}

gets.to_i.times do
  w, h, n = gets.split.map &:to_i
  res = 1
  while w % 2 == 0
    w /= 2
    res *= 2
  end
  while h % 2 == 0
    h /= 2
    res *= 2
  end
  puts res >= n ? "YES" : "NO"
end

require "prime"
t = gets.chomp.to_i
t.times do
    w, h, n = gets.chomp.split(" ").map(&:to_i)
    cnt_w = w.prime_division
    cnt_h = h.prime_division
    cnt = 1
    cnt_w.each do |i,j|
        if i == 2
            cnt *= i ** j
        end
    end
    cnt_h.each do |i,j|
        if i == 2
            cnt *= i ** j
        end
    end
    if cnt >= n
        puts "YES"
    else
        puts "NO"
    end
end

gets.to_i.times do
  w,h,n=gets.split.map(&:to_i)
  c=1
  while w.even?
    w/=2
    c*=2
  end
  while h.even?
    h/=2
    c*=2
  end
  if c>=n
    puts "YES"
  else
    puts "NO"
  end
end

a = gets.to_i
for i in 1..a do
    b = gets.chop
    c = b.split(/ /).map(&:to_i)
    w = c[0]
    h = c[1]
    n = c[2]
    i = 0
    j = 0
    while w % 2 == 0
        i += 1
        w = w / 2
    end
    while h % 2 == 0
        j += 1
        h = h / 2
    end
    if ((i+1) * (j+1)) >= n
        print("YES", "\n")
    else
        print("NO", "\n")
    end
end

a = gets.to_i
for i in 1..a do
    b = gets.chop
    c = b.split(/ /).map(&:to_i)
    w = c[0]
    h = c[1]
    n = c[2]
    i = 0
    j = 0
    while w % 2 == 0
        i += 1
        w = w / 2
    end
    while h % 2 == 0
        j += 1
        h = h / 2
    end
    print(((i+1) * (j+1)) >= n, "\n")
end

a = gets.to_i
for i in 1..a do
    b = gets.chop
    c = b.split(/ /).map(&:to_i)
    w = c[0]
    h = c[1]
    n = c[2]
    i = 0
    j = 0
    while w % 2 == 0
        i += 1
        w = w / 2
    end
    while h % 2 == 0
        j += 1
        h = h / 2
    end
    print(((i+1) * (j+1)) >= n)
end

require 'prime'
t = gets.chomp.to_i
t.times do
  w, h, n = gets.chomp.split(' ').map(&:to_i)
  w1 = Prime.prime_division(w)[0]
  h1 = Prime.prime_division(h)[0]
  res = 0
  res += 2 ** w1[1] if w1 && w1[0] == 2
  res += 2 ** h1[1] if h1 && h1[0] == 2
  puts n <= [res, 1].max ? "YES" : "NO"
end

require 'prime'
t = gets.chomp.to_i
t.times do
  w, h, n = gets.chomp.split(' ').map(&:to_i)
  w1 = Prime.prime_division(w)[0]
  h1 = Prime.prime_division(h)[0]
  res = 1
  res += 2 ** w1[1] if w1 && w1[0] == 2
  res += 2 ** h1[1] if h1 && h1[0] == 2
  puts n <= res ? "YES" : "NO"
end


Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has n stones which are rectangular parallelepipeds. The edges sizes of the i-th of them are ai, bi and ci. He can take no more than two stones and present them to Kostya. If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way. Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar.

The first line contains the integer n (1 ≤ n ≤ 105). n lines follow, in the i-th of which there are three integers ai, bi and ci (1 ≤ ai, bi, ci ≤ 109) — the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones.

In the first line print k (1 ≤ k ≤ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n — the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data. You can print the stones in arbitrary order. If there are several answers print any of them.

NoteIn the first example we can connect the pairs of stones:  2 and 4, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1  2 and 5, the size of the parallelepiped: 3 × 2 × 8 or 6 × 2 × 4 or 3 × 4 × 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively.  2 and 6, the size of the parallelepiped: 3 × 5 × 4, the radius of the inscribed sphere 1.5  4 and 5, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1  5 and 6, the size of the parallelepiped: 3 × 4 × 5, the radius of the inscribed sphere 1.5 Or take only one stone:  1 the size of the parallelepiped: 5 × 5 × 5, the radius of the inscribed sphere 2.5  2 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1  3 the size of the parallelepiped: 1 × 4 × 1, the radius of the inscribed sphere 0.5  4 the size of the parallelepiped: 2 × 1 × 3, the radius of the inscribed sphere 0.5  5 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1  6 the size of the parallelepiped: 3 × 3 × 4, the radius of the inscribed sphere 1.5 It is most profitable to take only the first stone.

n = gets.to_i
ary = []
hsh = {}
n.times do |i|
  x, y, z = gets.split.map(&:to_i)
  ary << [x,y,z].min
  tary = [x,y,z].sort.reverse
  key = "#{tary[0]},#{tary[1]}"
  hsh[key] = [] unless hsh[key]
  hsh[key] << [tary[2], i+1]
end

ans = ary.max
idxs = [ary.index(ans)+1]
hsh.each do |key, vals|
  if vals.size > 1
    d1, d2 = key.split(",").map(&:to_i)
    vals.sort!
    tans = [d1, d2, vals[-1][0] + vals[-2][0]].min
    # puts key
    # puts vals.inspect
    # puts "#{tans} : #{ans}"
    if tans > ans
      # puts vals.inspect
      # puts "#{tans} : #{ans}"
      ans = tans
      idxs = [vals[-1][1], vals[-2][1]].sort
    end
  end
end

puts idxs.size
puts idxs.join(" ")

def mymax(ary)
  i1 = nil
  i2 = nil
  m1 = 0
  m2 = 0
  ary.each do |x|
    if i1 == nil
      m1 = x[0]
      i1 = x[1]
      next
    end
    next if i1 == x[1]
    if i2 == nil
      m2 = x[0]
      i2 = x[1]
      next
    end
    next if i2 == x[1]
    if x[0] > m1
      m1 = x[0]
      i1 = x[1]
      next
    end
    if x[0] > m2
      m2 = x[0]
      i2 = x[1]
      next
    end
  end
  if i2 == nil
    [[i1], m1]
  else
    [[i1, i2], m1+m2]
  end
end

n = gets.to_i
ary = []
hsh = {}
n.times do |i|
  x, y, z = gets.split.map(&:to_i)
  ary << [x,y,z].min

  hsh[x] = {} unless hsh[x]
  hsh[x][y] = [] unless hsh[x][y]
  hsh[x][y] << [z, i+1]

  hsh[y] = {} unless hsh[y]
  hsh[y][z] = [] unless hsh[y][z]
  hsh[y][z] << [x, i+1]

  hsh[z] = {} unless hsh[z]
  hsh[z][x] = [] unless hsh[z][x]
  hsh[z][x] << [y, i+1]
end

ans = ary.max
# puts ans
idxs = [ary.index(ans)+1]
hsh.each do |d1, h1|
  h1.each do |d2, d3s|
    tidxs, d3 = mymax(d3s)
    tans = [d1, d2, d3].min
    if tans > ans
      ans = tans
      idxs = tidxs
    end
    # puts ans
  end
end

puts idxs.size
puts idxs.join(" ")

def mymax(ary)
  i1 = nil
  i2 = nil
  m1 = 0
  m2 = 0
  ary.each do |x|
    if i1 == nil
      m1 = x[0]
      i1 = x[1]
      next
    end
    next if i1 == x[1]
    if i2 == nil
      m2 = x[0]
      i2 = x[1]
      next
    end
    next if i2 == x[1]
    if m1 < m2
      if x[0] > m1
        m1 = x[0]
        i1 = x[1]
        next
      end
      if x[0] > m2
        m2 = x[0]
        i2 = x[1]
        next
      end
    else
      if x[0] > m2
        m2 = x[0]
        i2 = x[1]
        next
      end
      if x[0] > m1
        m1 = x[0]
        i1 = x[1]
        next
      end
    end
  end
  if i2 == nil
    [[i1], m1]
  else
    [[i1, i2], m1+m2]
  end
end

n = gets.to_i
ary = []
hsh = {}
n.times do |i|
  x, y, z = gets.split.map(&:to_i)
  ary << [x,y,z].min

  hsh[x] = {} unless hsh[x]
  hsh[x][y] = [] unless hsh[x][y]
  hsh[x][y] << [z, i+1]

  hsh[y] = {} unless hsh[y]
  hsh[y][z] = [] unless hsh[y][z]
  hsh[y][z] << [x, i+1]

  hsh[z] = {} unless hsh[z]
  hsh[z][x] = [] unless hsh[z][x]
  hsh[z][x] << [y, i+1]
end

ans = ary.max
# puts ans
idxs = [ary.index(ans)+1]
hsh.each do |d1, h1|
  h1.each do |d2, d3s|
    tidxs, d3 = mymax(d3s)
    tans = [d1, d2, d3].min
    if tans > ans
      ans = tans
      idxs = tidxs
    end
    # puts ans
  end
end

puts idxs.size
puts idxs.join(" ")

n = gets.to_i
ary = []
hsh = {}
n.times do |i|
  x, y, z = gets.split.map(&:to_i)
  ary << [x,y,z].min
  tary = [x,y,z].sort.reverse
  key = "#{tary[0]},#{tary[1]}"
  hsh[key] = [] unless hsh[key]
  hsh[key] << [tary[2], i+1]
end

ans = ary.max
idxs = [ary.index(ans)+1]
hsh.each do |key, vals|
  if vals.size > 1
    d1, d2 = key.split(",").map(&:to_i)
    vals.sort
    tans = [d1, d2, vals[-1][0] + vals[-2][0]].min
    if tans > ans
      tans = ans
      idxs = [vals[-1][1], vals[-2][1]].sort
    end
  end
end

puts idxs.size
puts idxs.join(" ")

n = gets.to_i
ary = []
hsh = {}
n.times do |i|
  x, y, z = gets.split.map(&:to_i)
  ary << [x,y,z].min
  tary = [x,y,z].sort.reverse
  key = "#{tary[0]},#{tary[1]}"
  hsh[key] = [] unless hsh[key]
  hsh[key] << [tary[2], i+1]
end

ans = ary.max
idxs = [ary.index(ans)+1]
hsh.each do |key, vals|
  if vals.size > 1
    d1, d2 = key.split(",").map(&:to_i)
    vals.sort
    tans = [d1, d2, vals[-1][0] + vals[-2][0]].min
    if tans > ans
      ans = tans
      idxs = [vals[-1][1], vals[-2][1]].sort
    end
  end
end

puts idxs.size
puts idxs.join(" ")


The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has n students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.The head of the SSU OPTC is recently gathering teams to participate in the world championship. Each team must consist of exactly three people, at that, any person cannot be a member of two or more teams. What maximum number of teams can the head make if he wants each team to participate in the world championship with the same members at least k times?

The first line contains two integers, n and k (1 ≤ n ≤ 2000; 1 ≤ k ≤ 5). The next line contains n integers: y1, y2, ..., yn (0 ≤ yi ≤ 5), where yi shows the number of times the i-th person participated in the ACM ICPC world championship.

Print a single number — the answer to the problem.

NoteIn the first sample only one team could be made: the first, the fourth and the fifth participants.In the second sample no teams could be created.In the third sample two teams could be created. Any partition into two teams fits.

n, k = gets.split(' ').map(&:to_i)
puts gets.split(' ',n).map(&:to_i).select{|x| x+k<=5}.count / 3

n, k = gets.split.map &:to_i
participation_count = gets.split.map &:to_i

participation_count.sort!

teams_count = 0
(2 ... n).step(3) do |i|
  teams_count += 1 if participation_count[i] + k <= 5
end

puts teams_count

n, k = gets.split.map(&:to_i)
y = gets.split.map(&:to_i)
y.sort!
i = 0
while (i * 3 + 2 < n) && (y[i * 3 + 2] + k <= 5)
	i += 1
end
puts i

n,k=gets.split.map &:to_i
m=gets.split.map &:to_i
p=0
m.each { |x| p+=1 if x+k<=5 }
puts p/3

n,k=gets.split.map(&:to_i)
puts (gets.split.map(&:to_i).select{|i| i<=5-k}.size)/3

n,k = gets.split.map(&:to_i)
puts (gets.split.map(&:to_i).select{|i| i<=5-k}.size)/3

answer = 0
n, k = gets.split.map(&:to_i)
gets.split.map(&:to_i).each { |x| answer +=1 if k+x <= 5 }
puts (answer/3).floor

n, k = gets.split.map &:to_i
counter = 0
puts gets.split.map { |x| x.to_i }.count { |x| x + k <= 5 } / 3

(n , k) = gets.split.map(&:to_i)
arr = gets.split.map(&:to_i)
cnt = 0
arr.each do |num|
  if 5 - num >=k
    cnt+=1
  end
end
puts cnt / 3

n, k = gets.split(' ').map(&:to_i)
a = gets.split(' ').map(&:to_i)
count = [0, 0, 0, 0, 0, 0]
for x in a
  count[x] += 1
end
sum = 0
(6-k).times{|i|
  sum += count[i]
}
puts sum/3

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

members = 0
ys.each do |y|
  if 5 - y >= k
    members += 1
  end
end
puts members / 3

n, k = gets.chomp.split(/ /).map(&:to_i)
students = gets.chomp.split(/ /).map(&:to_i)
if n < 3
    puts "0"
else
    teams = []
    students.reject! { |s| s == 5 }
    students.reject! { |s| s > 5 - k }
    while students.length >= 3
        teams << students[0..2]
        (0..2).each do |s|
            students.delete_at s
        end
    end
    puts teams.length
end

n,k=gets.split.map{|e| e.to_i}
x=gets.split.map{|e| 5-e.to_i}.count{|e| e>=k}
p x/3

n,k = gets.split.map(&:to_i)
puts gets.split.map(&:to_i).sort.count{|i| i + k <= 5} /3

s, n, k = [0] + gets.chomp.split.map{|e| e.to_i}

gets.chomp.split.map{|e| e.to_i}.sort.each_slice(3).to_a.each {|e| s += 1 if e.length == 3 and e.all? {|t| 5 - t >= k}}

puts s

#!/usr/bin/ruby

class Solver
    def solve()
        n, k = STDIN.gets.split(" ").map(&:to_i)
        times = STDIN.gets.split(" ").map(&:to_i)
        valid = 0
        times.each do |t|
            valid = valid + 1 if t + k <= 5
        end

        puts valid / 3
    end
end

Solver.new.solve()

n = gets.chomp
n = n.split
number_of_participants = n[0].to_i
times_needed = n[1].to_i
part = gets.chomp
participated = part.split

possible_teams = number_of_participants/3
count = 0
for i in (0..number_of_participants-1)
	if participated[i].to_i + times_needed <= 5
		count += 1
	end
end

if count >= 3
	puts count/3
else
	puts 0
end

first_line = gets.split(" ")
n = first_line[0].to_i
k = first_line[1].to_i
ys = gets.split(" ").collect {|x| x.to_i}
count = 0
for i in ys
  if k + i <= 5
    count += 1
  end
end
puts (count / 3)

line1=gets.chomp.split(" ").map!{|x| x.to_i}
n=line1[0];k=line1[1]
line2=gets.chomp.split(" ").map!{|x| x.to_i}
def Solve(list,k)
  list.select! {|x| 5-x>=k }
  puts list.size/3
end
Solve(line2,k)

n,k = gets.split(" ").map(&:to_i)
no_participations = gets.split(" ").map(&:to_i)
count_hash = {}

no_participations.each do |p|
  count_hash[p] ||= 0
  count_hash[p] += 1
end
res = 0
(0..5-k).each do |i|
  res += count_hash[i] if count_hash[i]
end
puts res / 3

n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort
c = 0
a.each do |x|
  c += 1 if x + k <= 5
end
puts c / 3

n, k = gets.split.map(&:to_i)
puts gets.split.map(&:to_i).count{|x| x + k <= 5} / 3

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

puts(a.select { |x| x <= 5-k }.size.div(3))

i=->{gets.split.map(&:to_i)}
_,k=i[]
p i[].select{|x|x<6-k}.size/3

#!/usr/bin/ruby

class Solver
    def solve()
        ans = 0
        n, k = STDIN.gets.split(" ").map(&:to_i)
        times = STDIN.gets.split(" ").map(&:to_i)
        times.sort!
        i = 0
        while i <= times.length - 3
            a = times[i]
            b = times[i+1]
            c = times[i+2]
            max = [a, b, c].max
            if max + k <= 5
                ans += 1
            end
            i += 2
        end

        puts ans
    end
end

Solver.new.solve()

n = gets.chomp
n = n.split
number_of_participants = n[0].to_i
times_needed = n[1].to_i
part = gets.chomp
participated = part.split

possible_teams = number_of_participants/3
count = 0
for i in (0..number_of_participants-1)
	if participated[i].to_i + times_needed <= 5
		count += 1
	end
end

if count >= 3
	puts possible_teams
else
	puts 0
end

n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort
c = 0
a.each do |x|
  c += 1 if x + k < 5
end
puts c / 3

i=->{gets.split.map(&:to_i)}
_,k=i[]
p i[].collect{|x|x<6-k}.size/3


There is a badminton championship in which $$$n$$$ players take part. The players are numbered from $$$1$$$ to $$$n$$$. The championship proceeds as follows: player $$$1$$$ and player $$$2$$$ play a game, then the winner and player $$$3$$$ play a game, and then the winner and player $$$4$$$ play a game, and so on. So, $$$n-1$$$ games are played, and the winner of the last game becomes the champion. There are no draws in the games.You want to find out the result of championship. Currently, you only know the following information:  Each player has either won $$$x$$$ games or $$$y$$$ games in the championship. Given $$$n$$$, $$$x$$$, and $$$y$$$, find out if there is a result that matches this information.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The only line of each test case contains three integers $$$n$$$, $$$x$$$, $$$y$$$ ($$$2 \le n \le 10^5$$$, $$$0 \le x, y < n$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.

Print the answer for each test case, one per line. If there is no result that matches the given information about $$$n$$$, $$$x$$$, $$$y$$$, print $$$-1$$$. Otherwise, print $$$n-1$$$ space separated integers, where the $$$i$$$-th integer is the player number of the winner of the $$$i$$$-th game.  If there are multiple valid results, print any.

NoteIn the first test case, player $$$1$$$ and player $$$4$$$ won $$$x$$$ times, player $$$2$$$ and player $$$3$$$ won $$$y$$$ times.In the second, third, and fifth test cases, no valid result exists.

def main
  t = inp.to_i
  t.times do
    n, x, y = mapint(inarr)
    if (x != 0 && y != 0) || (x == 0 && y == 0) || ((n - 1) % (x + y) != 0)
      puts -1
    else
      win = 1
      s = x + y
      k = 0
      1.upto(n - 1) do |i|
        if k >= s
          win = i + 1
          k=0
        end
        print win
        print " " if i != n - 1
        k+=1
      end
      puts ""
    end

  end

end

# lib
def inp
  gets.chomp
end

def inarr
  gets.chomp.split
end

def mapint(lst)
  lst.map(&:to_i)
end

main


Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0 ≤ 2k ≤ n) who showed the best result in their semifinals and all other places in the finals go to the people who haven't ranked in the top k in their semifinal but got to the n - 2k of the best among the others.The tournament organizers hasn't yet determined the k value, so the participants want to know who else has any chance to get to the finals and who can go home.

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of participants in each semifinal. Each of the next n lines contains two integers ai and bi (1 ≤ ai, bi ≤ 109) — the results of the i-th participant (the number of milliseconds he needs to cover the semifinals distance) of the first and second semifinals, correspondingly. All results are distinct. Sequences a1, a2, ..., an and b1, b2, ..., bn are sorted in ascending order, i.e. in the order the participants finished in the corresponding semifinal.

Print two strings consisting of n characters, each equals either "0" or "1". The first line should correspond to the participants of the first semifinal, the second line should correspond to the participants of the second semifinal. The i-th character in the j-th line should equal "1" if the i-th participant of the j-th semifinal has any chances to advance to the finals, otherwise it should equal a "0".

NoteConsider the first sample. Each semifinal has 4 participants. The results of the first semifinal are 9840, 9860, 9930, 10040. The results of the second semifinal are 9920, 9980, 10020, 10090.  If k = 0, the finalists are determined by the time only, so players 9840, 9860, 9920 and 9930 advance to the finals.  If k = 1, the winners from both semifinals move to the finals (with results 9840 and 9920), and the other places are determined by the time (these places go to the sportsmen who run the distance in 9860 and 9930 milliseconds).  If k = 2, then first and second places advance from each seminfial, these are participants with results 9840, 9860, 9920 and 9980 milliseconds.

# worst case: the first n (of both sf) advance;
# best case: the first n/2 of each semi-final;

n = gets.to_i
a = []
b = []
res = {'a'=>[], 'b'=>[]}
n.times do |i|
  ai,bi = gets.split.map(&:to_i)
  a << ai
  b << bi
end
(n/2...n).each do |i|
  res['a'] << (a[i] < b[n-i-1] ? '1' : '0')
  res['b'] << (b[i] < a[n-i-1] ? '1' : '0')
end
puts Array.new(n/2){'1'}.concat(res['a']).join
puts Array.new(n/2){'1'}.concat(res['b']).join

class Result
  def initialize(score, order)
    @score = score
    @order = order
  end

  def score
    @score
  end

  def order
    @order
  end
end

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

n = gets.to_i
results = Array.new(2 * n)
(0...n).each { |i|
  r = read_next_line
  results[i] = Result.new(r[0], 0)
  results[i + n] = Result.new(r[1], 1)
}

results.sort_by! { |result| result.score }

winners_count = Array.new(2, 0)
(0...n).each { |i|
  winners_count[results[i].order] += 1
}

winners_count.each { |count|
  puts ('1' * [count, n / 2].max).ljust(n, '0')
}


The map of the capital of Berland can be viewed on the infinite coordinate plane. Each point with integer coordinates contains a building, and there are streets connecting every building to four neighbouring buildings. All streets are parallel to the coordinate axes.The main school of the capital is located in $$$(s_x, s_y)$$$. There are $$$n$$$ students attending this school, the $$$i$$$-th of them lives in the house located in $$$(x_i, y_i)$$$. It is possible that some students live in the same house, but no student lives in $$$(s_x, s_y)$$$.After classes end, each student walks from the school to his house along one of the shortest paths. So the distance the $$$i$$$-th student goes from the school to his house is $$$|s_x - x_i| + |s_y - y_i|$$$.The Provision Department of Berland has decided to open a shawarma tent somewhere in the capital (at some point with integer coordinates). It is considered that the $$$i$$$-th student will buy a shawarma if at least one of the shortest paths from the school to the $$$i$$$-th student's house goes through the point where the shawarma tent is located. It is forbidden to place the shawarma tent at the point where the school is located, but the coordinates of the shawarma tent may coincide with the coordinates of the house of some student (or even multiple students).You want to find the maximum possible number of students buying shawarma and the optimal location for the tent itself.

The first line contains three integers $$$n$$$, $$$s_x$$$, $$$s_y$$$ ($$$1 \le n \le 200\,000$$$, $$$0 \le s_x, s_y \le 10^{9}$$$) — the number of students and the coordinates of the school, respectively. Then $$$n$$$ lines follow. The $$$i$$$-th of them contains two integers $$$x_i$$$, $$$y_i$$$ ($$$0 \le x_i, y_i \le 10^{9}$$$) — the location of the house where the $$$i$$$-th student lives. Some locations of houses may coincide, but no student lives in the same location where the school is situated.

The output should consist of two lines. The first of them should contain one integer $$$c$$$ — the maximum number of students that will buy shawarmas at the tent.  The second line should contain two integers $$$p_x$$$ and $$$p_y$$$ — the coordinates where the tent should be located. If there are multiple answers, print any of them. Note that each of $$$p_x$$$ and $$$p_y$$$ should be not less than $$$0$$$ and not greater than $$$10^{9}$$$.

NoteIn the first example, If we build the shawarma tent in $$$(4, 2)$$$, then the students living in $$$(4, 2)$$$, $$$(4, 1)$$$ and $$$(5, 1)$$$ will visit it.In the second example, it is possible to build the shawarma tent in $$$(1, 1)$$$, then both students living in $$$(0, 0)$$$ will visit it.

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

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

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

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n,sx,sy=gsmi
xy=n.times.map{gsmi}

place=[]
max=0
# 候補は学校の上下左右の4箇所
# 右
bor = sx+1
cnt=0
n.times do |i|
  cnt += 1 if xy[i][0]>=bor
end
if max<cnt
  max=cnt
  place=[bor,sy]
end
# 左
bor = sx-1
cnt=0
n.times do |i|
  cnt += 1 if xy[i][0]<=bor
end
if max<cnt
  max=cnt
  place=[bor,sy]
end

# 上
bor = sy+1
cnt=0
n.times do |i|
  cnt += 1 if xy[i][1]>=bor
end
if max<cnt
  max=cnt
  place=[sx,bor]
end
# 下
bor = sy-1
cnt=0
n.times do |i|
  cnt += 1 if xy[i][1]<=bor
end
if max<cnt
  max=cnt
  place=[sx,bor]
end

puts max
puts place.join(" ")


George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.

The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.

Print a single integer — the answer to the problem.

NoteIn the first sample the set of the prepared problems meets the requirements for a good round.In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.

def checks(n_m, p1, p2)
  n_m = n_m.split.map(&:to_i)
  n = n_m[0]
  m = n_m[1]
  p1 = p1.split.map(&:to_i)
  p2 = p2.split.map(&:to_i)

  count = 0
  j = 0
  for i in (0..n - 1)
    for j in (j..m - 1)
      if p1[i] <= p2[j]
        count += 1
        j += 1
        break
      else
        j += 1
      end
    end
  end

  puts n - count
end

checks(gets, gets, gets)

n, m = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)
i = 0
j = 0
while i < n && j < m
  i += 1 if a[i] <= b[j]
  j += 1
end
puts n - i

n,m=gets.chomp.split.map(&:to_i)
a=gets.chomp.split.map(&:to_i)
b=gets.chomp.split.map(&:to_i)
i,j=0,0
while i<n && j<m
	i+=1 if a[i]<=b[j]
	j+=1
end
puts n-i

class ProblemA
  def initialize
    @dats = STDIN.read.split("\n")
    @n, @m = @dats[0].split(" ").map(&:to_i)
    @a_arr = @dats[1].split(" ").map(&:to_i) #need
    @b_arr = @dats[2].split(" ").map(&:to_i) #prepared
  end

  def solve
    i,j = [0, 0]
    j_memoize = nil

    need  = @a_arr.sort
    had   = @b_arr.sort
    max_touch = need.length

    while i < need.length && j < had.length do
      if need[i] <= had[j]
        max_touch -= 1
        i,j = i+1, j+1
        next
      else
        j = j+1
        next
      end
    end
    print max_touch
  end
end

solver = ProblemA.new
solver.solve

n,m=gets.chomp.split.collect{|a| a.to_i}
ns=gets.chomp.split.collect{|a| a.to_i}
ps=Hash.new(0)
gets.chomp.split.collect{|a| ps[a.to_i]+=1 }
next_hard=0
hardest=ps.keys.max
#p hardest
res=0
ns.each_index do |i|
 if next_hard<=ns[i]
   next_hard=ns[i]+1
 end
   if ps[ns[i]] == 0
#      puts i,next_hard,ps[next_hard]
      while next_hard <= hardest && ps[next_hard] == 0
        next_hard+=1
      end
 #     puts next_hard
 #     puts "saaaaaaaaaaa"
      if next_hard > hardest
         res+=1
      else
         ps[next_hard]-=1
      end
   end
end
#puts "sssssssssssS"
puts res

def binSearch(find_in, left, right, value_to_find)
    best = -1

    while left <= right
        mid = (left + right) / 2

        if find_in[mid].to_i >= value_to_find
            best = mid
            right = mid - 1
        else
            left = mid + 1
        end

    end

    return best
end

n_m = gets.chomp.split(/ /)
n = n_m[0].to_i
m = n_m[1].to_i

to_find = gets.chomp.split(/ /)
find_in = gets.chomp.split(/ /)
extra = 0

to_find.each do |i|
    pos = binSearch(find_in, 0, m - 1, i.to_i)

    if pos == -1
        extra += 1
    else
        for j in pos..m - 1 do
            find_in[j] = find_in[j + 1]
        end
        m -= 1
    end
end

puts extra

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

dummy = Hash.new(0)
arr.each do |a|
	dummy[a] += 1
end
ans = 0
count = {}.merge!(dummy)
# puts "#{count}"
comp.each do |c|
	key = c if count[c] && count[c] != 0
	key ||= count.keys.detect{|x|  x > c && count[x] != 0}
	# puts "key #{key}"
	if key
		count[key] -= 1
	else
		ans += 1
	end
end

puts ans

# http://codeforces.com/problemset/problem/387/B
# Two pointers

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

i, j = 0, 0
count = 0

while i < n && j < m
  if a[i] <= b[j]
    i += 1
    count += 1
  end

  j += 1
end

puts n - count

def solve(req, actual)
  i, j, req_size, act_size = [0, 0, req.size, actual.size]
  while i < req_size
    while j < act_size && actual[j] < req[i]
      j += 1
    end
    break if j == act_size
    i += 1
    j += 1
  end
  req_size - i
end

if __FILE__ == $0
  def read_next_line
    gets.chomp.split.map(&:to_i)
  end

  gets
  puts solve(read_next_line, read_next_line)
end

def read_data
	s = gets.chomp
	s.split.map &:to_i
end

n,m = read_data
a = read_data
b = read_data

a.sort! { |x,y| y <=> x}
b.sort! { |x,y| y <=> x}

result = 0
index = 0

for k in a
	if b[index] && b[index] >= k
		index += 1
	else
		result += 1
	end
end

puts result

def checks(n_m, p1, p2)
  n_m = n_m.split.map(&:to_i)
  n = n_m[0]
  m = n_m[1]
  p1 = p1.split.map(&:to_i)
  p2 = p2.split.map(&:to_i)

  count = 0
  for i in (0..n - 1)
    for j in (0..m - 1)
      if p1[i] <= p2[j]
        count += 1
        break
      end
    end
  end

  puts n - count
end

checks(gets, gets, gets)

def checks(n_m, p1, p2)
  n_m = n_m.split.map(&:to_i)
  n = n_m[0]
  m = n_m[1]
  p1 = p1.split.map(&:to_i).uniq
  p2 = p2.split.map(&:to_i)

  count = p1.size
  for i in (0..n - 1)
    for j in (0..m - 1)
      if p1[i] == p2[j]
        count -= 1
        break
      end
    end
  end
  if [0, 2, 3].include? count
    puts count
  else
    puts count
    puts p2
  end
end

checks(gets, gets, gets)

def checks(n_m, p1, p2)
  n_m = n_m.split.map(&:to_i)
  n = n_m[0]
  m = n_m[1]
  p1 = p1.split.map(&:to_i)
  p2 = p2.split.map(&:to_i)

  count = 0
  for i in (0..n - 1)
    for j in (0..m - 1)
      if p1[i] != p2[j]
        count += 1
        break
      end
    end
  end

  puts n - count
end

checks(gets, gets, gets)

def checks(n_m, p1, p2)
  n_m = n_m.split.map(&:to_i)
  n = n_m[0]
  m = n_m[1]
  p1 = p1.split.map(&:to_i).uniq
  p2 = p2.split.map(&:to_i)

  count = p1.size
  for i in (0..n - 1)
    for j in (0..m - 1)
      if p1[i] != p2[j]
        count += 1
        break
      end
    end
  end

  puts n - count
end

checks(gets, gets, gets)

def checks(n_m, p1, p2)
  n_m = n_m.split.map(&:to_i)
  n = n_m[0]
  m = n_m[1]
  p1 = p1.split.map(&:to_i)
  p2 = p2.split.map(&:to_i)

  count = 0
  for i in (0..n - 1)
    for j in (0..m - 1)
      if p1[i] == p2[j]
        count += 1
        break
      end
    end
  end

  puts n - count
end

checks(gets, gets, gets)

def checks(n_m, p1, p2)
  n_m = n_m.split.map(&:to_i)
  n = n_m[0]
  m = n_m[1]
  p1 = p1.split.map(&:to_i).uniq
  p2 = p2.split.map(&:to_i).uniq

  count = n
  for i in (0..n - 1)
    for j in (0..m - 1)
      if p1[i] == p2[j]
        count -= 1
        break
      end
    end
  end

  puts count
end

checks(gets, gets, gets)

def checks(n_m, p1, p2)
  n_m = n_m.split.map(&:to_i)
  n = n_m[0]
  m = n_m[1]
  p1 = p1.split.map(&:to_i).uniq
  p2 = p2.split.map(&:to_i).uniq

  count = p1.size
  for i in (0..n - 1)
    for j in (0..m - 1)
      if p1[i] == p2[j]
        count -= 1
        break
      end
    end
  end
  if [0, 2, 3].include? count
    puts count
  else
    puts p2
  end
end

checks(gets, gets, gets)

def checks(n_m, p1, p2)
  n_m = n_m.split.map(&:to_i)
  n = n_m[0]
  m = n_m[1]
  p1 = p1.split.map(&:to_i).uniq
  p2 = p2.split.map(&:to_i).uniq

  count = p1.size
  for i in (0..n - 1)
    for j in (0..m - 1)
      if p1[i] == p2[j]
        count -= 1
        break
      end
    end
  end

  puts count
end

checks(gets, gets, gets)

def checks(n_m, p1, p2)
  n_m = n_m.split.map(&:to_i)
  n = n_m[0]
  m = n_m[1]
  p1 = p1.split.map(&:to_i)
  p2 = p2.split.map(&:to_i)

  count = n
  for i in (0..n - 1)
    for j in (0..m - 1)
      if p1[i] == p2[j]
        count -= 1
        break
      end
    end
  end

  puts count
end

checks(gets, gets, gets)

def checks(n_m, p1, p2)
  n_m = n_m.split.map(&:to_i)
  n = n_m[0]
  m = n_m[1]
  p1 = p1.split.map(&:to_i)
  p2 = p2.split.map(&:to_i)

  count = 0
  for i in (0..n - 1)
    for j in (0..m - 1)
      if p1[i] <= p2[j]
        count += 1
        j += 1
        break
      else
        j += 1
      end
    end
  end

  puts n - count
end

checks(gets, gets, gets)

class ProblemA
  def initialize
    @dats = STDIN.read.split("\n")
    @n, @m = @dats[0].split(" ").map(&:to_i)
    @a_arr = @dats[1].split(" ").map(&:to_i) #need
    @b_arr = @dats[2].split(" ").map(&:to_i) #prepared
  end

  def solve
    i,j = [0, 0]
    j_memoize = nil

    need  = @a_arr
    had   = @b_arr
    max_touch = need.length

    while i < need.length && j < had.length do
      if need[i] == had[j]
        max_touch -= 1
        i,j = i+1, j+1
        next
      elsif need[i] < had[j]
        i = i+1
        next
      else
        j = j+1
        next
      end
    end
    print max_touch
  end
end

solver = ProblemA.new
solver.solve

n,m=gets.chomp.split.collect{|a| a.to_i}
ns=gets.chomp.split.collect{|a| a.to_i}
ps=Hash.new(0)
gets.chomp.split.collect{|a| ps[a.to_i]+=1 }
next_hard=0
res=0
for i in 0..n-1
 if next_hard<=ns[i]
   next_hard=ns[i]+1
 end
   if ps[ns[i]] == 0
      while next_hard < n && ps[next_hard] == 0
        next_hard+=1
      end
      if next_hard >= n
         res+=1
      else
         ps[next_hard]-=1
      end
   end
end

puts res

n,m=gets.chomp.split.collect{|a| a.to_i}
ns=gets.chomp.split.collect{|a| a.to_i}
ps=Hash.new(0)
gets.chomp.split.collect{|a| ps[a.to_i]+=1 }
next_hard=0
hardest=ps.keys.max
res=0
ns.each_index do |i|
 if next_hard<=ns[i]
   next_hard=ns[i]+1
 end
   if ps[ns[i]] == 0
#      puts i,next_hard
      while next_hard <= n && ps[next_hard] == 0
        next_hard+=1
      end
#      puts next_hard
 #     puts "saaaaaaaaaaa"
      if next_hard > hardest
         res+=1
      else
         ps[next_hard]-=1
      end
   end
end
#puts "sssssssssssS"
puts res

n,m=gets.chomp.split.collect{|a| a.to_i}
ns=gets.chomp.split.collect{|a| a.to_i}
ps=Hash.new(0)
gets.chomp.split.collect{|a| ps[a.to_i]+=1 }
next_hard=0
res=0
for i in 0..n-1
 if next_hard<=ns[i]
   next_hard=ns[i]+1
 end
   if ps[ns[i]] == 0
 #     puts i,next_hard
      while next_hard <= n && ps[next_hard] == 0
        next_hard+=1
      end
 #     puts next_hard
#      puts "saaaaaaaaaaa"
      if next_hard > n
         res+=1
      else
         ps[next_hard]-=1
      end
   end
end
#puts "sssssssssssS"
puts res

n_m_s = gets.chomp
n_m_a = n_m_s.split(/ /)

to_find_s = gets.chomp
to_find_a = to_find_s.split(/ /)

find_in_s = gets.chomp
find_in_a = find_in_s.split(/ /)

hash = Hash.new(0)

find_in_a.each do |i|
    hash[i] += 1
end

extra = 0

to_find_a.each do |i|
    hash[i] -= 1
    if hash[i] < 0
        hash[i] = 0
        extra += 1
    end
end

puts extra

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

dummy = Hash.new(0)
arr.each do |a|
	dummy[a] += 1
end
ans = 0
count = {}.merge!(dummy)
# puts "#{count}"
comp.each do |c|
	key = c if count[c]
	key ||= count.keys.detect{|x|  x > c && count[x] != 0}
	# puts "key #{key}"
	if key
		count[key] -= 1
	else
		ans += 1
	end
end

puts ans

# http://codeforces.com/problemset/problem/387/B
# Two pointers

n, m = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)
count = 0

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

puts n - count

# http://codeforces.com/problemset/problem/387/B
# Two pointers

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

i, j = 0, 0
count = 0

while i < n && j < m
  if b[j] == a[i]
    count += 1
    i += 1
    j += 1
  elsif b[j] > a[i]
    i += 1
  else
    j += 1
  end
end

puts n - count


Three friends are going to meet each other. Initially, the first friend stays at the position $$$x = a$$$, the second friend stays at the position $$$x = b$$$ and the third friend stays at the position $$$x = c$$$ on the coordinate axis $$$Ox$$$.In one minute each friend independently from other friends can change the position $$$x$$$ by $$$1$$$ to the left or by $$$1$$$ to the right (i.e. set $$$x := x - 1$$$ or $$$x := x + 1$$$) or even don't change it.Let's introduce the total pairwise distance — the sum of distances between each pair of friends. Let $$$a'$$$, $$$b'$$$ and $$$c'$$$ be the final positions of the first, the second and the third friend, correspondingly. Then the total pairwise distance is $$$|a' - b'| + |a' - c'| + |b' - c'|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.Friends are interested in the minimum total pairwise distance they can reach if they will move optimally. Each friend will move no more than once. So, more formally, they want to know the minimum total pairwise distance they can reach after one minute.You have to answer $$$q$$$ independent test cases.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 1000$$$) — the number of test cases. The next $$$q$$$ lines describe test cases. The $$$i$$$-th test case is given as three integers $$$a, b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) — initial positions of the first, second and third friend correspondingly. The positions of friends can be equal.

For each test case print the answer on it — the minimum total pairwise distance (the minimum sum of distances between each pair of friends) if friends change their positions optimally. Each friend will move no more than once. So, more formally, you have to find the minimum total pairwise distance they can reach after one minute.

gets.to_i.times do
	a = gets.split.map(&:to_i)
	puts [-1, 0, 1].repeated_permutation(3).map { |perm|
			a.zip(perm).map { _1 + _2 }.combination(2).sum { (_1 - _2).abs }
	     }.min
end

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

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

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

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
q=gi
q.times do
  aa=gsmi.sort
  diff = aa[2]-aa[0]
  if diff<=1
    puts 0
  else
    aa[2]-=1
    aa[0]+=1
    d = 2*(aa[2]-aa[0])
    puts d
  end
end


You are given a string $$$s$$$ of length $$$n$$$, which consists only of the first $$$k$$$ letters of the Latin alphabet. All letters in string $$$s$$$ are uppercase.A subsequence of string $$$s$$$ is a string that can be derived from $$$s$$$ by deleting some of its symbols without changing the order of the remaining symbols. For example, "ADE" and "BD" are subsequences of "ABCDE", but "DEA" is not.A subsequence of $$$s$$$ called good if the number of occurences of each of the first $$$k$$$ letters of the alphabet is the same.Find the length of the longest good subsequence of $$$s$$$.

The first line of the input contains integers $$$n$$$ ($$$1\le n \le 10^5$$$) and $$$k$$$ ($$$1 \le k \le 26$$$). The second line of the input contains the string $$$s$$$ of length $$$n$$$. String $$$s$$$ only contains uppercase letters from 'A' to the $$$k$$$-th letter of Latin alphabet.

Print the only integer — the length of the longest good subsequence of string $$$s$$$.

NoteIn the first example, "ACBCAB" ("ACAABCCAB") is one of the subsequences that has the same frequency of 'A', 'B' and 'C'. Subsequence "CAB" also has the same frequency of these letters, but doesn't have the maximum possible length.In the second example, none of the subsequences can have 'D', hence the answer is $$$0$$$.

Alphabet = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
used = {}
n,k = gets.split.map(&:to_i)
for i in 0...k
	used[Alphabet[i]] = 0
end

s = gets.chomp.split('')

for char in s
	used[char] += 1
end

puts used.values.min * k

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

ary = Array.new(k, 0)
hsh = {}
i = 0
('A'..'Z').to_a.each do |c|
  hsh[c]=i
  i+=1
end

str.each_char do |c|
  ary[hsh[c]] += 1
end

puts ary.min * k

n, k = gets.split.map(&:to_i)
s = gets.chomp.chars

cnt = Array.new(k, 0)

s.each do |ss|
  cnt[('A'..'Z').to_a.index(ss)] += 1
end

puts cnt.min * k

n, k = gets.split.map &:to_i
m = {}
('A'..'Z').to_a[0...k].each { |x| m[x] = 0 }
gets.strip.split('').each { |x| m[x] += 1 }
l = m['A']
m.each { |key, value| l = [l, value].min }
puts l*k

nk = gets.split(" ").map(&:to_i)
str = gets.chomp

n = nk[0]
k = nk[1]

hash = Hash.new(0)
str.each_char do |ch|
  hash[ch]+=1
end

if hash.keys.length < k
  puts 0
else
  puts hash.values.min*k
end


Nezzar has $$$n$$$ balls, numbered with integers $$$1, 2, \ldots, n$$$. Numbers $$$a_1, a_2, \ldots, a_n$$$ are written on them, respectively. Numbers on those balls form a non-decreasing sequence, which means that $$$a_i \leq a_{i+1}$$$ for all $$$1 \leq i < n$$$.Nezzar wants to color the balls using the minimum number of colors, such that the following holds.  For any color, numbers on balls will form a strictly increasing sequence if he keeps balls with this chosen color and discards all other balls.  Note that a sequence with the length at most $$$1$$$ is considered as a strictly increasing sequence.Please help Nezzar determine the minimum number of colors.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of testcases.  The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le n$$$). It is guaranteed that $$$a_1 \leq a_2 \leq \ldots \leq a_n$$$.

For each test case, output the minimum number of colors Nezzar can use.

NoteLet's match each color with some numbers. Then:In the first test case, one optimal color assignment is $$$[1,2,3,3,2,1]$$$.In the second test case, one optimal color assignment is $$$[1,2,1,2,1]$$$.

t = gets.to_i
t.times do
  n = gets.to_i
  a = gets.split.map {|x| x.to_i }
  puts a.map { |x| a.count(x) }.max
end

gets.to_i.times do
  n=gets.to_i
  a=gets.split.map(&:to_i)
  c=0
  q=0
  m=0
  a.each do |aa|
    if aa!=q
      m=c if c>m
      c=1
      q=aa
    else
      c+=1
    end
  end
  m=c if c>m
  puts m
end


A class of students got bored wearing the same pair of shoes every day, so they decided to shuffle their shoes among themselves. In this problem, a pair of shoes is inseparable and is considered as a single object.There are $$$n$$$ students in the class, and you are given an array $$$s$$$ in non-decreasing order, where $$$s_i$$$ is the shoe size of the $$$i$$$-th student. A shuffling of shoes is valid only if no student gets their own shoes and if every student gets shoes of size greater than or equal to their size. You have to output a permutation $$$p$$$ of $$$\{1,2,\ldots,n\}$$$ denoting a valid shuffling of shoes, where the $$$i$$$-th student gets the shoes of the $$$p_i$$$-th student ($$$p_i \ne i$$$). And output $$$-1$$$ if a valid shuffling does not exist.A permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1\leq n\leq10^5$$$) — the number of students. The second line of each test case contains $$$n$$$ integers $$$s_1, s_2,\ldots,s_n$$$ ($$$1\leq s_i\leq10^9$$$, and for all $$$1\le i<n$$$, $$$s_i\le s_{i+1}$$$) — the shoe sizes of the students. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, print the answer in a single line using the following format. If a valid shuffling does not exist, print the number $$$-1$$$ as the answer. If a valid shuffling exists, print $$$n$$$ space-separated integers — a permutation $$$p$$$ of $$$1,2,\ldots,n$$$ denoting a valid shuffling of shoes where the $$$i$$$-th student gets the shoes of the $$$p_i$$$-th student. If there are multiple answers, then print any of them.

NoteIn the first test case, any permutation $$$p$$$ of $$$1,\ldots,n$$$ where $$$p_i\ne i$$$ would represent a valid shuffling since all students have equal shoe sizes, and thus anyone can wear anyone's shoes.In the second test case, it can be shown that no valid shuffling is possible.

def solve(arr)
  hash = Hash.new { |h, k| h[k] = [] }
  arr.each_with_index do |size, i|
    hash[size] << i + 1
  end
  res = []
  hash.each do |_, indices|
    return -1 if indices.length < 2
    res.concat(indices[1..-1])
    res << indices[0]
  end
  res.join(' ')
end

tests = gets.to_i
tests.times do
  gets
  puts solve(gets.chomp.split(' '))
end


You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an n × n grid. The rows are numbered 1 through n from top to bottom, and the columns are numbered 1 through n from left to right. At the far side of the room lies a door locked with evil magical forces. The following inscriptions are written on the door: The cleaning of all evil will awaken the door! Being a very senior adventurer, you immediately realize what this means. You notice that every single cell in the grid are initially evil. You should purify all of these cells.The only method of tile purification known to you is by casting the "Purification" spell. You cast this spell on a single tile — then, all cells that are located in the same row and all cells that are located in the same column as the selected tile become purified (including the selected tile)! It is allowed to purify a cell more than once.You would like to purify all n × n cells while minimizing the number of times you cast the "Purification" spell. This sounds very easy, but you just noticed that some tiles are particularly more evil than the other tiles. You cannot cast the "Purification" spell on those particularly more evil tiles, not even after they have been purified. They can still be purified if a cell sharing the same row or the same column gets selected by the "Purification" spell.Please find some way to purify all the cells with the minimum number of spells cast. Print -1 if there is no such way.

The first line will contain a single integer n (1 ≤ n ≤ 100). Then, n lines follows, each contains n characters. The j-th character in the i-th row represents the cell located at row i and column j. It will be the character 'E' if it is a particularly more evil cell, and '.' otherwise.

If there exists no way to purify all the cells, output -1. Otherwise, if your solution casts x "Purification" spells (where x is the minimum possible number of spells), output x lines. Each line should consist of two integers denoting the row and column numbers of the cell on which you should cast the "Purification" spell.

NoteThe first example is illustrated as follows. Purple tiles are evil tiles that have not yet been purified. Red tile is the tile on which "Purification" is cast. Yellow tiles are the tiles being purified as a result of the current "Purification" spell. Green tiles are tiles that have been purified previously.   In the second example, it is impossible to purify the cell located at row 1 and column 1.For the third example:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin.The world can be represented by the first quadrant of a plane and the wall is built along the identity line (i.e. the line with the equation x = y). Any point below the wall belongs to the first kingdom while any point above the wall belongs to the second kingdom. There is a gate at any integer point on the line (i.e. at points (0, 0), (1, 1), (2, 2), ...). The wall and the gates do not belong to any of the kingdoms. Fafa is at the gate at position (0, 0) and he wants to walk around in the two kingdoms. He knows the sequence S of moves he will do. This sequence is a string where each character represents a move. The two possible moves Fafa will do are 'U' (move one step up, from (x, y) to (x, y + 1)) and 'R' (move one step right, from (x, y) to (x + 1, y)). Fafa wants to know the number of silver coins he needs to pay to walk around the two kingdoms following the sequence S. Note that if Fafa visits a gate without moving from one kingdom to another, he pays no silver coins. Also assume that he doesn't pay at the gate at point (0, 0), i. e. he is initially on the side he needs.

The first line of the input contains single integer n (1 ≤ n ≤ 105) — the number of moves in the walking sequence. The second line contains a string S of length n consisting of the characters 'U' and 'R' describing the required moves. Fafa will follow the sequence S in order from left to right.

On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence S.

NoteThe figure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins.

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

coordinate_movements = [[0, 0]]

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

payment = 0

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

puts payment


You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence.We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... < pk ≤ |s|) a subsequence of string s = s1s2... s|s|.String x = x1x2... x|x| is lexicographically larger than string y = y1y2... y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ... , x|y| = y|y|, or exists such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1. Characters in lines are compared like their ASCII codes.

The single line contains a non-empty string s, consisting only of lowercase English letters. The string's length doesn't exceed 105.

Print the lexicographically maximum subsequence of string s.

NoteLet's look at samples and see what the sought subsequences look like (they are marked with uppercase bold letters).The first sample: aBaBBAThe second sample: abbCbCCaCbbCBaaBA

# Codeforces Round #124
# Problem C -- Lexicographically Maximum Subsequence
answer = []
gets.each_char do |c|
    answer.pop while not answer.empty? and answer[-1] < c
    answer << c
end
puts answer.join("")


Ksusha is a beginner coder. Today she starts studying arrays. She has array a1, a2, ..., an, consisting of n positive integers.Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number!

The first line contains integer n (1 ≤ n ≤ 105), showing how many numbers the array has. The next line contains integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the array elements.

Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1. If there are multiple answers, you are allowed to print any of them.

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

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

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

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

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

  puts f ? a.first : -1
end

run if $0 == __FILE__

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

    ans = array[0]

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

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

a = A.new

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

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

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

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

puts ksuha(input)

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

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

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

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

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

end

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

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

if div
        puts num
else
        puts -1
end

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

    ans = array[0]

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

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

a = A.new

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

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

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

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

if div
        puts num
else
        puts -1
end


Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi (xi ≠ yi).In the tournament, each team plays exactly one home game and exactly one away game with each other team (n(n - 1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit.Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit.

The first line contains a single integer n (2 ≤ n ≤ 105) — the number of teams. Next n lines contain the description of the teams. The i-th line contains two space-separated numbers xi, yi (1 ≤ xi, yi ≤ 105; xi ≠ yi) — the color numbers for the home and away kits of the i-th team.

For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input.

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

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

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

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