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

}


PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, if both play optimally?

The first input line contains two integers n and m (1 ≤ n, m ≤ 103) — number of words PolandBall and EnemyBall know, respectively. Then n strings follow, one per line — words familiar to PolandBall. Then m strings follow, one per line — words familiar to EnemyBall. Note that one Ball cannot know a word more than once (strings are unique), but some words can be known by both players. Each word is non-empty and consists of no more than 500 lowercase English alphabet letters.

In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally.

2 2
kremowka
wadowicka
kremowka
wiedenska

NoteIn the first example PolandBall knows much more words and wins effortlessly.In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins.

n,m=gets.split.map(&:to_i)
x,y=[n,m].map{|e|e.times.map{gets.chomp}}
n+=1 if (x&y).size.odd?
puts [:NO,:YES,:NO][n<=>m]

n, m = gets.split.map(&:to_i)
a, b = [], []
n.times { a << gets.chomp }
m.times { b << gets.chomp }
x = (a & b).count
ans = (x + 1 >> 1) + n - x > (x >> 1) + m - x
puts ans ? "YES" : "NO"

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

player1 = Array.new(n) { |e| gets }
player2 = Array.new(m) { |e| gets }

common = player1 & player2

player1 = player1 - common
player2 = player2 - common

puts (if player1.length + common.length % 2 > player2.length then "YES" else "NO" end)

n, m = gets.strip.split.map(&:to_i)
p = Array.new(n)
e = Array.new(m)
n.times do |i|
    s = gets.strip
    p[i] = s
end
common = 0
m.times do |i|
    s = gets.strip
    e[i] = s
    common += 1 if p.include? s
end
n -= common
m -= common
ans = "YES"
total = n + m
i = 1
while true
    if i.odd?
        if common > 0
            common -= 1
        else
            if n > 0
                n -= 1
            else
                ans = "NO"
                break
            end
        end
    else
        if common > 0
            common -= 1
        else
            if m > 0
                m -= 1
            else
                break
            end
        end
    end
    i += 1
end
puts ans

n, m =gets.chomp.split(" ").map(&:to_i)
list = Array.new; list2 = Array.new
ctr =0
for i in 0..n-1
  list[i] = gets.to_s
end
for i in 0..m-1
  list2[i] = gets.to_s
end
for i in 0..n-1
  for j in 0..m-1
    if list[i] == list2[j]
      ctr += 1
    end
  end
end
if (ctr%2 == 0)
  n, m = n-ctr/2, m-ctr/2
else
  n,m = n-ctr/2, m-ctr/2 - 1
end
puts n>m ? "YES": "NO"

#就是polandball的n个词是互不相同的！
#就是enemyball的m个词是互不相同的！
#一个策略是：先说两个人共同的词，让对方能使用的词更少！
nm=gets.chomp.split.map{ |x| x.to_i }
n=nm[0]
m=nm[1]
polandball=[]
n.times do
	x=gets.chomp
	polandball.push(x)
end
enemyball=[]
m.times do
	x=gets.chomp
	enemyball.push(x)
end
polandball.sort!
enemyball.sort!
#puts polandball.join(" ")
#puts enemyball.join(" ")
i=0
j=0
same=0
#puts "#{polandball.length} #{enemyball.length}"
while true
	if i>=polandball.length || j>=enemyball.length
		break
	end
	case polandball[i]<=>enemyball[j]
	when 0
		#puts "#{polandball[i]}==#{enemyball[j]} #{i} #{j}"
		same+=1
		i+=1
		j+=1
	when -1
		i+=1
	else
		j+=1
	end
end
#puts "same=#{same}"
polandball_word=polandball.length-same+same/2
if same%2==1
	polandball_word+=1
end
enemyball_word=enemyball.length-same+same/2
#puts "#{polandball_word} #{enemyball_word}"
if polandball_word>enemyball_word
	puts "YES"
else
	puts "NO"
end

#!/usr/bin/env ruby

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

if n > m
  puts "YES"
  exit 0
elsif n < m
  puts "NO"
  exit 0
end

polandball_words = []
n.times do
  polandball_words << gets.chop
end

enemyball_words = []
m.times do
  enemyball_words << gets.chop
end

common_words = polandball_words & enemyball_words
common_words_size = common_words.size
if common_words_size % 2 == 0
  puts "NO"
else
  puts "YES"
end

n,m=gets.split.map(&:to_i)
x,y=[n,m].map{|e|e.times.map{gets.chomp}}
n+=1 if (x&y).size.even?
puts [:NO,:YES,:NO][n<=>m]

n,m=gets.split.map(&:to_i)
x,y=[n,m].map{|e|e.times.map{gets.chomp}}
n+=1 if (x&y).size.even?
puts [:YES,:YES,:NO][n<=>m]

n, m = gets.split.map(&:to_i)
a, b = [], []
n.times { a << gets.chomp }
m.times { b << gets.chomp }
x = (a - b).count
ans = (x + 1 >> 1) + n - x > (x >> 1) + m - x
puts ans ? "YES" : "NO"

n, m = gets.strip.split.map(&:to_i)
p = Array.new(n)
e = Array.new(m)
n.times do |i|
    s = gets.strip
    p[i] = s
end
m.times do |i|
    s = gets.strip
    e[i] = s
end
said = []
ans = "YES"
total = n + m
i = 1
while i <= total
    s = nil
    curr = ""
    if i.odd?
        s = p.shift
        curr = "P"
    else
        s = e.shift
        curr = "E"
    end
    while said.include? s
        if i.odd?
            s = p.shift
        else
            s = e.shift
        end
    end
    if s.nil?
        ans = "NO" if curr == "P"
        break
    end
    said.push s
    i += 1
end
ans = "NO" if ans == "YES" && i.odd?
puts ans

n, m = gets.strip.split.map(&:to_i)
p = Array.new(n)
e = Array.new(m)
n.times do
    s = gets.strip
    p.push s
end
m.times do
    s = gets.strip
    e.push s
end
said = []
ans = "YES"
total = n + m
i = 1
while i <= total
    s = nil
    curr = ""
    if i.odd?
        s = p.pop
        curr = "P"
    else
        s = e.pop
        curr = "E"
    end
    if s.nil?
        ans = "NO" if curr == "P"
        break
    end
    next if said.include? s
    said.push s
    i += 1
end
puts ans

n, m = gets.strip.split.map(&:to_i)
p = Array.new(n)
e = Array.new(m)
n.times do
    s = gets.strip
    p.push s
end
m.times do
    s = gets.strip
    e.push s
end
said = []
ans = "YES"
if n < m
    ans = "NO"
else
    total = n + m
    i = 1
    while i <= total && p.length > 0 && e.length > 0
        s = i.odd? ? p.pop : e.pop
        next if said.include? s
        said.push s
        i += 1
    end
    ans = "NO" if p.length == 0 && e.length > 0
end
puts ans

n, m = gets.strip.split.map(&:to_i)
p = Array.new(n)
e = Array.new(m)
n.times do |i|
    s = gets.strip
    p[i] = s
end
m.times do |i|
    s = gets.strip
    e[i] = s
end
said = []
ans = "YES"
total = n + m
i = 1
while i <= total
    s = nil
    curr = ""
    if i.odd?
        s = p.shift
        curr = "P"
    else
        s = e.shift
        curr = "E"
    end
    next if said.include? s
    if s.nil?
        ans = "NO" if curr == "P"
        break
    end
    said.push s
    i += 1
end
puts ans

n, m =gets.chomp.split(" ").map(&:to_i)
list = Array.new; list2 = Array.new
ctr =0
for i in 0..n-1
  list[i] = gets
end
for i in 0..m-1
  list2[i] = gets
end
for i in 0..n-1
  for j in i..m-1
    if list[i] == list2[j]
      ctr += 1
    end
  end
end
if (ctr%2 == 0)
  n, m = n-ctr/2, m-ctr/2
else
  n,m = n-ctr/2, m-ctr/2 - 1
end
puts n>m ? "YES": "NO"


After the contest in comparing numbers, Shapur's teacher found out that he is a real genius and that no one could possibly do the calculations faster than him even using a super computer!Some days before the contest, the teacher took a very simple-looking exam and all his n students took part in the exam. The teacher gave them 3 strings and asked them to concatenate them. Concatenating strings means to put them in some arbitrary order one after the other. For example from concatenating Alireza and Amir we can get to AlirezaAmir or AmirAlireza depending on the order of concatenation.Unfortunately enough, the teacher forgot to ask students to concatenate their strings in a pre-defined order so each student did it the way he/she liked.Now the teacher knows that Shapur is such a fast-calculating genius boy and asks him to correct the students' papers.Shapur is not good at doing such a time-taking task. He rather likes to finish up with it as soon as possible and take his time to solve 3-SAT in polynomial time. Moreover, the teacher has given some advice that Shapur has to follow. Here's what the teacher said:   As I expect you know, the strings I gave to my students (including you) contained only lowercase and uppercase Persian Mikhi-Script letters. These letters are too much like Latin letters, so to make your task much harder I converted all the initial strings and all of the students' answers to Latin.  As latin alphabet has much less characters than Mikhi-Script, I added three odd-looking characters to the answers, these include "-", ";" and "_". These characters are my own invention of course! And I call them Signs.  The length of all initial strings was less than or equal to 100 and the lengths of my students' answers are less than or equal to 600  My son, not all students are genius as you are. It is quite possible that they make minor mistakes changing case of some characters. For example they may write ALiReZaAmIR instead of AlirezaAmir. Don't be picky and ignore these mistakes.  Those signs which I previously talked to you about are not important. You can ignore them, since many students are in the mood for adding extra signs or forgetting about a sign. So something like Iran;;-- is the same as --;IRAN  You should indicate for any of my students if his answer was right or wrong. Do this by writing "WA" for Wrong answer or "ACC" for a correct answer.  I should remind you that none of the strings (initial strings or answers) are empty.  Finally, do these as soon as possible. You have less than 2 hours to complete this.

The first three lines contain a string each. These are the initial strings. They consists only of lowercase and uppercase Latin letters and signs ("-", ";" and "_"). All the initial strings have length from 1 to 100, inclusively. In the fourth line there is a single integer n (0 ≤ n ≤ 1000), the number of students. Next n lines contain a student's answer each. It is guaranteed that the answer meets what the teacher said. Each answer iconsists only of lowercase and uppercase Latin letters and signs ("-", ";" and "_"). Length is from 1 to 600, inclusively.

For each student write in a different line. Print "WA" if his answer is wrong or "ACC" if his answer is OK.

Iran_
Persian;
W_o;n;d;e;r;f;u;l;
7
WonderfulPersianIran
wonderful_PersIAN_IRAN;;_
WONDERFUL___IRAN__PERSIAN__;;
Ira__Persiann__Wonderful
Wonder;;fulPersian___;I;r;a;n;
__________IranPersianWonderful__________
PersianIran_is_Wonderful

Shapur;;
is___
a_genius
3
Shapur__a_is___geniUs
is___shapur___a__Genius;
Shapur;;is;;a;;geni;;us;;

def gao(s)
	_ = s.downcase.gsub(/[^a-z]/, '')
end

a = [gets, gets, gets].permutation.map{|_| gao(_ * '')}
gets.to_i.times do
	puts a.member?(gao(gets)) ? :ACC : :WA
end

input=[gets.split[0],gets.split[0],gets.split[0]]
for i in 0..2
	input[i]=input[i].gsub(/[:;,_-]/,"").upcase
end
n=gets.to_i
n.times{
	data=gets.split[0]
	data=data.gsub(/[:;,_-]/,"").upcase
	ans=0
	input.permutation.to_a.each{|a|
		if data==a[0]+a[1]+a[2] then
			puts "ACC"
			ans=1
			break
		end
	}
	if ans==0 then
		puts "WA"
	end
}

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

Infinity = 1/0.0

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

a=gets.chomp.gsub(/;|-|_/,"").upcase
b=gets.chomp.gsub(/;|-|_/,"").upcase
c=gets.chomp.gsub(/;|-|_/,"").upcase

d=[a+b+c,a+c+b,b+a+c,b+c+a,c+a+b,c+b+a]

n=geti
n.times{
    s=gets.chomp.gsub(/;|-|_/,"").upcase
    puts d.include?(s) ? "ACC" : "WA"
}

words = (0...3).map { gets.strip.tr('-;_', '').downcase }
gets
$<.map do |s|
  s = s.strip.tr('-;_', '').downcase
  puts ["WA", "ACC"][words.permutation.map { |ws| ws.join } .include?(s) ? 1 : 0]
end

arr = []
3.times do
	arr << gets.chomp.tr("-;_","").downcase
end
list = arr.permutation(3).map{|a| a.inject("",&:concat)}
# puts "#{list}"
n = gets.to_i
n.times do
	s = gets.chomp.tr("-;_","").downcase
	puts list.include?(s) ? "ACC" : "WA"
end

# http://codeforces.com/problemset/problem/61/B

init_str = []
3.times do
  init_str << gets.chomp.downcase.gsub(/[;_-]/, "")
end

students_ans = []
n = gets.chomp.to_i
n.times do
  students_ans << gets.chomp.downcase.gsub(/[;_-]/, "")
end

a, b, c = init_str
acc_ans = [a + b + c, a + c + b, b + a + c, b + c + a, c + a + b, c + b + a]

for i in 0..(n - 1)
  puts acc_ans.include?(students_ans[i]) ? "ACC" : "WA"
end

s = []
3.times { |i| s[i] = gets.downcase.delete "-;_\n" }
a = s.permutation.to_a.map { |a,b,c| a + b + c }
gets.to_i.times do
    x = gets.downcase.delete "-;_\n"
    puts (a.include?(x) ? "ACC" : "WA")
end


On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length $$$k$$$ ($$$k \ge 3$$$). Nastya was very confused by this present, so she decided to break the door, throwing it on the mountains.Mountains are described by a sequence of heights $$$a_1, a_2, \dots, a_n$$$ in order from left to right ($$$k \le n$$$). It is guaranteed that neighboring heights are not equal to each other (that is, $$$a_i \ne a_{i+1}$$$ for all $$$i$$$ from $$$1$$$ to $$$n-1$$$).Peaks of mountains on the segment $$$[l,r]$$$ (from $$$l$$$ to $$$r$$$) are called indexes $$$i$$$ such that $$$l < i < r$$$, $$$a_{i - 1} < a_i$$$ and $$$a_i > a_{i + 1}$$$. It is worth noting that the boundary indexes $$$l$$$ and $$$r$$$ for the segment are not peaks. For example, if $$$n=8$$$ and $$$a=[3,1,4,1,5,9,2,6]$$$, then the segment $$$[1,8]$$$ has only two peaks (with indexes $$$3$$$ and $$$6$$$), and there are no peaks on the segment $$$[3, 6]$$$.To break the door, Nastya throws it to a segment $$$[l,l+k-1]$$$ of consecutive mountains of length $$$k$$$ ($$$1 \le l \le n-k+1$$$). When the door touches the peaks of the mountains, it breaks into two parts, after that these parts will continue to fall in different halves and also break into pieces when touching the peaks of the mountains, and so on. Formally, the number of parts that the door will break into will be equal to $$$p+1$$$, where $$$p$$$ is the number of peaks on the segment $$$[l,l+k-1]$$$.Nastya wants to break it into as many pieces as possible. Help her choose such a segment of mountains $$$[l, l+k-1]$$$ that the number of peaks on it is maximum. If there are several optimal segments, Nastya wants to find one for which the value $$$l$$$ is minimal.Formally, you need to choose a segment of mountains $$$[l, l+k-1]$$$ that has the maximum number of peaks. Among all such segments, you need to find the segment that has the minimum possible value $$$l$$$.

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$)  — the number of test cases. Then the descriptions of the test cases follow. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$3 \leq k \leq n \leq 2 \cdot 10^5$$$)  — the number of mountains and the length of the door. The second line of the input data set contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \leq a_i \leq 10 ^ 9$$$, $$$a_i \neq a_{i + 1}$$$)  — the heights of mountains. It is guaranteed that the sum of $$$n$$$ over all the test cases will not exceed $$$2 \cdot 10^5$$$.

For each test case, output two integers $$$t$$$ and $$$l$$$  — the maximum number of parts that the door can split into, and the left border of the segment of length $$$k$$$ that the door should be reset to.

NoteIn the first example, you need to select a segment of mountains from $$$2$$$ to $$$7$$$. In this segment, the indexes $$$3$$$ and $$$6$$$ are peaks, so the answer is $$$3$$$ (only $$$2$$$ peaks, so the door will break into $$$3$$$ parts). It is not difficult to notice that the mountain segments $$$[1, 6]$$$ and $$$[3, 8]$$$ are not suitable since they only have a $$$1$$$ peak (for the first segment, the $$$6$$$ index is not a peak, and for the second segment, the $$$3$$$ index is not a peak).In the second example, you need to select a segment of mountains from $$$2$$$ to $$$4$$$. In this segment, the index $$$3$$$ is a peak, so the answer is $$$2$$$ (only $$$1$$$ peak, so the door will break into $$$2$$$ parts).In the third example, you need to select a segment of mountains from $$$1$$$ to $$$4$$$. In this segment, the index $$$3$$$ is a peak, so the answer is $$$2$$$ (only $$$1$$$ peak, so the door will break into $$$2$$$ parts). You can see that on the segments $$$[2, 5]$$$, $$$[4, 7]$$$ and $$$[5, 8]$$$ the number of peaks is also $$$1$$$, but these segments have a left border greater than the segment $$$[1, 4]$$$, so they are not the correct answer.

def solve arr, k
  peak = []
  peak[0] = 0
  (1...arr.length-1).each do |i|
    if arr[i] > arr[i - 1] && arr[i] > arr[i + 1]
      peak[i] = peak[i - 1] + 1
    else
      peak[i] = peak[i - 1]
    end
  end
  peak[arr.length - 1] = peak[arr.length - 2]
  res = [-1, 1000000]
  (0..arr.length - k).each do |i|
    if peak[i + k - 2] - peak[i] > res[0]
      res[0] = peak[i + k - 2] - peak[i]
      res[1] = i
    end
  end
  [res[0] + 1, res[1] + 1]
end

t = STDIN.gets.chomp.to_i

t.times do |i|
  n, k = STDIN.gets.chomp.split.map {|i| i.to_i}
  arr = STDIN.gets.chomp.split.map {|i| i.to_i}
  res = solve arr, k
  puts res.join(" ")
end

# coding: utf-8

t = gets.to_i
t.times {
    n, k = gets.split.map(&:to_i)
    peaks = []
    l = 0
    max_peaks = 0
    a = gets.split.map(&:to_i)
    for i in 2...n
        if a[i-2] < a[i-1] && a[i-1] > a[i]
            #p "add peak #{i-1}"
            peaks << i-1
        end

        if i - (k-1) >= 0
            while !peaks.empty? && peaks.first <= i-(k-1)
                #p "===> #{i}"
                #p peaks
                peaks.shift
            end

            if max_peaks < (peaks.count)
                #p "updating #{i}"
                max_peaks = peaks.count
                l = i-(k-1) #zero-based
            end
        end
    end
    #p peaks
    # [l, l+k -1] <=> (l-1, l+k)
    puts "#{max_peaks + 1} #{l + 1}" #l+1 -> one-based
}

t = gets.to_i
t.times do
  n, k = gets.split.map(&:to_i)
  a = gets.split.map(&:to_i)
  hist = Array.new(n, 0)
  count = 0
  for i in 1..(n - 2) do
    count += 1 if a[i - 1] < a[i] && a[i] > a[i + 1]
    hist[i] = count
  end
  hist[n - 1] = hist[n - 2]
  #  p hist
  s_max = 0
  for l in 0..(n - k) do
    s = hist[l + k - 2] - hist[l] + 1
    if s > s_max
      s_max = s
      l_ans = l
    end
  end
  puts "#{s_max} #{l_ans + 1}"
end

t = gets.chomp.to_i
t.times do
	n, k = gets.chomp.split(" ").map(&:to_i)
	arr = gets.chomp.split(" ").map(&:to_i)
	ngo = Array.new(n, 0)
	(1..arr.length-2).each do |a|
		if arr[a-1] < arr[a] && arr[a] > arr[a+1] then
			# ngo[a-1] = 1
			# ngo[a] = 2
			# ngo[a+1] = 1
			ngo[a]=1
		end
	end
	#puts "ppp"
	#p ngo
	sum = ngo.slice(1,k - 2).inject(:+)
	max = sum
	ind = 1
	(2..n - k + 2).each do |i|
		#puts "i:#{i}"
		sum = sum - ngo[i - 1] + ngo[i + k - 2 - 1]
		if max < sum then
			#p ngo.slice(i, k - 2)
			#p arr.slice(i, i + k-1)
			max = sum
			ind = i
		end
	end
	puts "#{max + 1} #{ind}"
end


Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases.But Zulu warns him that a group of k > 1 Pokemon with strengths {s1, s2, s3, ..., sk} tend to fight among each other if gcd(s1, s2, s3, ..., sk) = 1 (see notes for gcd definition).Bash, being smart, does not want his Pokemon to fight among each other. However, he also wants to maximize the number of Pokemon he takes from the lab. Can you help Bash find out the maximum number of Pokemon he can take? Note: A Pokemon cannot fight with itself.

The input consists of two lines. The first line contains an integer n (1 ≤ n ≤ 105), the number of Pokemon in the lab. The next line contains n space separated integers, where the i-th of them denotes si (1 ≤ si ≤ 105), the strength of the i-th Pokemon.

Print single integer — the maximum number of Pokemons Bash can take.

Notegcd (greatest common divisor) of positive integers set {a1, a2, ..., an} is the maximum positive integer that divides all the integers {a1, a2, ..., an}.In the first sample, we can take Pokemons with strengths {2, 4} since gcd(2, 4) = 2.In the second sample, we can take Pokemons with strengths {2, 4, 6}, and there is no larger group with gcd ≠ 1.

N = 1e5

n = gets.to_i
a = gets.split.map(&:to_i)
c = Array.new(N + 1, 0)
a.each{|x| c[x] += 1}
amx = a.max
ans = 1
(2..amx).each do |i|
  cnt = 0
  (i..amx).step(i){|j| cnt += c[j]}
  ans = [ans, cnt].max
end
p ans

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

count = [0] * (data.max + 1)
data.each { |i| count[i] += 1 }

puts ([1] + (2...count.length).map { |i|
    (i...count.length).step(i).map { |j|
        count[j]
    }.reduce(0, :+)
}).max

#!/usr/bin/ruby
#require 'prime'
h=Hash.new 0
gets
gets.split.each{|_|
	if false
		_.to_i.prime_division.each{|n,p|h[n]+=1}
	else
		n=_.to_i
		i=2
		while i*i<=n
			if n%i==0
				h[i]+=1
				n/=i while n%i==0
			end
			i+=1
		end
		h[n]+=1 if n>1
	end
}
p h.values.max||1

N = 10 ** 5

n = gets.to_i
a = gets.split.map(&:to_i)
c = Array.new(N + 1, 0)
a.each{|x| c[x] += 1}
ans = 1
2.upto(N) do |i|
  cnt = 0
  i.step(N, i){|j| cnt += c[j]}
  ans = [ans, cnt].max
end
p ans

N = 10 ** 5

n = gets.to_i
a = gets.split.map(&:to_i)
c = Array.new(N + 1, 0)
a.each{|x| c[x] += 1}
ans = 1
(2..N).each do |i|
  cnt = 0
  i.step(N, i){|j| cnt += c[j]}
  ans = [ans, cnt].max
end
p ans

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

count = [0] * (data.max + 1)
data.each { |i| count[i] += 1 }

puts (2...count.length).map { |i|
    (i...count.length).step(i).map { |j|
        count[j]
    }.reduce(0, :+)
}.max

N = 1e5

n = gets.to_i
a = gets.split.map(&:to_i)
c = Array.new(N + 1, 0)
a.each{|x| c[x] += 1}
amx = a.max
ans = 0
(2..amx).each do |i|
  cnt = 0
  (i..amx).step(i){|j| cnt += c[j]}
  ans = [ans, cnt].max
end
p n == 1 ? 1 : ans