You're given an array $$$a_1, \ldots, a_n$$$ of $$$n$$$ non-negative integers.Let's call it sharpened if and only if there exists an integer $$$1 \le k \le n$$$ such that $$$a_1 < a_2 < \ldots < a_k$$$ and $$$a_k > a_{k+1} > \ldots > a_n$$$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example:  The arrays $$$[4]$$$, $$$[0, 1]$$$, $$$[12, 10, 8]$$$ and $$$[3, 11, 15, 9, 7, 4]$$$ are sharpened;  The arrays $$$[2, 8, 2, 8, 6, 5]$$$, $$$[0, 1, 1, 0]$$$ and $$$[2, 5, 6, 9, 8, 8]$$$ are not sharpened. You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $$$i$$$ ($$$1 \le i \le n$$$) such that $$$a_i>0$$$ and assign $$$a_i := a_i - 1$$$.Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 15\ 000$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each test case contains a sequence of $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise.

NoteIn the first and the second test case of the first test, the given array is already sharpened.In the third test case of the first test, we can transform the array into $$$[3, 11, 15, 9, 7, 4]$$$ (decrease the first element $$$97$$$ times and decrease the last element $$$4$$$ times). It is sharpened because $$$3 < 11 < 15$$$ and $$$15 > 9 > 7 > 4$$$.In the fourth test case of the first test, it's impossible to make the given array sharpened.

num_tests = gets.chomp.to_i

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

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

T = gets.to_i

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

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

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

      if cur < 0
        success = false
      end
    end
  end

  success
end

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

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

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

num_tests = gets.chomp.to_i

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

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


You have a list of numbers from $$$1$$$ to $$$n$$$ written from left to right on the blackboard.You perform an algorithm consisting of several steps (steps are $$$1$$$-indexed). On the $$$i$$$-th step you wipe the $$$i$$$-th number (considering only remaining numbers). You wipe the whole number (not one digit).  When there are less than $$$i$$$ numbers remaining, you stop your algorithm. Now you wonder: what is the value of the $$$x$$$-th remaining number after the algorithm is stopped?

The first line contains one integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of queries. The next $$$T$$$ lines contain queries — one per line. All queries are independent. Each line contains two space-separated integers $$$n$$$ and $$$x$$$ ($$$1 \le x < n \le 10^{9}$$$) — the length of the list and the position we wonder about. It's guaranteed that after the algorithm ends, the list will still contain at least $$$x$$$ numbers.

Print $$$T$$$ integers (one per query) — the values of the $$$x$$$-th number after performing the algorithm for the corresponding queries.

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

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

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

n = gets
output = []

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

output.each do |e|
  puts e
end

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

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

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

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

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

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


$$$n$$$ distinct integers $$$x_1,x_2,\ldots,x_n$$$ are written on the board. Nezzar can perform the following operation multiple times.  Select two integers $$$x,y$$$ (not necessarily distinct) on the board, and write down $$$2x-y$$$. Note that you don't remove selected numbers. Now, Nezzar wonders if it is possible to have his favorite number $$$k$$$ on the board after applying above operation multiple times.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases.  The first line of each test case contains two integers $$$n,k$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$-10^{18} \le k \le 10^{18}$$$). The second line of each test case contains $$$n$$$ distinct integers $$$x_1,x_2,\ldots,x_n$$$ ($$$-10^{18} \le x_i \le 10^{18}$$$). It is guaranteed that the sum of $$$n$$$ for all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print "YES" on a single line if it is possible to have $$$k$$$ on the board. Otherwise, print "NO". You can print each letter in any case (upper or lower).

NoteIn the first test case, the number $$$1$$$ is already on the board.In the second test case, Nezzar could perform the following operations to write down $$$k=0$$$ on the board:   Select $$$x=3$$$ and $$$y=2$$$ and write down $$$4$$$ on the board.  Select $$$x=4$$$ and $$$y=7$$$ and write down $$$1$$$ on the board.  Select $$$x=1$$$ and $$$y=2$$$ and write down $$$0$$$ on the board. In the third test case, it is impossible to have the number $$$k = -1$$$ on the board.

gets.to_i.times do
  n,k=gets.split.map(&:to_i)
  x=gets.split.map(&:to_i).sort
  g=x[1]-x[0]
  (n-1).times do |i|
    g=g.gcd(x[i+1]-x[i])
  end
  if (x[0]-k)%g==0
    puts "YES"
  else
    puts "NO"
  end
end


Kawashiro Nitori is a girl who loves competitive programming.One day she found a string and an integer. As an advanced problem setter, she quickly thought of a problem.Given a string $$$s$$$ and a parameter $$$k$$$, you need to check if there exist $$$k+1$$$ non-empty strings $$$a_1,a_2...,a_{k+1}$$$, such that $$$$$$s=a_1+a_2+\ldots +a_k+a_{k+1}+R(a_k)+R(a_{k-1})+\ldots+R(a_{1}).$$$$$$ Here $$$+$$$ represents concatenation. We define $$$R(x)$$$ as a reversed string $$$x$$$. For example $$$R(abcd) = dcba$$$. Note that in the formula above the part $$$R(a_{k+1})$$$ is intentionally skipped.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1\le t\le 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case description contains two integers $$$n$$$, $$$k$$$ ($$$1\le n\le 100$$$, $$$0\le k\le \lfloor \frac{n}{2} \rfloor$$$)  — the length of the string $$$s$$$ and the parameter $$$k$$$. The second line of each test case description contains a single string $$$s$$$ of length $$$n$$$, consisting of lowercase English letters.

For each test case, print "YES" (without quotes), if it is possible to find $$$a_1,a_2,\ldots,a_{k+1}$$$, and "NO" (without quotes) otherwise. You can print letters in any case (upper or lower).

7
5 1
qwqwq
2 1
ab
3 1
ioi
4 2
icpc
22 0
dokidokiliteratureclub
19 8
imteamshanghaialice
6 3
aaaaaa

NoteIn the first test case, one possible solution is $$$a_1=qw$$$ and $$$a_2=q$$$.In the third test case, one possible solution is $$$a_1=i$$$ and $$$a_2=o$$$.In the fifth test case, one possible solution is $$$a_1=dokidokiliteratureclub$$$.

def fn(s, k)
  if k == 0
    if s.empty?
    puts "NO"
    else
    puts "YES"
    end
    return
  end

  if s.length == 2 * k
    puts "NO"
    return
  end
  l=0; r=s.length-1

  while l < r
    if s[l] == s[r]
      l+=1
      r-=1
    else
      puts "NO"
      return
    end
    if l == k
      puts "YES"
      return
    end
  end

  puts "NO"
end

gets.to_i.times {
  l, k = gets.chomp!.split(' ').map &:to_i
  s = gets.chomp
  fn(s[0,l], k)
}


Little X has n distinct integers: p1, p2, ..., pn. He wants to divide all of them into two sets A and B. The following two conditions must be satisfied:  If number x belongs to set A, then number a - x must also belong to set A.  If number x belongs to set B, then number b - x must also belong to set B. Help Little X divide the numbers into two sets or determine that it's impossible.

The first line contains three space-separated integers n, a, b (1 ≤ n ≤ 105; 1 ≤ a, b ≤ 109). The next line contains n space-separated distinct integers p1, p2, ..., pn (1 ≤ pi ≤ 109).

If there is a way to divide the numbers into two sets, then print "YES" in the first line. Then print n integers: b1, b2, ..., bn (bi equals either 0, or 1), describing the division. If bi equals to 0, then pi belongs to set A, otherwise it belongs to set B. If it's impossible, print "NO" (without the quotes).

NoteIt's OK if all the numbers are in the same set, and the other one is empty.

def find(u)
    if u != $f[u]
        $f[u] = find($f[u])
    end
    return $f[u]
end

def merge(x, y)
    x = find(x)
    y = find(y)
    if x != y
        $f[x] = y
    end
end

n, a, b = gets.split
n = n.to_i
a = a.to_i
b = b.to_i
$f = Array.new(n, 0)
(1..n + 2).each do |i|
    $f[i] = i
end
h = Hash.new
s = gets.split
(1..n).each do |i|
    x = s[i - 1].to_i
    h.store(x, i)
end
h.each do |k, v|
    if h[a - k] != nil
        merge(v, h[a - k])
    else
        merge(v, n + 2)
    end
    if h[b - k] != nil
        merge(v, h[b - k])
    else
        merge(v, n + 1)
    end
end
if find(n + 1) == find(n + 2)
    puts "NO"
else
    puts "YES"
    (1..n).each do |i|
        if find(i) == find(n + 1)
            print "0 "
        else
            print "1 "
        end
    end
    puts ""
end


Little Chris is very keen on his toy blocks. His teacher, however, wants Chris to solve more problems, so he decided to play a trick on Chris.There are exactly s blocks in Chris's set, each block has a unique number from 1 to s. Chris's teacher picks a subset of blocks X and keeps it to himself. He will give them back only if Chris can pick such a non-empty subset Y from the remaining blocks, that the equality holds:  "Are you kidding me?", asks Chris.For example, consider a case where s = 8 and Chris's teacher took the blocks with numbers 1, 4 and 5. One way for Chris to choose a set is to pick the blocks with numbers 3 and 6, see figure. Then the required sums would be equal: (1 - 1) + (4 - 1) + (5 - 1) = (8 - 3) + (8 - 6) = 7.  However, now Chris has exactly s = 106 blocks. Given the set X of blocks his teacher chooses, help Chris to find the required set Y!

The first line of input contains a single integer n (1 ≤ n ≤ 5·105), the number of blocks in the set X. The next line contains n distinct space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 106), the numbers of the blocks in X. Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++.

In the first line of output print a single integer m (1 ≤ m ≤ 106 - n), the number of blocks in the set Y. In the next line output m distinct space-separated integers y1, y2, ..., ym (1 ≤ yi ≤ 106), such that the required equality holds. The sets X and Y should not intersect, i.e. xi ≠ yj for all i, j (1 ≤ i ≤ n; 1 ≤ j ≤ m). It is guaranteed that at least one solution always exists. If there are multiple solutions, output any of them.

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


InputThe first line contains a single integer n (1 ≤ n ≤ 1000) — the number of points on a plane.Each of the next n lines contains two real coordinates xi and yi of the  point, specified with exactly 2 fractional digits. All coordinates are between  - 1000 and 1000, inclusive.OutputOutput a single real number θ — the answer to the problem statement. The absolute or relative error of your answer should be at most 10 - 2.ExamplesInput8-2.14 2.06-1.14 2.04-2.16 1.46-2.14 0.70-1.42 0.40-0.94 -0.48-1.42 -1.28-2.16 -1.62Output5.410Input52.26 1.442.28 0.642.30 -0.301.58 0.663.24 0.66Output5.620Input86.98 2.066.40 1.125.98 0.245.54 -0.607.16 0.307.82 1.248.34 0.248.74 -0.76Output5.480Input510.44 2.0610.90 0.8011.48 -0.4812.06 0.7612.54 2.06Output6.040Input816.94 2.4215.72 2.3814.82 1.5814.88 0.5015.76 -0.1616.86 -0.2017.00 0.8816.40 0.92Output6.040Input720.62 3.0021.06 2.2821.56 1.3621.66 0.5621.64 -0.5222.14 2.3222.62 3.04Output6.720

The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of points on a plane. Each of the next n lines contains two real coordinates xi and yi of the  point, specified with exactly 2 fractional digits. All coordinates are between  - 1000 and 1000, inclusive.

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

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


You are given a string $$$s$$$ consisting of the characters '0', '1', and '?'. You need to replace all the characters with '?' in the string $$$s$$$ by '0' or '1' so that the string becomes a palindrome and has exactly $$$a$$$ characters '0' and exactly $$$b$$$ characters '1'. Note that each of the characters '?' is replaced independently from the others.A string $$$t$$$ of length $$$n$$$ is called a palindrome if the equality $$$t[i] = t[n-i+1]$$$ is true for all $$$i$$$ ($$$1 \le i \le n$$$).For example, if $$$s=$$$"01?????0", $$$a=4$$$ and $$$b=4$$$, then you can replace the characters '?' in the following ways:   "01011010";  "01100110". For the given string $$$s$$$ and the numbers $$$a$$$ and $$$b$$$, replace all the characters with '?' in the string $$$s$$$ by '0' or '1' so that the string becomes a palindrome and has exactly $$$a$$$ characters '0' and exactly $$$b$$$ characters '1'.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. The first line of each test case contains two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 2 \cdot 10^5$$$, $$$a + b \ge 1$$$). The second line of each test case contains the string $$$s$$$ of length $$$a+b$$$, consisting of the characters '0', '1', and '?'. It is guaranteed that the sum of the string lengths of $$$s$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output:    "-1", if you can't replace all the characters '?' in the string $$$s$$$ by '0' or '1' so that the string becomes a palindrome and that it contains exactly $$$a$$$ characters '0' and exactly $$$b$$$ characters '1';  the string that is obtained as a result of the replacement, otherwise.  If there are several suitable ways to replace characters, you can output any.

t = gets.to_s.to_i

def solve(a, b, s)
  sr = s.reverse

  c0 = 0
  c1 = 0

  s.each do |x|
    if x == "0"
      c0 += 1
    end
    if x == "1"
      c1 += 1
    end
  end

  return "-1" if c0 > a
  return "-1" if c1 > b

  a = a - c0
  b = b - c1

  # pass 1
  s.each_index do |i|
    return "-1" if s[i] != sr[i] && s[i] != "?" && sr[i] != "?"
    next if s[i] == sr[i] && s[i] != "?"
    next if s[i] == "?" && sr[i] == "?"
    if s[i] == "?" && sr[i] == "0"
      s[i] = "0"
      a -= 1
      return "-1" if a < 0
    end
    if s[i] == "?" && sr[i] == "1"
      s[i] = "1"
      b -= 1
      return "-1" if b < 0
    end
  end

  # special case
  if s.size % 2 == 1 && s[s.size / 2] == "?"
    if a % 2 == 1
      s[s.size / 2] = "0"
      a -= 1
    elsif b % 2 == 1
      s[s.size / 2] = "1"
      b -= 1
    else
      return "-1"
    end
  end

  # pass 2
  s.each_index do |i|
    break if i >= s.size / 2
    if s[i] == "?"
      if a >= 2
        s[i] = "0"
        s[s.size - i - 1] = "0"
        a -= 2
      elsif b >= 2
        s[i] = "1"
        s[s.size - i - 1] = "1"
        b -= 2
      else
        return "-1"
      end
    end
  end

  return s.join("")
end

1.upto(t) do |casenum|
  a, b = gets.to_s.split.map {|x| x.to_i }
  s = gets.to_s.strip.split("")
  printf("%s\n", solve(a, b, s))
end


Родители Васи хотят, чтобы он как можно лучше учился. Поэтому если он получает подряд три положительные оценки («четвёрки» или «пятёрки»), они дарят ему подарок. Соответственно, оценки «единица», «двойка» и «тройка» родители Васи считают плохими. Когда Вася получает подряд три хорошие оценки, ему сразу вручают подарок, но для того, чтобы получить ещё один подарок, ему вновь надо получить подряд ещё три хорошие оценки.Например, если Вася получит подряд пять «четвёрок» оценок, а потом «двойку», то ему дадут только один подарок, а вот если бы «четвёрок» было уже шесть, то подарков было бы два. За месяц Вася получил n оценок. Вам предстоит посчитать количество подарков, которые получил Вася. Оценки будут даны именно в том порядке, в котором Вася их получал.

В первой строке входных данных следует целое положительное число n (3 ≤ n ≤ 1000) — количество оценок, полученных Васей. Во второй строке входных данных следует последовательность из n чисел a1, a2, ..., an (1 ≤ ai ≤ 5) — оценки, полученные Васей. Оценки заданы в том порядке, в котором Вася их получил.

Выведите одно целое число — количество подарков, полученных Васей.

ПримечаниеВ первом примере Вася получит два подарка — за первые три положительные оценки и за следующую тройку положительных оценок соответственно.

#!/usr/bin/env ruby

n = gets.to_i
inp = gets.split.map(&:to_i)
ret = 0
pos = 0
for i in 0..n-1
  if inp[i] >= 4 then pos += 1
  else pos = 0 end
  if pos == 3 then ret += 1; pos = 0 end
end
puts ret

#!/usr/bin/env ruby

n = gets.to_i
inp = gets.split.map(&:to_i)
ret = 0
pos = 0
for i in 0..n-1
  if inp[i] >= 4 then pos += 1 end
  if pos == 3 then ret += 1; pos = 0 end
end
puts ret


One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two primes". Let's modify it. How about a statement like that: "each integer no less than 12 can be expressed as the sum of two composite numbers." Not like the Goldbach's conjecture, I can prove this theorem.You are given an integer n no less than 12, express it as a sum of two composite numbers.

The only line contains an integer n (12 ≤ n ≤ 106).

Output two composite integers x and y (1 < x, y < n) such that x + y = n. If there are multiple solutions, you can output any of them.

NoteIn the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number.

nn = gets.to_i

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

require 'prime'

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

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

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

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

n=gets.to_i

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

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

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

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

n = gets.to_i

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

puts coco.to_s + " " + moco.to_s

require 'prime'

n = $stdin.readline.to_i

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

puts "#{a} #{b}"

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

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

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

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

n = gets.to_i

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

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

n = gets.chomp.to_i

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

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

n=gets.to_i

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

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

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

puts "#{x} #{y}"

n = gets.to_i

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

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

n = Integer(gets)

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

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

print a, " ", b

number = gets.chomp.to_i

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

n = gets.to_i

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

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

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

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

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

print number1.to_s + " "+ number2.to_s

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

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

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

require 'prime'

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

require 'prime'

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

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

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

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

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

  $o[n] = false
  return false
end

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

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

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

n = gets.chomp.to_i

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

i = 2
m = 0

until i==1000000 do

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

		num[m] = i
		m += 1

	end

	i += 1
end

for i in 2...m

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

end

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

n = gets.to_i

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

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

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

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

require 'prime'

number = gets.chomp.to_i

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

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

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

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

n = gets.to_i

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

p [coco, moco]

n = gets.to_i

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

puts coco.to_s + " " + moco.to_s

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

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

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

puts "#{x} #{y}"

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

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

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

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

puts "#{x} #{y}"

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

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

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

puts "#{x} #{y}"

n = gets.to_i

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

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

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

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

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

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

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


A permutation is a sequence of integers from 1 to n of length n containing each number exactly once. For example, (1), (4, 3, 5, 1, 2), (3, 2, 1) are permutations, and (1, 1), (4, 3, 1), (2, 3, 4) are not. There are many tasks on permutations. Today you are going to solve one of them. Let’s imagine that somebody took several permutations (perhaps, with a different number of elements), wrote them down consecutively as one array and then shuffled the resulting array. The task is to restore the initial permutations if it is possible.

The first line contains an integer n (1 ≤ n ≤ 105). The next line contains the mixed array of n integers, divided with a single space. The numbers in the array are from 1 to 105.

If this array can be split into several permutations so that every element of the array belongs to exactly one permutation, print in the first line the number of permutations. The second line should contain n numbers, corresponding to the elements of the given array. If the i-th element belongs to the first permutation, the i-th number should be 1, if it belongs to the second one, then its number should be 2 and so on. The order of the permutations’ numbering is free. If several solutions are possible, print any one of them. If there’s no solution, print in the first line  - 1.

NoteIn the first sample test the array is split into three permutations: (2, 1), (3, 2, 1, 4, 5), (1, 2). The first permutation is formed by the second and the fourth elements of the array, the second one — by the third, the fifth, the sixth, the seventh and the ninth elements, the third one — by the first and the eigth elements. Clearly, there are other splitting variants possible.

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

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


Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct English letters to all nucleotides, then the genome of a Berland dinosaur will represent a non-empty string consisting of small English letters, such that each letter occurs in it at most once.Scientists have n genome fragments that are represented as substrings (non-empty sequences of consecutive nucleotides) of the sought genome.You face the following problem: help scientists restore the dinosaur genome. It is guaranteed that the input is not contradictory and at least one suitable line always exists. When the scientists found out that you are a strong programmer, they asked you in addition to choose the one with the minimum length. If there are multiple such strings, choose any string.

The first line of the input contains a positive integer n (1 ≤ n ≤ 100) — the number of genome fragments. Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are distinct. Fragments could arbitrarily overlap and one fragment could be a substring of another one. It is guaranteed that there is such string of distinct letters that contains all the given fragments as substrings.

In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them.

n=gets.to_i

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

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

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

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

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

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

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

puts answer

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

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

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

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

puts answer


You have $$$n$$$ gifts and you want to give all of them to children. Of course, you don't want to offend anyone, so all gifts should be equal between each other. The $$$i$$$-th gift consists of $$$a_i$$$ candies and $$$b_i$$$ oranges.During one move, you can choose some gift $$$1 \le i \le n$$$ and do one of the following operations:  eat exactly one candy from this gift (decrease $$$a_i$$$ by one);  eat exactly one orange from this gift (decrease $$$b_i$$$ by one);  eat exactly one candy and exactly one orange from this gift (decrease both $$$a_i$$$ and $$$b_i$$$ by one). Of course, you can not eat a candy or orange if it's not present in the gift (so neither $$$a_i$$$ nor $$$b_i$$$ can become less than zero).As said above, all gifts should be equal. This means that after some sequence of moves the following two conditions should be satisfied: $$$a_1 = a_2 = \dots = a_n$$$ and $$$b_1 = b_2 = \dots = b_n$$$ (and $$$a_i$$$ equals $$$b_i$$$ is not necessary).Your task is to find the minimum number of moves required to equalize all the given gifts.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 50$$$) — the number of gifts. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the number of candies in the $$$i$$$-th gift. The third line of the test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le 10^9$$$), where $$$b_i$$$ is the number of oranges in the $$$i$$$-th gift.

For each test case, print one integer: the minimum number of moves required to equalize all the given gifts.

NoteIn the first test case of the example, we can perform the following sequence of moves:  choose the first gift and eat one orange from it, so $$$a = [3, 5, 6]$$$ and $$$b = [2, 2, 3]$$$;  choose the second gift and eat one candy from it, so $$$a = [3, 4, 6]$$$ and $$$b = [2, 2, 3]$$$;  choose the second gift and eat one candy from it, so $$$a = [3, 3, 6]$$$ and $$$b = [2, 2, 3]$$$;  choose the third gift and eat one candy and one orange from it, so $$$a = [3, 3, 5]$$$ and $$$b = [2, 2, 2]$$$;  choose the third gift and eat one candy from it, so $$$a = [3, 3, 4]$$$ and $$$b = [2, 2, 2]$$$;  choose the third gift and eat one candy from it, so $$$a = [3, 3, 3]$$$ and $$$b = [2, 2, 2]$$$.

gets.to_i.times do

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

  a_min = a.min
  b_min = b.min

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

gets.to_i.times do

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

  a_min = a.min
  b_min = b.min

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

gets.to_i.times do

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

  a_min = a.min
  b_min = b.min

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

t=gets.chomp.to_i

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

min_c= candy.min
min_o= oranges.min

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

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

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

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

times = gets.to_i

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

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

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

t = gets.chomp.to_i

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

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

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

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

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

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

  am = a.min
  bm = b.min

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

n = gets.chomp.to_i

tests = []

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

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

t=gets.chomp.to_i

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

min_c= candy.min
min_o= oranges.min

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

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

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

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

t=gets.chomp.to_i

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

min_c= candy.min
min_o= oranges.min

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

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

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

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

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


You are given a text consisting of n lines. Each line contains some space-separated words, consisting of lowercase English letters.We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowels: 'a', 'e', 'i', 'o', 'u' and 'y'.Each word of the text that contains at least one vowel can be divided into syllables. Each character should be a part of exactly one syllable. For example, the word "mamma" can be divided into syllables as "ma" and "mma", "mam" and "ma", and "mamm" and "a". Words that consist of only consonants should be ignored.The verse patterns for the given text is a sequence of n integers p1, p2, ..., pn. Text matches the given verse pattern if for each i from 1 to n one can divide words of the i-th line in syllables in such a way that the total number of syllables is equal to pi.You are given the text and the verse pattern. Check, if the given text matches the given verse pattern.

The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of lines in the text. The second line contains integers p1, ..., pn (0 ≤ pi ≤ 100) — the verse pattern. Next n lines contain the text itself. Text consists of lowercase English letters and spaces. It's guaranteed that all lines are non-empty, each line starts and ends with a letter and words are separated by exactly one space. The length of each line doesn't exceed 100 characters.

If the given text matches the given verse pattern, then print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes).

4
13 11 15 15
to be or not to be that is the question
whether tis nobler in the mind to suffer
the slings and arrows of outrageous fortune
or to take arms against a sea of troubles

NoteIn the first sample, one can split words into syllables in the following way: in-telco-dech al-len-geSince the word "ch" in the third line doesn't contain vowels, we can ignore it. As the result we get 2 syllabels in first two lines and 3 syllables in the third one.

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

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

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

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

pr = []

ok = true

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

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

#! /usr/bin/env ruby

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

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

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

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

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

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

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

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

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

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

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

puts b ? "YES" : "NO"

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

ans = 'YES'

n.times do |i|
    partStringNum = 0

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

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

puts ans

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

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

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

puts b ? "YES" : "NO"

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

puts b ? "YES" : "NO"

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

puts b ? "YES" : "NO"

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

ans = 'YES'

n.times do |i|
    partStringNum = 0

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

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

puts ans


Toad Ivan has $$$m$$$ pairs of integers, each integer is between $$$1$$$ and $$$n$$$, inclusive. The pairs are $$$(a_1, b_1), (a_2, b_2), \ldots, (a_m, b_m)$$$. He asks you to check if there exist two integers $$$x$$$ and $$$y$$$ ($$$1 \leq x < y \leq n$$$) such that in each given pair at least one integer is equal to $$$x$$$ or $$$y$$$.

The first line contains two space-separated integers $$$n$$$ and $$$m$$$ ($$$2 \leq n \leq 300\,000$$$, $$$1 \leq m \leq 300\,000$$$) — the upper bound on the values of integers in the pairs, and the number of given pairs. The next $$$m$$$ lines contain two integers each, the $$$i$$$-th of them contains two space-separated integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \leq a_i, b_i \leq n, a_i \neq b_i$$$) — the integers in the $$$i$$$-th pair.

Output "YES" if there exist two integers $$$x$$$ and $$$y$$$ ($$$1 \leq x < y \leq n$$$) such that in each given pair at least one integer is equal to $$$x$$$ or $$$y$$$. Otherwise, print "NO". You can print each letter in any case (upper or lower).

NoteIn the first example, you can't choose any $$$x$$$, $$$y$$$ because for each such pair you can find a given pair where both numbers are different from chosen integers.In the second example, you can choose $$$x=2$$$ and $$$y=4$$$.In the third example, you can choose $$$x=1$$$ and $$$y=2$$$.

def solve(n,m,ary)
    ary[0].each do |x|
        second_ary = []
        ary.each do |item|
            if !(item[0] == x or item[1] == x)
                second_ary << item
            end
        end
        if second_ary.length == 0
            return "YES"
        end
        flag = 0
        second_ary[0].each do |y|
            second_ary.each do |item|
                if !(item[0] == y or item[1] == y)
                    flag += 1
                    break
                end
            end
        end
        if flag != 2
            return "YES"
        end
    end
    return "NO"
end

n, m = gets.chomp.split.map(&:to_i)
ary = []
m.times do
    ary << gets.chomp.split.map(&:to_i)
end
ans = solve(n,m,ary)
puts ans


Let $$$s(x)$$$ be sum of digits in decimal representation of positive integer $$$x$$$. Given two integers $$$n$$$ and $$$m$$$, find some positive integers $$$a$$$ and $$$b$$$ such that   $$$s(a) \ge n$$$,  $$$s(b) \ge n$$$,  $$$s(a + b) \le m$$$.

The only line of input contain two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1129$$$).

Print two lines, one for decimal representation of $$$a$$$ and one for decimal representation of $$$b$$$. Both numbers must not contain leading zeros and must have length no more than $$$2230$$$.

NoteIn the first sample, we have $$$n = 6$$$ and $$$m = 5$$$. One valid solution is $$$a = 6$$$, $$$b = 7$$$. Indeed, we have $$$s(a) = 6 \ge n$$$ and $$$s(b) = 7 \ge n$$$, and also $$$s(a + b) = s(13) = 4 \le m$$$.

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

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

puts a
puts b

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

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

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

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


You are given two binary strings $$$x$$$ and $$$y$$$, which are binary representations of some two integers (let's denote these integers as $$$f(x)$$$ and $$$f(y)$$$). You can choose any integer $$$k \ge 0$$$, calculate the expression $$$s_k = f(x) + f(y) \cdot 2^k$$$ and write the binary representation of $$$s_k$$$ in reverse order (let's denote it as $$$rev_k$$$). For example, let $$$x = 1010$$$ and $$$y = 11$$$; you've chosen $$$k = 1$$$ and, since $$$2^1 = 10_2$$$, so $$$s_k = 1010_2 + 11_2 \cdot 10_2 = 10000_2$$$ and $$$rev_k = 00001$$$.For given $$$x$$$ and $$$y$$$, you need to choose such $$$k$$$ that $$$rev_k$$$ is lexicographically minimal (read notes if you don't know what does "lexicographically" means).It's guaranteed that, with given constraints, $$$k$$$ exists and is finite.

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of queries. Next $$$2T$$$ lines contain a description of queries: two lines per query. The first line contains one binary string $$$x$$$, consisting of no more than $$$10^5$$$ characters. Each character is either 0 or 1. The second line contains one binary string $$$y$$$, consisting of no more than $$$10^5$$$ characters. Each character is either 0 or 1. It's guaranteed, that $$$1 \le f(y) \le f(x)$$$ (where $$$f(x)$$$ is the integer represented by $$$x$$$, and $$$f(y)$$$ is the integer represented by $$$y$$$), both representations don't have any leading zeroes, the total length of $$$x$$$ over all queries doesn't exceed $$$10^5$$$, and the total length of $$$y$$$ over all queries doesn't exceed $$$10^5$$$.

Print $$$T$$$ integers (one per query). For each query print such $$$k$$$ that $$$rev_k$$$ is lexicographically minimal.

NoteThe first query was described in the legend.In the second query, it's optimal to choose $$$k = 3$$$. The $$$2^3 = 1000_2$$$ so $$$s_3 = 10001_2 + 110_2 \cdot 1000_2 = 10001 + 110000 = 1000001$$$ and $$$rev_3 = 1000001$$$. For example, if $$$k = 0$$$, then $$$s_0 = 10111$$$ and $$$rev_0 = 11101$$$, but $$$rev_3 = 1000001$$$ is lexicographically smaller than $$$rev_0 = 11101$$$.In the third query $$$s_0 = 10$$$ and $$$rev_0 = 01$$$. For example, $$$s_2 = 101$$$ and $$$rev_2 = 101$$$. And $$$01$$$ is lexicographically smaller than $$$101$$$.The quote from Wikipedia: "To determine which of two strings of characters comes when arranging in lexicographical order, their first letters are compared. If they differ, then the string whose first letter comes earlier in the alphabet comes before the other string. If the first letters are the same, then the second letters are compared, and so on. If a position is reached where one string has no more letters to compare while the other does, then the first (shorter) string is deemed to come first in alphabetical order."

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

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

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

def lowbit n
	n & -n
end

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


A and B are preparing themselves for programming contests.After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes.A likes lowercase letters of the Latin alphabet. He has assigned to each letter a number that shows how much he likes that letter (he has assigned negative numbers to the letters he dislikes). B likes substrings. He especially likes the ones that start and end with the same letter (their length must exceed one).Also, A and B have a string s. Now they are trying to find out how many substrings t of a string s are interesting to B (that is, t starts and ends with the same letter and its length is larger than one), and also the sum of values of all letters (assigned by A), except for the first and the last one is equal to zero.Naturally, A and B have quickly found the number of substrings t that are interesting to them. Can you do it?

The first line contains 26 integers xa, xb, ..., xz ( - 105 ≤ xi ≤ 105) — the value assigned to letters a, b, c, ..., z respectively. The second line contains string s of length between 1 and 105 characters, consisting of Lating lowercase letters— the string for which you need to calculate the answer.

NoteIn the first sample test strings satisfying the condition above are abca and bcab.In the second sample test strings satisfying the condition above are two occurences of aa.

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

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

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

char_positions = Array.new(26)

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

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

  temp = {}

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

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

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

p ans

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

@sum_table = {}

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

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

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

puts count


Anu has created her own function $$$f$$$: $$$f(x, y) = (x | y) - y$$$ where $$$|$$$ denotes the bitwise OR operation. For example, $$$f(11, 6) = (11|6) - 6 = 15 - 6 = 9$$$. It can be proved that for any nonnegative numbers $$$x$$$ and $$$y$$$ value of $$$f(x, y)$$$ is also nonnegative. She would like to research more about this function and has created multiple problems for herself. But she isn't able to solve all of them and needs your help. Here is one of these problems.A value of an array $$$[a_1, a_2, \dots, a_n]$$$ is defined as $$$f(f(\dots f(f(a_1, a_2), a_3), \dots a_{n-1}), a_n)$$$ (see notes). You are given an array with not necessarily distinct elements. How should you reorder its elements so that the value of the array is maximal possible?

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). Elements of the array are not guaranteed to be different.

Output $$$n$$$ integers, the reordering of the array with maximum value. If there are multiple answers, print any.

N = gets.to_i
A = gets.split.map(&:to_i)
L = A.map { |a| a.to_s(2).size }

bit_counter = Hash.new(0)

A.zip(L) do |a, len|
  len.times do |i|
    if a[i] == 1
      bit_counter[i] += 1
    end
  end
end

max_v = -1
max_idx = -1

A.zip(L).each_with_index do |(a, len), idx|
  v = 0
  x = 1

  len.times do |i|
    if bit_counter[i] == 1 && a[i] == 1
      v += x
    end

    x *= 2
  end

  if max_v < v
    max_v = v
    max_idx = idx
  end
end

A[0], A[max_idx] = A[max_idx], A[0]

puts A.join(' ')

N = gets.to_i
A = gets.split.map(&:to_i)
L = A.map { |a| a.to_s(2).size }

bit_counter = Hash.new(0)

A.zip(L) do |a, len|
  len.times do |i|
    if a[i] == 1
      bit_counter[i] += 1
    end
  end
end

max_v = -1
max_idx = -1

A.zip(L).each_with_index do |(a, len), idx|
  v = 0
  x = 1

  len.times do |i|
    if bit_counter[i].odd? && a[i] == 1
      v += x
    end

    x *= 2
  end

  if max_v < v
    max_v = v
    max_idx = idx
  end
end

A[0], A[max_idx] = A[max_idx], A[0]

puts A.join(' ')


Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section?

The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.

Print one integer — the number of times Kolya will have to empty the waste section.

NoteIn the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all.

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

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

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

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

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

puts c

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

# coding: utf-8

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

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

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

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

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

#!/usr/bin/env ruby

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

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

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

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

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

puts ans

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

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

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

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

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

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

puts r

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

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

# coding: utf-8

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

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

# coding: utf-8

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

# coding: utf-8

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

# coding: utf-8

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

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

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

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

# coding: utf-8

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

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

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

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

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

#!/usr/bin/env ruby

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

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

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

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

temp = 0

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

puts temp==d ? 0 : temp/d

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

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

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


You are living on an infinite plane with the Cartesian coordinate system on it. In one move you can go to any of the four adjacent points (left, right, up, down).More formally, if you are standing at the point $$$(x, y)$$$, you can:   go left, and move to $$$(x - 1, y)$$$, or  go right, and move to $$$(x + 1, y)$$$, or  go up, and move to $$$(x, y + 1)$$$, or  go down, and move to $$$(x, y - 1)$$$. There are $$$n$$$ boxes on this plane. The $$$i$$$-th box has coordinates $$$(x_i,y_i)$$$. It is guaranteed that the boxes are either on the $$$x$$$-axis or the $$$y$$$-axis. That is, either $$$x_i=0$$$ or $$$y_i=0$$$.You can collect a box if you and the box are at the same point. Find the minimum number of moves you have to perform to collect all of these boxes if you have to start and finish at the point $$$(0,0)$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of boxes. The $$$i$$$-th line of the following $$$n$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$-100 \le x_i, y_i \le 100$$$) — the coordinate of the $$$i$$$-th box. It is guaranteed that either $$$x_i=0$$$ or $$$y_i=0$$$. Do note that the sum of $$$n$$$ over all test cases is not bounded.

For each test case output a single integer — the minimum number of moves required.

NoteIn the first test case, a possible sequence of moves that uses the minimum number of moves required is shown below.  $$$$$$(0,0) \to (1,0) \to (1,1) \to (1, 2) \to (0,2) \to (-1,2) \to (-1,1) \to (-1,0) \to (-1,-1) \to (-1,-2) \to (0,-2) \to (0,-1) \to (0,0)$$$$$$ In the second test case, a possible sequence of moves that uses the minimum number of moves required is shown below.  $$$$$$(0,0) \to (0,1) \to (0,2) \to (-1, 2) \to (-2,2) \to (-3,2) \to (-3,1) \to (-3,0) \to (-3,-1) \to (-2,-1) \to (-1,-1) \to (0,-1) \to (0,0)$$$$$$ In the third test case, we can collect all boxes without making any moves.

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

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


The German University in Cairo (GUC) dorm houses are numbered from 1 to n. Underground water pipes connect these houses together. Each pipe has certain direction (water can flow only in this direction and not vice versa), and diameter (which characterizes the maximal amount of water it can handle).For each house, there is at most one pipe going into it and at most one pipe going out of it. With the new semester starting, GUC student and dorm resident, Lulu, wants to install tanks and taps at the dorms. For every house with an outgoing water pipe and without an incoming water pipe, Lulu should install a water tank at that house. For every house with an incoming water pipe and without an outgoing water pipe, Lulu should install a water tap at that house. Each tank house will convey water to all houses that have a sequence of pipes from the tank to it. Accordingly, each tap house will receive water originating from some tank house.In order to avoid pipes from bursting one week later (like what happened last semester), Lulu also has to consider the diameter of the pipes. The amount of water each tank conveys should not exceed the diameter of the pipes connecting a tank to its corresponding tap. Lulu wants to find the maximal amount of water that can be safely conveyed from each tank to its corresponding tap.

The first line contains two space-separated integers n and p (1 ≤ n ≤ 1000, 0 ≤ p ≤ n) — the number of houses and the number of pipes correspondingly.  Then p lines follow — the description of p pipes. The i-th line contains three integers ai bi di, indicating a pipe of diameter di going from house ai to house bi (1 ≤ ai, bi ≤ n, ai ≠ bi, 1 ≤ di ≤ 106). It is guaranteed that for each house there is at most one pipe going into it and at most one pipe going out of it.

Print integer t in the first line — the number of tank-tap pairs of houses. For the next t lines, print 3 integers per line, separated by spaces: tanki, tapi, and diameteri, where tanki ≠ tapi (1 ≤ i ≤ t). Here tanki and tapi are indexes of tank and tap houses respectively, and diameteri is the maximum amount of water that can be conveyed. All the t lines should be ordered (increasingly) by tanki.

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

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

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

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

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

end

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

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

#!/usr/bin/ruby

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

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

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

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

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

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

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

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

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

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

end

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

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

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

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

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

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

end

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

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

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

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

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

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

end

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

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

#!/usr/bin/ruby

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

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

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


You are given two integers $$$n$$$ and $$$m$$$ ($$$m < n$$$). Consider a convex regular polygon of $$$n$$$ vertices. Recall that a regular polygon is a polygon that is equiangular (all angles are equal in measure) and equilateral (all sides have the same length).  Examples of convex regular polygons Your task is to say if it is possible to build another convex regular polygon with $$$m$$$ vertices such that its center coincides with the center of the initial polygon and each of its vertices is some vertex of the initial polygon.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. Each test case is given as two space-separated integers $$$n$$$ and $$$m$$$ ($$$3 \le m < n \le 100$$$) — the number of vertices in the initial polygon and the number of vertices in the polygon you want to build.

For each test case, print the answer — "YES" (without quotes), if it is possible to build another convex regular polygon with $$$m$$$ vertices such that its center coincides with the center of the initial polygon and each of its vertices is some vertex of the initial polygon and "NO" otherwise.

Note  The first test case of the example It can be shown that the answer for the second test case of the example is "NO".

T = gets.to_i

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

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

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

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

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

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


You are given an integer $$$n$$$.Let's define $$$s(n)$$$ as the string "BAN" concatenated $$$n$$$ times. For example, $$$s(1)$$$ = "BAN", $$$s(3)$$$ = "BANBANBAN". Note that the length of the string $$$s(n)$$$ is equal to $$$3n$$$.Consider $$$s(n)$$$. You can perform the following operation on $$$s(n)$$$ any number of times (possibly zero): Select any two distinct indices $$$i$$$ and $$$j$$$ $$$(1 \leq i, j \leq 3n, i \ne j)$$$. Then, swap $$$s(n)_i$$$ and $$$s(n)_j$$$. You want the string "BAN" to not appear in $$$s(n)$$$ as a subsequence. What's the smallest number of operations you have to do to achieve this? Also, find one such shortest sequence of operations.A string $$$a$$$ is a subsequence of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ $$$(1 \leq t \leq 100)$$$  — the number of test cases. The description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$.

For each test case, in the first line output $$$m$$$ ($$$0 \le m \le 10^5$$$) — the minimum number of operations required. It's guaranteed that the objective is always achievable in at most $$$10^5$$$ operations under the constraints of the problem.  Then, output $$$m$$$ lines. The $$$k$$$-th of these lines should contain two integers $$$i_k$$$, $$$j_k$$$ $$$(1\leq i_k, j_k \leq 3n, i_k \ne j_k)$$$ denoting that you want to swap characters at indices $$$i_k$$$ and $$$j_k$$$ at the $$$k$$$-th operation.  After all $$$m$$$ operations, "BAN" must not appear in $$$s(n)$$$ as a subsequence.  If there are multiple possible answers, output any.

NoteIn the first testcase, $$$s(1) = $$$ "BAN", we can swap $$$s(1)_1$$$ and $$$s(1)_2$$$, converting $$$s(1)$$$ to "ABN", which does not contain "BAN" as a subsequence.In the second testcase, $$$s(2) = $$$ "BANBAN", we can swap $$$s(2)_2$$$ and $$$s(2)_6$$$, converting $$$s(2)$$$ to "BNNBAA", which does not contain "BAN" as a subsequence.

gets.to_i.times do
    n=gets.to_i
    puts (n+1)/2
    ((n+1)/2).times do|i|
        puts  "#{i*3+1} #{(n-i)*3-1}"
    end
end


Mikhail walks on a Cartesian plane. He starts at the point $$$(0, 0)$$$, and in one move he can go to any of eight adjacent points. For example, if Mikhail is currently at the point $$$(0, 0)$$$, he can go to any of the following points in one move:   $$$(1, 0)$$$;  $$$(1, 1)$$$;  $$$(0, 1)$$$;  $$$(-1, 1)$$$;  $$$(-1, 0)$$$;  $$$(-1, -1)$$$;  $$$(0, -1)$$$;  $$$(1, -1)$$$. If Mikhail goes from the point $$$(x1, y1)$$$ to the point $$$(x2, y2)$$$ in one move, and $$$x1 \ne x2$$$ and $$$y1 \ne y2$$$, then such a move is called a diagonal move.Mikhail has $$$q$$$ queries. For the $$$i$$$-th query Mikhail's target is to go to the point $$$(n_i, m_i)$$$ from the point $$$(0, 0)$$$ in exactly $$$k_i$$$ moves. Among all possible movements he want to choose one with the maximum number of diagonal moves. Your task is to find the maximum number of diagonal moves or find that it is impossible to go from the point $$$(0, 0)$$$ to the point $$$(n_i, m_i)$$$ in $$$k_i$$$ moves.Note that Mikhail can visit any point any number of times (even the destination point!).

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Then $$$q$$$ lines follow. The $$$i$$$-th of these $$$q$$$ lines contains three integers $$$n_i$$$, $$$m_i$$$ and $$$k_i$$$ ($$$1 \le n_i, m_i, k_i \le 10^{18}$$$) — $$$x$$$-coordinate of the destination point of the query, $$$y$$$-coordinate of the destination point of the query and the number of moves in the query, correspondingly.

Print $$$q$$$ integers. The $$$i$$$-th integer should be equal to -1 if Mikhail cannot go from the point $$$(0, 0)$$$ to the point $$$(n_i, m_i)$$$ in exactly $$$k_i$$$ moves described above. Otherwise the $$$i$$$-th integer should be equal to the the maximum number of diagonal moves among all possible movements.

NoteOne of the possible answers to the first test case: $$$(0, 0) \to (1, 0) \to (1, 1) \to (2, 2)$$$.One of the possible answers to the second test case: $$$(0, 0) \to (0, 1) \to (1, 2) \to (0, 3) \to (1, 4) \to (2, 3) \to (3, 2) \to (4, 3)$$$.In the third test case Mikhail cannot reach the point $$$(10, 1)$$$ in 9 moves.

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

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

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

q = gets.to_i

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

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

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

nq = gets.to_i

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


You are given one integer number $$$n$$$. Find three distinct integers $$$a, b, c$$$ such that $$$2 \le a, b, c$$$ and $$$a \cdot b \cdot c = n$$$ or say that it is impossible to do it.If there are several answers, you can print any.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The next $$$n$$$ lines describe test cases. The $$$i$$$-th test case is given on a new line as one integer $$$n$$$ ($$$2 \le n \le 10^9$$$).

For each test case, print the answer on it. Print "NO" if it is impossible to represent $$$n$$$ as $$$a \cdot b \cdot c$$$ for some distinct integers $$$a, b, c$$$ such that $$$2 \le a, b, c$$$. Otherwise, print "YES" and any possible such representation.

#!usr/bin/env ruby

# https://codeforces.com/problemset/problem/1294/C

require 'prime'

n = gets.to_i

primes = []
Prime.each(31630) { |p| primes << p }

n.times do
 num = gets.to_i
 answer = []
 temp = 1
 i = 0
 limit = Math.sqrt(num).floor
 failed = false

 while answer.size < 2
  if num % primes[i] == 0
   if answer.include?(primes[i])
    temp *= primes[i]
    num /= primes[i]

    if !answer.include?(temp)
     answer << temp
     temp = 1
    end

   else
    answer << primes[i]
    num /= primes[i]
   end

  else
   i += 1
   if primes[i] > limit
    failed = true
    break
   end
  end
 end

 rest = temp * num
 failed = true if rest == 1 || answer.include?(rest)

 unless failed
  answer << rest
  puts "YES"
  puts answer.join(' ')
 else
  puts "NO"
 end
end

require 'prime'

T = gets.to_i

T.times do
  n = gets.to_i

  primes = Hash[n.prime_division]

  used = Hash.new(false)
  ans = []
  n = 1

  primes.each do |v, e|
    e.times do
      n *= v

      unless used[n]
        ans << n
        used[n] = true
        n = 1
      end
    end
  end

  if ans.size >= 3
    ans << n
    a, b, *r = ans
    c = r.inject(:*)

    puts 'YES'
    puts [a, b, c].join(' ')
  else
    puts 'NO'
  end
end

# coding: utf-8

# if __FILE__ == $0
# end

t = gets.to_i
primes = [2,3]
t.times {
    n = gets.chomp
    len = n.length
    n = n.to_i
    # 큰 수를 절반으로 나눠서 표현할 수 있다.
    # 너무 잘게 표기하면 목적에 부합하지 않으니까 절반으로만.
    # 앞부분과 뒷부분의 최대공약수를 구한다.
    # 최대공약수로 다시 원 수를 나눈다. 최대 공약수를 소인수 분해를 한다.
    # ... 이거 나름 신박했는데 실패함
    # 풀이를 보면, 2...sqrt(n) 까지 두 번 나눠보는식임.
    # 그리고 그 나눈 수를 set에 넣어둔다.
    # set 길이가 2 넘기면 OK.
    # a<b<c 일때, n/(a*b) 가 나누어 떨어지만 n/(a*b) = c' 이 c가 될 수 있는 가능성은 아래와 같음
    # i) 1이 되어선 안됨 (distinct한 두 수로만 나눠 떨어짐) ii) a가 되어선 안됨
    # iii) b가 되어선 안됨
    if n < 2*3*4
        puts "NO" # minimum distinct
    else
        sqrt_n = Math.sqrt(n).ceil
        collected = {}
        2.times {
            for i in 2..sqrt_n
                if n%i == 0 && collected[i] == nil
                    n /= i
                    collected[i] ||= 0
                    collected[i] += 1
                    break
                end
            end
        }

        if collected.size > 1 && collected[n] == nil
            puts "YES"
            puts "#{collected.keys.join(' ')} #{n}"
        else
            puts "NO"
        end
    end

}

#!usr/bin/env ruby

# https://codeforces.com/problemset/problem/1294/C

require 'prime'

n = gets.to_i

primes = []
Prime.each(31610) { |p| primes << p }

n.times do
 num = gets.to_i
 answer = []
 temp = 1
 i = 0
 limit = Math.sqrt(num).floor
 failed = false

 while answer.size < 2
  if num % primes[i] == 0
   if answer.include?(primes[i])
    temp *= primes[i]
    num /= primes[i]

    if !answer.include?(temp)
     answer << temp
     temp = 1
    end

   else
    answer << primes[i]
    num /= primes[i]
   end

  else
   i += 1
   if num == 1 || primes[i] > limit
    failed = true
    break
   end
  end
 end

 failed = true if num == 1 || answer.include?(num)

 unless failed
  answer << num
  puts "YES"
  puts answer.join(' ')
 else
  puts "NO"
 end
end

#!usr/bin/env ruby

# https://codeforces.com/problemset/problem/1294/C

require 'prime'

n = gets.to_i

primes = []
Prime.each(31610) { |p| primes << p }

n.times do
 num = gets.to_i
 answer = []
 temp = 1
 i = 0
 limit = Math.sqrt(num).floor
 failed = false

 while answer.size < 2
  if num % primes[i] == 0
   if answer.include?(primes[i])
    temp *= primes[i]
    if !answer.include?(temp)
     answer << temp
     num /= temp
    end

   else
    answer << primes[i]
    num /= primes[i]
   end

  else
   i += 1
   if primes[i] > limit
    failed = true
    break
   end
  end
 end

 unless failed
  answer << num
  puts "YES"
  puts answer.join(' ')
 else
  puts "NO"
 end
end

#!usr/bin/env ruby

# https://codeforces.com/problemset/problem/1294/C

require 'prime'

n = gets.to_i

primes = []
Prime.each(31610) { |p| primes << p }

n.times do
 num = gets.to_i
 answer = []
 temp = 1
 i = 0
 limit = Math.sqrt(num).floor
 failed = false

 while answer.size < 2
  if num % primes[i] == 0
   if answer.include?(primes[i])
    temp *= primes[i]
    if !answer.include?(temp)
     answer << temp
     num /= temp
    end

   else
    answer << primes[i]
    num /= primes[i]
   end

  else
   i += 1
   if primes[i] > limit
    failed = true
    break
   end
  end
 end

 failed = true if answer.include? num

 unless failed
  answer << num
  puts "YES"
  puts answer.join(' ')
 else
  puts "NO"
 end
end

#!usr/bin/env ruby

# https://codeforces.com/problemset/problem/1294/C

require 'prime'

n = gets.to_i

primes = []
Prime.each(31610) { |p| primes << p }

n.times do
 num = gets.to_i
 answer = []
 temp = 1
 i = 0
 limit = Math.sqrt(num).floor
 failed = false

 while answer.size < 2
  if num % primes[i] == 0
   if answer.include?(primes[i])
    temp *= primes[i]
    num /= primes[i]

    if !answer.include?(temp)
     answer << temp
     temp = 1
    end

   else
    answer << primes[i]
    num /= primes[i]
   end

  else
   i += 1
   if num == 1 || primes[i] > limit
    failed = true
    break
   end
  end
 end

 failed = true if answer.include? num

 unless failed
  answer << num
  puts "YES"
  puts answer.join(' ')
 else
  puts "NO"
 end
end

require 'prime'

T = gets.to_i

T.times do
  n = gets.to_i

  primes = Hash[n.prime_division]

  used = Hash.new(false)
  ans = []
  n = 1

  primes.each do |v, e|
    e.times do
      n *= v

      unless used[n]
        ans << n
        used[n] = true
        n = 1
      end
    end
  end

  if ans.size >= 3
    a, b, *r = ans
    c = r.inject(:*)

    puts 'YES'
    puts [a, b, c].join(' ')
  else
    puts 'NO'
  end
end

require 'prime'

T = gets.to_i

T.times do
  n = gets.to_i

  primes = Hash[n.prime_division]

  used = Hash.new(false)
  ans = []

  primes.each do |v, e|
    n = 1

    e.times do
      n *= v

      unless used[n]
        ans << n
        used[n] = true
        n = 1
      end
    end
  end

  if ans.size >= 3
    a, b, *r = ans
    c = r.inject(:*)

    puts 'YES'
    puts [a, b, c].join(' ')
  else
    puts 'NO'
  end
end

# coding: utf-8

# if __FILE__ == $0
# end

t = gets.to_i
primes = [2,3]
t.times {
    n = gets.chomp
    len = n.length
    n = n.to_i
    # 큰 수를 절반으로 나눠서 표현할 수 있다.
    # 너무 잘게 표기하면 목적에 부합하지 않으니까 절반으로만.
    # 앞부분과 뒷부분의 최대공약수를 구한다.
    # 최대공약수로 다시 원 수를 나눈다. 최대 공약수를 소인수 분해를 한다.
    # ... 이거 나름 신박했는데 실패함
    # 풀이를 보면, 2...sqrt(n) 까지 두 번 나눠보는식임.
    # 그리고 그 나눈 수를 set에 넣어둔다.
    # set 길이가 2 넘기면 OK.
    # a<b<c 일때, n/(a*b) 가 나누어 떨어지만 n/(a*b) = c' 이 c가 될 수 있는 가능성은 아래와 같음
    # i) 1이 되어선 안됨 (distinct한 두 수로만 나눠 떨어짐) ii) a가 되어선 안됨
    # iii) b가 되어선 안됨
    if n < 2*3*4
        puts "NO" # minimum distinct
    else
        sqrt_n = Math.sqrt(n).ceil
        collected = {}
        2.times {
            for i in 2..sqrt_n
                if n%i == 0 && collected[i] == nil
                    n /= i
                    collected[i] ||= 0
                    collected[i] += 1
                    break
                end
            end
        }

        if collected.size > 1
            puts "YES"
            puts "#{collected.keys.join(' ')} #{n}"
        else
            puts "NO"
        end
    end

}