Constanze is the smartest girl in her village but she has bad eyesight.One day, she was able to invent an incredible machine! When you pronounce letters, the machine will inscribe them onto a piece of paper. For example, if you pronounce 'c', 'o', 'd', and 'e' in that order, then the machine will inscribe "code" onto the paper. Thanks to this machine, she can finally write messages without using her glasses.However, her dumb friend Akko decided to play a prank on her. Akko tinkered with the machine so that if you pronounce 'w', it will inscribe "uu" instead of "w", and if you pronounce 'm', it will inscribe "nn" instead of "m"! Since Constanze had bad eyesight, she was not able to realize what Akko did.The rest of the letters behave the same as before: if you pronounce any letter besides 'w' and 'm', the machine will just inscribe it onto a piece of paper.The next day, I received a letter in my mailbox. I can't understand it so I think it's either just some gibberish from Akko, or Constanze made it using her machine. But since I know what Akko did, I can just list down all possible strings that Constanze's machine would have turned into the message I got and see if anything makes sense.But I need to know how much paper I will need, and that's why I'm asking you for help. Tell me the number of strings that Constanze's machine would've turned into the message I got.But since this number can be quite large, tell me instead its remainder when divided by $$$10^9+7$$$.If there are no strings that Constanze's machine would've turned into the message I got, then print $$$0$$$.

Input consists of a single line containing a string $$$s$$$ ($$$1 \leq |s| \leq 10^5$$$) — the received message. $$$s$$$ contains only lowercase Latin letters.

Print a single integer — the number of strings that Constanze's machine would've turned into the message $$$s$$$, modulo $$$10^9+7$$$.

NoteFor the first example, the candidate strings are the following: "ouuokarinn", "ouuokarim", "owokarim", and "owokarinn".For the second example, there is only one: "banana".For the third example, the candidate strings are the following: "nm", "mn" and "nnn".For the last example, there are no candidate strings that the machine can turn into "amanda", since the machine won't inscribe 'm'.


Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information.Zhorik knows that each of the messages is an archive containing one or more files. Zhorik knows how each of these archives was transferred through the network: if an archive consists of k files of sizes l1, l2, ..., lk bytes, then the i-th file is split to one or more blocks bi, 1, bi, 2, ..., bi, mi (here the total length of the blocks bi, 1 + bi, 2 + ... + bi, mi is equal to the length of the file li), and after that all blocks are transferred through the network, maintaining the order of files in the archive.Zhorik thinks that the two messages contain the same archive, because their total lengths are equal. However, each file can be split in blocks in different ways in the two messages.You are given the lengths of blocks in each of the two messages. Help Zhorik to determine what is the maximum number of files could be in the archive, if the Zhorik's assumption is correct.

The first line contains two integers n, m (1 ≤ n, m ≤ 105) — the number of blocks in the first and in the second messages. The second line contains n integers x1, x2, ..., xn (1 ≤ xi ≤ 106) — the length of the blocks that form the first message. The third line contains m integers y1, y2, ..., ym (1 ≤ yi ≤ 106) — the length of the blocks that form the second message. It is guaranteed that x1 + ... + xn = y1 + ... + ym. Also, it is guaranteed that x1 + ... + xn ≤ 106.

Print the maximum number of files the intercepted array could consist of.

NoteIn the first example the maximum number of files in the archive is 3. For example, it is possible that in the archive are three files of sizes 2 + 5 = 7, 15 = 3 + 1 + 11 = 8 + 2 + 4 + 1 and 4 + 4 = 8.In the second example it is possible that the archive contains two files of sizes 1 and 110 = 10 + 100 = 100 + 10. Note that the order of files is kept while transferring archives through the network, so we can't say that there are three files of sizes 1, 10 and 100.In the third example the only possibility is that the archive contains a single file of size 4.

la,lb=gets.split.collect{|t|t.to_i}
sbl,res=0,0
a=gets.split.collect{|t|t.to_i}
b=gets.split.collect{|t|t.to_i}
while a.size>0
  if sbl==0
    res+=1
    sbl+=a.shift
  end
  if sbl>0
    sbl-=b.shift
  else
    sbl+=a.shift
  end
end
puts res

n, m = gets.split.map(&:to_i)
a = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.map(&:to_i)
ans, sa, sb, la, lb = 0, 0, 0, 0, 0
while la < n || lb < m
  if sa == 0
    sa += a[la]
    la += 1
  end
  if sb == 0
    sb += b[lb]
    lb += 1
  end
  if sa == sb
    ans += 1
    sa = 0
    sb = 0
  else
    if sa < sb
      sa += a[la]
      la += 1
    else
      sb += b[lb]
      lb += 1
    end
  end
end
ans += 1 if sa != 0
puts ans

# http://codeforces.com/problemset/problem/950/B
n, m = gets.split.map(&:to_i)
m1 = gets.split.map(&:to_i)
m2 = gets.split.map(&:to_i)

c = 0
if m == 1 || n == 1
  puts 1
else
  file1_size = 0
  file2_size = 0
  p1 = 0
  p2 = 0

  while p1 < n && p2 < m
    if file1_size + m1[p1] == file2_size + m2[p2]
      file1_size = 0
      file2_size = 0
      p1 += 1
      p2 += 1
      c += 1
      next
    end

    if file1_size + m1[p1] > file2_size + m2[p2]
      file2_size += m2[p2]
      p2 += 1
    else
      file1_size += m1[p1]
      p1 += 1
    end
  end
  puts c
end

# http://codeforces.com/problemset/problem/950/B
n, m = gets.split.map(&:to_i)
m1 = gets.split.map(&:to_i)
m2 = gets.split.map(&:to_i)

c = 0
if m == 1 || n == 1
  puts 1
else
  file1_size = 0
  file2_size = 0
  p1 = 0
  p2 = 0

  while p1 < n && p2 < m
    if file1_size + m1[p1] == file2_size + m2[p2]
      file1_size = 0
      file2_size = 0
      p1 += 1
      p2 += 1
      c += 1
      next
    end

    if file1_size + m1[p1] > file2_size + m2[p2]
      file2_size += m2[p2]
      p2 += 1
    else
      file1_size += m1[p1]
      p1 += 1
    end
  end
end

puts c


David was given a red checkered rectangle of size $$$n \times m$$$. But he doesn't like it. So David cuts the original or any other rectangle piece obtained during the cutting into two new pieces along the grid lines. He can do this operation as many times as he wants.As a result, he will get a set of rectangles. Rectangles $$$1 \times 1$$$ are forbidden.David also knows how to paint the cells blue. He wants each rectangle from the resulting set of pieces to be colored such that any pair of adjacent cells by side (from the same piece) have different colors.What is the minimum number of cells David will have to paint?

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$n$$$, $$$m$$$ ($$$1 \leq n, m \leq 3 \cdot 10^4$$$, $$$n \cdot m \geq 2$$$).

For each test case print a single integer — the minimum number of cells David will have to paint blue.

NoteThe following pictures show how the initial rectangle can be split and cells colored blue.In the first test case:  In the second test case:  In the third test case:  In the fourth test case:

za=gets.chomp.to_i
za.times do
	n,m=gets.split.map(&:to_i)
	p=n*m;
        if(p%3==0)
            puts p/3
        else
            puts (p/3)+1
        end
end


The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls.

The first line contains an integer n (1 ≤ n ≤ 100) — the number of boys. The second line contains sequence a1, a2, ..., an (1 ≤ ai ≤ 100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1 ≤ m ≤ 100) — the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ≤ bj ≤ 100), where bj is the j-th girl's dancing skill.

Print a single number — the required maximum possible number of pairs.

# cook your code here
b=gets.to_i
skb = gets.split(/ /).map! { |e| e=e.to_i }
g=gets.to_i
skg = gets.split(/ /).map! { |e| e=e.to_i }
skg=skg.sort
skb=skb.sort
i=0
j=0
pe=0

while j < g and i < b
    if (skb[i]-skg[j]).abs<=1
        pe=pe+1
        i=i+1
        j=j+1
    elsif skb[i]>skg[j]
        j=j+1
    elsif skb[i]<skg[j]
        i=i+1
    end
end
puts pe

gets
a = gets.split.map { |x| x.to_i }.sort
gets
b = gets.split.map { |x| x.to_i }.sort.join(" ")

a.each do |x|
  b.sub!(/\b(#{x-1}|#{x}|#{x+1})\b/, "200")
end
puts b.scan(/200/).length

n = gets.to_i
a = gets.split.map { |x| x.to_i }
n = gets.to_i
b = gets.split.map { |x| x.to_i }

a.sort!
b.sort!

x = nil
y = nil
count = 0

while (!a.empty? or !x.nil?) and (!b.empty? || !y.nil?)
  x = a.shift if x.nil?
  y = b.shift if y.nil?
  if x < y - 1
    x = nil
  elsif y < x - 1
    y = nil
  else
    x = nil
    y = nil
    count = count + 1
  end
end

puts count

n = STDIN.readline.to_i
boys = STDIN.readline.split.map {|s| s.to_i }
m = STDIN.readline.to_i
girls = STDIN.readline.split.map {|s| s.to_i }

def search(n, m, kosher, u, seen, match)
	n.times do |v|
		if kosher[u][v] and not seen[v]
			seen[v] = true
			if match[v] < 0 or search(n, m, kosher, match[v], seen, match)
				match[v] = u
				return true
			end
		end
	end
	false
end

kosher = m.times.map {|j| n.times.map {|i| (boys[i]-girls[j]).abs <= 1 } }
match = n.times.map { -1 }
count = 0
m.times do |u|
	seen = n.times.map { false }
	count += 1 if search(n, m, kosher, u, seen, match)
end
puts count

n = STDIN.readline.to_i
boys = STDIN.readline.split.map {|s| s.to_i }.sort
m = STDIN.readline.to_i
girls = STDIN.readline.split.map {|s| s.to_i }.sort

b = 0
count = 0
girls.each do |girl|
	b += 1 while b < n and girl-boys[b] > 1
	if b < n and (girl-boys[b]).abs <= 1
		count += 1
		b += 1
	end
end

puts count

n = gets.to_i
a = gets.split.map { |x| x.to_i }.sort
m = gets.to_i
b = gets.split.map { |x| x.to_i }.sort

i, j = 0, 0
cnt = 0
while i < n and j < m
  if (a[i] - b[j]).abs <= 1
    i += 1
    j += 1
    cnt += 1
  elsif a[i] + 1 < b[j]
    i += 1
  else
    j += 1
  end
end

puts cnt

gets
x=gets.split.map{|e| e.to_i}.sort
gets
y=gets.split.map{|e| e.to_i}.sort

ans=0
while (!x.empty?) && (!y.empty?)
	if (x[0]-y[0]).abs<=1 then
		ans+=1
		x.shift
		y.shift
	else
		if x[0]<y[0] then
			x.shift
		else
			y.shift
		end
	end
end

puts ans

#$stdin = File.open "input.txt"

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

m = gets.to_i
b = gets.split.map(&:to_i).sort

i, j, pairs = 0, 0, 0

while (i < n) && (j < m)
	if (a[i] - b[j]).abs <= 1
		pairs += 1
		i += 1
		j += 1
	else
		if a[i] < b[j]; i += 1 else j += 1 end
	end
end

p pairs

n = Integer(gets)
nums = gets.chomp.split
boy = Array.new
for i in 0...n
    boy[i] = Integer(nums[i])
end
m = Integer(gets)
nums2 = gets.chomp.split
girl = Array.new
for i in 0...m
    girl[i] = Integer(nums2[i])
end

boy.sort!
girl.sort!
def pairs(x,y)
    count = 0
    for i in 0...x.length
        for j in 0...y.length
            if (x[i] - y[j]).abs <= 1
                count += 1
                y.delete_at(j)
                break
            end
        end
    end
    return count
end

if  n >= m
    puts pairs(girl, boy)
else
    puts pairs(boy, girl)
end

boys = gets.chomp.to_i
boys_skills = gets.chomp
boys_skills = boys_skills.split
girls = gets.chomp.to_i
girls_skills = gets.chomp
girls_skills = girls_skills.split

count = 0
for i in (0..girls-1)
	for x in (i..girls-1)
		if girls_skills[i].to_i > girls_skills[x].to_i && i != x
			temp = girls_skills[i].to_i
			girls_skills[i] = girls_skills[x].to_i
			girls_skills[x] = temp
		end
	end
end
for i in (0..boys-1)
	for x in (i..boys-1)
		if boys_skills[i].to_i > boys_skills[x].to_i && i != x
			temp = boys_skills[i].to_i
			boys_skills[i] = boys_skills[x].to_i
			boys_skills[x] = temp
		end
	end
end
if boys <= girls
	for i in (0..boys-1)
		for x in (0..girls_skills.size-1)
			if boys_skills[i].to_i == girls_skills[x].to_i || boys_skills[i].to_i - 1 == girls_skills[x].to_i || boys_skills[i].to_i + 1 == girls_skills[x].to_i
				girls_skills.delete_at(x)
				count += 1
				break
			end
		end
	end
else
	for i in (0..girls-1)
		for x in (0..boys_skills.size-1)
			if girls_skills[i].to_i == boys_skills[x].to_i || girls_skills[i].to_i - 1 == boys_skills[x].to_i || girls_skills[i].to_i + 1 == boys_skills[x].to_i
				boys_skills.delete_at(x)
				count += 1
				break
			end
		end
	end
end
print count

#!/usr/bin/env ruby

n = $stdin.gets.to_i
boys = $stdin.gets.split.map { |b| b.to_i }
m = $stdin.gets.to_i
girls = $stdin.gets.split.map { |b| b.to_i }

raise "weird" unless boys.size == n
raise "weird" unless girls.size == m

boys.sort!
girls.sort!

i = 0
j = 0
res = 0
while i < n and j < m
  if (boys[i] - girls[j]).abs <= 1
    res += 1
    i += 1
    j += 1
  elsif boys[i] < girls[j]
    i += 1
  elsif boys[i] > girls[j]
    j += 1
  end
end

puts res

def solution(boys, boys_skill, girls, girls_skill)
  @boys = boys
  @girls = girls
  @boys_skill = boys_skill.sort!
  @girls_skill = girls_skill.sort!

  @couples = 0
  solve(0, 0)
  @couples
end

def solve(a_i, b_i)
  return nil if a_i == @boys || b_i == @girls
  if (@boys_skill[a_i] - @girls_skill[b_i]).abs <= 1
    @couples += 1
    solve(a_i + 1, b_i + 1)
  elsif @boys_skill[a_i] > @girls_skill[b_i]
    solve(a_i, b_i + 1)
  else
    solve(a_i + 1, b_i)
  end
end

boys = gets.to_i
boys_skill = gets.split.map(&:to_i)
girls = gets.to_i
girls_skill = gets.split.map(&:to_i)
puts solution(boys, boys_skill, girls, girls_skill)

def solution(boys, boys_skill, girls, girls_skill)
  boys_skill.sort!
  girls_skill.sort!
  i, j = 0, 0

  couples = 0
  while i < boys && j < girls do
    if (boys_skill[i] - girls_skill[j]).abs <= 1
      couples += 1
      i += 1
      j += 1
    else
      if boys_skill[i] > girls_skill[j]
        j += 1
      else
        i += 1
      end
    end
  end
  couples
end

boys = gets.to_i
boys_skill = gets.split.map(&:to_i)
girls = gets.to_i
girls_skill = gets.split.map(&:to_i)

puts solution(boys, boys_skill, girls, girls_skill)

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

n = gets.to_i
ns = gets.chomp.split.map(&:to_i).sort
m = gets.to_i
ms = gets.chomp.split.map(&:to_i).sort
ans = 0
i = 0
j = 0
while i < n && j < m
  if ns[i] == ms[j] || ns[i] + 1 == ms[j] || ns[i] - 1 == ms[j]
    i += 1
    j += 1
    ans += 1
  elsif ns[i] > ms[j] + 1
    j += 1
  elsif ns[i] + 1 < ms[j]
    i += 1
  end
end
p ans

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

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

result = 0
while !a.empty? && !b.empty?
  if (a.first - b.first).abs < 2
    result += 1
    a.shift
    b.shift
  else
    a.first < b.first ? a.shift : b.shift
  end
end

puts result

#File.open("4.txt","r") do |file|
	a=Array.new
	b=Array.new
	c=Array.new
	d=Array.new
	n=gets.to_i
	str=gets.to_s
	c=str.split
	i=0
	while i<n
		a[i]=c[i].to_i
		i+=1
	end
	m=gets.to_i
	str=gets.to_s
	d=str.split
	i=0
	while i<m
		b[i]=d[i].to_i
		i+=1
	end
	a.sort!
	b.sort!
	# print a
	# puts
	# print b
	# puts
	i=j=s=0
	while i<n and j<m
		if (a[i]-b[j]).abs<=1
			i+=1
			j+=1
			s+=1
		elsif a[i]>b[j]
			j+=1
		else
			i+=1
		end
	end
	puts s
#end

$dp = Array.new(101)
(0..101).each do |i|
  $dp[i]=Array.new(101,-1)
end
$n= gets.to_i
$a= gets.split(' ').map(&:to_i).sort
$m= gets.to_i
$b= gets.split(' ').map(&:to_i).sort
def calc(i,j)
  ret = 0
  if i == $n
    ret
  elsif j==$m
    ret
  elsif $dp[i][j]!=-1
    $dp[i][j]
  else
    ret=calc(i+1,j)
    ret=[calc(i+1,j+1)+(($a[i]-$b[j]).abs<2?1:0),ret].max
    ret=[calc(i,j+1),ret].max
    $dp[i][j]=ret
    ret
  end
end

puts calc(0,0)

n = gets.to_i

a = gets.split.map { |x| x.to_i }

n = gets.to_i

b = gets.split.map { |x| x.to_i }

a.sort!
b.sort!

x = nil
y = nil
count = 0

while !a.empty? and !b.empty?
	x = a.shift if x.nil?
	y = b.shift if y.nil?
	if x < y - 1
		x = nil
	elsif y < x - 1
		y = nil
	else
		x = nil
		y = nil
		count = count + 1
	end
end

puts count

gets
a = gets.split.map { |x| x.to_i }.sort
gets
b = gets.chomp

a.each do |x|
  b.sub!(/\b(#{x}|#{x+1}|#{x-1})\b/, "200")
end
puts b.scan(/200/).length

gets
a = gets.split.map { |x| x.to_i }.sort
n = gets.to_i
b = gets.split.map { |x| x.to_i }.sort
index = 0
ans = 0

a.each do |x|
  break if (index >= n)

  if ((x - b[index]).abs <= 1)
      index += 1
      ans += 1
  end
end

puts ans

gets
a = gets.split.map { |x| x.to_i }.sort
gets
b = gets.split.map { |x| x.to_i }.sort
ans = 0

a.each do |x|
  b.each do |y|
    if ((x - y).abs <= 1)
      ans += 1
      b.shift
      break
    elsif ( x > y + 1)
      b.shift
    end
  end
end

puts ans

gets
a = gets.split.map { |x| x.to_i }.sort
gets
b = gets.chomp

a.each do |x|
  b.sub!(/\b(#{x-1}|#{x}|#{x+1})\b/, "200")
end
puts b.scan(/200/).length

n = gets.to_i
a = gets.split.map { |x| x.to_i }.sort
m = gets.to_i
b = gets.split.map { |x| x.to_i }.sort

i, j = 0, 0
cnt = 0
while i < n and j < m
  if (a[i] - b[j]).abs <= 1
    i += 1
    j += 1
    cnt += 1
  elsif a[i] + 1 < a[j]
    i += 1
  else
    j += 1
  end
end

puts cnt

#$stdin = File.open "input.txt"

n = gets.to_i
a = gets.split.sort.map &:to_i

m = gets.to_i
b = gets.split.sort.map &:to_i

i, j, pairs = 0, 0, 0

while (i < n) && (j < m)
	if (a[i] - b[j]).abs <= 1
		pairs += 1
		i += 1
		j += 1
	else
		if a[i] < b[j]; i += 1 else j += 1 end
	end
end

p pairs

n = Integer(gets)
nums = gets.chomp.split
boy = Array.new
for i in 0...n
    boy[i] = Integer(nums[i])
end
m = Integer(gets)
nums2 = gets.chomp.split
girl = Array.new
for i in 0...m
    girl[i] = Integer(nums2[i])
end

boy.sort!
girl.sort!
def pairs(x,y)
    count = 0
    for i in 0...x.length
        for j in 0...y.length
            if (x[i] - y[j]).abs <= 1
                print (x[i] - y[j]).abs
                count += 1
                y.delete_at(j)
                break
            end
        end
    end
    return count
end

if  n >= m
    puts pairs(girl, boy)
else
    puts pairs(boy, girl)
end

boys = gets.chomp.to_i
boys_skills = gets.chomp
boys_skills = boys_skills.split
girls = gets.chomp.to_i
girls_skills = gets.chomp
girls_skills = girls_skills.split

count = 0
for i in (0..girls-1)
	for x in (i..girls-1)
		if girls_skills[i].to_i > girls_skills[x].to_i && i += x
			temp = girls_skills[i].to_i
			girls_skills[i] = girls_skills[x].to_i
			girls_skills[x] = temp
		end
	end
end
for i in (0..boys-1)
	for x in (i..boys-1)
		if boys_skills[i].to_i > boys_skills[x].to_i && i != x
			temp = boys_skills[i].to_i
			boys_skills[i] = boys_skills[x].to_i
			boys_skills[x] = temp
		end
	end
end
if boys <= girls
	for i in (0..boys-1)
		for x in (0..girls_skills.size-1)
			if boys_skills[i].to_i == girls_skills[x].to_i || boys_skills[i].to_i - 1 == girls_skills[x].to_i || boys_skills[i].to_i + 1 == girls_skills[x].to_i
				girls_skills.delete_at(x)
				count += 1
				break
			end
		end
	end
else
	for i in (0..girls-1)
		for x in (0..boys_skills.size-1)
			if girls_skills[i].to_i == boys_skills[x].to_i || girls_skills[i].to_i - 1 == boys_skills[x].to_i || girls_skills[i].to_i + 1 == boys_skills[x].to_i
				boys_skills.delete_at(x)
				count += 1
				break
			end
		end
	end
end
print count

boys = gets.chomp.to_i
boys_skills = gets.chomp
boys_skills = boys_skills.split
girls = gets.chomp.to_i
girls_skills = gets.chomp
girls_skills = girls_skills.split

count = 0
if boys <= girls
	for i in (0..boys-1)
		for x in (0..girls_skills.size-1)
			if boys_skills[i].to_i == girls_skills[x].to_i || boys_skills[i].to_i - 1 == girls_skills[x].to_i || boys_skills[i].to_i + 1 == girls_skills[x].to_i
				girls_skills.delete_at(x)
				count += 1
				break
			end
		end
	end
else
	for i in (0..girls-1)
		for x in (0..boys_skills.size-1)
			if girls_skills[i].to_i == boys_skills[x].to_i || girls_skills[i].to_i - 1 == boys_skills[x].to_i || girls_skills[i].to_i + 1 == boys_skills[x].to_i
				boys_skills.delete_at(x)
				count += 1
				break
			end
		end
	end
end
print count
# for i in (0..girls-1)
# 	for x in (1..girls-1)
# 		if girls_skills[i].to_i > girls_skills[x]
# 			temp = girls_skills[i].to_i
# 			girls_skills[i] = girls_skills[x].to_i
# 			girls_skills[x] = temp
# 		end
# 	end
# end

boys = gets.chomp.to_i
boys_skills = gets.chomp
boys_skills = boys_skills.split
girls = gets.chomp.to_i
girls_skills = gets.chomp
girls_skills = girls_skills.split

count = 0
for i in (0..girls-2)
	for x in (1..girls-1)
		if girls_skills[i].to_i > girls_skills[x].to_i
			temp = girls_skills[i].to_i
			girls_skills[i] = girls_skills[x].to_i
			girls_skills[x] = temp
		end
	end
end
for i in (0..boys-2)
	for x in (1..boys-1)
		if boys_skills[i].to_i > boys_skills[x].to_i
			temp = boys_skills[i].to_i
			boys_skills[i] = boys_skills[x].to_i
			boys_skills[x] = temp
		end
	end
end
if boys <= girls
	for i in (0..boys-1)
		for x in (0..girls_skills.size-1)
			if boys_skills[i].to_i == girls_skills[x].to_i || boys_skills[i].to_i - 1 == girls_skills[x].to_i || boys_skills[i].to_i + 1 == girls_skills[x].to_i
				girls_skills.delete_at(x)
				count += 1
				break
			end
		end
	end
else
	for i in (0..girls-1)
		for x in (0..boys_skills.size-1)
			if girls_skills[i].to_i == boys_skills[x].to_i || girls_skills[i].to_i - 1 == boys_skills[x].to_i || girls_skills[i].to_i + 1 == boys_skills[x].to_i
				boys_skills.delete_at(x)
				count += 1
				break
			end
		end
	end
end
print count

boys = gets.chomp.to_i
boys_skills = gets.chomp
boys_skills = boys_skills.split
girls = gets.chomp.to_i
girls_skills = gets.chomp
girls_skills = girls_skills.split

count = 0
for i in (0..girls-1)
	for x in (1..girls-1)
		if girls_skills[i].to_i > girls_skills[x].to_i
			temp = girls_skills[i].to_i
			girls_skills[i] = girls_skills[x].to_i
			girls_skills[x] = temp
		end
	end
end
for i in (0..boys-1)
	for x in (1..boys-1)
		if boys_skills[i].to_i > boys_skills[x].to_i
			temp = boys_skills[i].to_i
			boys_skills[i] = boys_skills[x].to_i
			boys_skills[x] = temp
		end
	end
end
if boys <= girls
	for i in (0..boys-1)
		for x in (0..girls_skills.size-1)
			if boys_skills[i].to_i == girls_skills[x].to_i || boys_skills[i].to_i - 1 == girls_skills[x].to_i || boys_skills[i].to_i + 1 == girls_skills[x].to_i
				girls_skills.delete_at(x)
				count += 1
				break
			end
		end
	end
else
	for i in (0..girls-1)
		for x in (0..boys_skills.size-1)
			if girls_skills[i].to_i == boys_skills[x].to_i || girls_skills[i].to_i - 1 == boys_skills[x].to_i || girls_skills[i].to_i + 1 == boys_skills[x].to_i
				boys_skills.delete_at(x)
				count += 1
				break
			end
		end
	end
end
print count

boys = gets.chomp.to_i
boys_skills = gets.chomp
boys_skills = boys_skills.split
girls = gets.chomp.to_i
girls_skills = gets.chomp
girls_skills = girls_skills.split

count = 0
for i in (0..girls-1)
	for x in (i..girls-1)
		if girls_skills[i].to_i > girls_skills[x].to_i && i != x
			temp = girls_skills[i].to_i
			girls_skills[i] = girls_skills[x].to_i
			girls_skills[x] = temp
		end
	end
end
for i in (0..boys-1)
	for x in (i..boys-1)
		if boys_skills[i].to_i > boys_skills[x].to_i && i != x
			temp = boys_skills[i].to_i
			boys_skills[i] = boys_skills[x].to_i
			boys_skills[x] = temp
		end
	end
end
print boys_skills
print girls_skills
if boys <= girls
	for i in (0..boys-1)
		for x in (0..girls_skills.size-1)
			if boys_skills[i].to_i == girls_skills[x].to_i || boys_skills[i].to_i - 1 == girls_skills[x].to_i || boys_skills[i].to_i + 1 == girls_skills[x].to_i
				girls_skills.delete_at(x)
				count += 1
				break
			end
		end
	end
else
	for i in (0..girls-1)
		for x in (0..boys_skills.size-1)
			if girls_skills[i].to_i == boys_skills[x].to_i || girls_skills[i].to_i - 1 == boys_skills[x].to_i || girls_skills[i].to_i + 1 == boys_skills[x].to_i
				boys_skills.delete_at(x)
				count += 1
				break
			end
		end
	end
end
print count

$dp = Array.new(101)
(0..101).each do |i|
  $dp[i]=Array.new(101,-1)
end
$n= gets.to_i
$a= gets.split(' ').map(&:to_i).sort
$m= gets.to_i
$b= gets.split(' ').map(&:to_i).sort
def calc(i,j)
  ret = 0
  if i == $n
    ret
  elsif j==$m
    ret
  elsif $dp[i][j]!=-1
    $dp[i][j]
  else
    ret=calc(i+1,j)
    ret=[calc(i+1,j+1)+(($a[i]-$b[j]).abs<2?1:0),ret].max
    ret=[calc(i+1,j),ret].max
    $dp[i][j]=ret
    ret
  end
end

puts calc(0,0)


Little Petya very much likes rectangles and especially squares. Recently he has received 8 points on the plane as a gift from his mother. The points are pairwise distinct. Petya decided to split them into two sets each containing 4 points so that the points from the first set lay at the vertexes of some square and the points from the second set lay at the vertexes of a rectangle. Each point of initial 8 should belong to exactly one set. It is acceptable for a rectangle from the second set was also a square. If there are several partitions, Petya will be satisfied by any of them. Help him find such partition. Note that the rectangle and the square from the partition should have non-zero areas. The sides of the figures do not have to be parallel to the coordinate axes, though it might be the case.

You are given 8 pairs of integers, a pair per line — the coordinates of the points Petya has. The absolute value of all coordinates does not exceed 104. It is guaranteed that no two points coincide.

Print in the first output line "YES" (without the quotes), if the desired partition exists. In the second line output 4 space-separated numbers — point indexes from the input, which lie at the vertexes of the square. The points are numbered starting from 1. The numbers can be printed in any order. In the third line print the indexes of points lying at the vertexes of a rectangle in the similar format. All printed numbers should be pairwise distinct. If the required partition does not exist, the first line should contain the word "NO" (without the quotes), after which no output is needed.

NotePay attention to the third example: the figures do not necessarily have to be parallel to the coordinate axes.

points=[]
8.times{|i|
        points.push(gets.split.map(&:to_i).push(i+1))
}
points.permutation.each(){|i|
        dx=i[1][0]-i[0][0]
        dy=i[1][1]-i[0][1]
        if i[2][0]-i[1][0]!=dy then next end
        if i[3][0]-i[2][0]!=-dx then next end
        if i[0][0]-i[3][0]!=-dy then next end
        if i[2][1]-i[1][1]!=-dx then next end
        if i[3][1]-i[2][1]!=-dy then next end
        if i[0][1]-i[3][1]!=dx then next end
        dx=i[5][0]-i[4][0]
        dy=i[5][1]-i[4][1]
        if i[7][0]-i[6][0]!=-dx then next end
        if i[7][1]-i[6][1]!=-dy then next end
        dx2=i[6][0]-i[5][0]
        dy2=i[6][1]-i[5][1]
        if i[4][0]-i[7][0]!=-dx2 then next end
        if i[4][1]-i[7][1]!=-dy2 then next end
        if dx*dx2+dy*dy2!=0 then next end

        puts "YES"
        4.times{|j|
                print "#{i[j][2]} "
        }
        puts
        4.times{|j|
                print "#{i[j+4][2]} "
        }
        puts
        exit

}
puts "NO"

E=1e-10
def rectangle?(a,b,c,d)
	return [a,b,c,d] if rect?(a,b,c,d)
	return [a,c,b,d] if rect?(a,c,b,d)
	return [b,a,c,d] if rect?(b,a,c,d)
	nil
end

def rect?(a,b,c,d)
	m_ac=mid_pts(a,c)
	return nil if same_pos?(a,m_ac)
	m_bd=mid_pts(b,d)
	return nil if same_pos?(b,m_bd)
	return nil unless same_pos?(m_ac,m_bd)
	return nil unless rect_angle?(a,b,c)
	return nil unless rect_angle?(b,c,d)
	true
end

def mid_pts(a,b)
	[(a[0]+b[0])/2,(a[1]+b[1])/2]
end

def dist(a,b)
	(a[0]-b[0])**2+(a[1]-b[1])**2
end

def rect_angle?(a,b,c)
	p,q=b[0]-a[0],b[1]-a[1]
	r,s=b[0]-c[0],b[1]-c[1]
	same_val?(p*r+q*s,0.0)
end

def same_val?(x,y)
	(x-y).abs<E
end

def same_pos?(a,b)
	same_val?(a[0],b[0])&&same_val?(a[1],b[1])
end

def square?(a,b,c,d)
	r=rectangle?(a,b,c,d)
	return nil unless r
	a,b,c,d=r
	same_val?(dist(a,b),dist(b,c))
end

pts=8.times.map{gets.split.map(&:to_f)}
pts.combination(4).each{|x|
	if square?(*x)
		y=pts-x
		if rectangle?(*y)
			puts "YES"
			puts [x,y].map{|vs|vs.map{|v|pts.index(v)+1}*" "}
			exit
		end
	end
}
puts "NO"

points=[]
8.times{|i|
        points.push(gets.split.map(&:to_i).push(i+1))
}
points.permutation.each(){|i|
        dx=i[1][0]-i[0][0]
        dy=i[1][1]-i[0][1]
        if i[2][0]-i[1][0]!=dy then next end
        if i[3][0]-i[2][0]!=-dx then next end
        if i[0][0]-i[3][0]!=-dy then next end
        if i[2][1]-i[1][1]!=dx then next end
        if i[3][1]-i[2][1]!=-dy then next end
        if i[0][1]-i[3][1]!=-dx then next end
        dx=i[5][0]-i[4][0]
        dy=i[5][1]-i[4][1]
        if i[7][0]-i[6][0]!=-dx then next end
        if i[7][1]-i[6][1]!=-dy then next end
        dx2=i[6][0]-i[5][0]
        dy2=i[6][1]-i[5][1]
        if i[4][0]-i[7][0]!=-dx2 then next end
        if i[4][1]-i[7][1]!=-dy2 then next end
        if dx*dx2+dy*dy2!=0 then next end

        puts "YES"
        4.times{|j|
                print "#{i[j][2]} "
        }
        puts
        4.times{|j|
                print "#{i[j+4][2]} "
        }
        puts
        exit
}
puts "NO"


There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought $$$n$$$ packets with inflatable balloons, where $$$i$$$-th of them has exactly $$$a_i$$$ balloons inside.They want to divide the balloons among themselves. In addition, there are several conditions to hold:  Do not rip the packets (both Grigory and Andrew should get unbroken packets);  Distribute all packets (every packet should be given to someone);  Give both Grigory and Andrew at least one packet;  To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets. Help them to divide the balloons or determine that it's impossible under these conditions.

The first line of input contains a single integer $$$n$$$ ($$$1 \le n \le 10$$$) — the number of packets with balloons. The second line contains $$$n$$$ integers: $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_n$$$ ($$$1 \le a_i \le 1000$$$) — the number of balloons inside the corresponding packet.

If it's impossible to divide the balloons satisfying the conditions above, print $$$-1$$$. Otherwise, print an integer $$$k$$$ — the number of packets to give to Grigory followed by $$$k$$$ distinct integers from $$$1$$$ to $$$n$$$ — the indices of those. The order of packets doesn't matter. If there are multiple ways to divide balloons, output any of them.

NoteIn the first test Grigory gets $$$3$$$ balloons in total while Andrey gets $$$1$$$.In the second test there's only one way to divide the packets which leads to equal numbers of balloons.In the third test one of the boys won't get a packet at all.

N = gets.to_i
as = gets.split.map(&:to_i)
if N == 1 || (N == 2 && as[0] == as[1])
    puts -1
else
    puts 1
    puts N.times.min_by{|i| as[i]} + 1
end

def unequal_split(n, bm, ary)
  zs = 0
  os = 0
  n.times do |s|
    b = (1 << s)
    if b & bm > 0
      os += ary[s]
    else
      zs += ary[s]
    end
  end
  os != zs
end

def print_ans(n, bm)
  zc = 0
  zpos = []
  n.times do |s|
    b = (1 << s)
    if b & bm == 0
      zc += 1
      zpos << (s+1)
    end
  end
  puts zc
  puts zpos.join(" ")
end

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

if n == 1
  puts -1
elsif n == 2
  if ary[0] == ary[1]
    puts -1
  else
    puts "1 1"
  end
else
  ans_found = false
  1.upto((2**n)-2).each do |bm|
    break if ans_found
    if unequal_split(n, bm, ary)
      print_ans(n, bm)
      ans_found = true
    end
  end
  puts -1 unless ans_found
end

n = gets.chomp
n = n.to_i

arr = gets.chomp
arr = arr.split " "
arr.map! {|a| a.to_i}

if (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])
  puts "-1"
else
  puts "1"
  min = arr.min
  puts arr.index(min) + 1
end

n = gets.chomp
n = n.to_i

arr = gets.chomp
arr = arr.split " "
arr.map! {|a| a.to_i}

if (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])
  puts "-1"
else
  puts "1"
  puts arr[0 + (arr.count/2)]
end

n = gets.chomp
n = n.to_i

arr = gets.chomp
arr = arr.split " "
arr.map! {|a| a.to_i}

if (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])
  puts "-1"
else
  puts "1"
  arr.sort!
  puts arr[0 + arr.count/2]
end

n = gets.chomp
n = n.to_i

arr = gets.chomp
arr = arr.split " "
arr.map! {|a| a.to_i}

if (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])
  puts "-1"
else
  puts "1"
  min = arr.min
  puts "1"
end

n = gets.chomp
n = n.to_i

arr = gets.chomp
arr = arr.split " "
arr.map! {|a| a.to_i}

if (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])
  puts "-1"
else
  puts "1"
  puts arr[0]
end

n = gets.chomp
n = n.to_i

arr = gets.chomp
arr = arr.split " "
arr.map! {|a| a.to_i}

if (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])
  puts "-1"
else
  puts "1"

  i = 0
  dup = true
  while i <= arr.count - 2
    dup = false if arr[i] != arr[i + 1]
    i = i + 1
  end

  even = (arr.count % 2 == 0)

  if dup and !even
    puts "-1"
  else
    puts arr[0]
  end
end

n = gets.chomp
n = n.to_i

arr = gets.chomp
arr = arr.split " "
arr.map! {|a| a.to_i}

if (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])
  puts "-1"
else
  puts "1"

  sum = arr.reduce 0, :+
  dup = true
  arr.each_with_index do |a, i|
    break if i >= arr.count - 2

    next if arr[i] == arr[i + 1]

    if arr[i] != arr[i+1]
      dup = false
      break
    end
  end

  if dup
      puts -1
  else
      puts arr[0]
  end
end

n = gets.chomp
n = n.to_i

arr = gets.chomp
arr = arr.split " "
arr.map! {|a| a.to_i}

if (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])
  puts "-1"
else
  puts "1"

  sum = arr.reduce 0, :+

  if arr[0] == sum - arr[0]
      puts arr[1]
  else
      puts arr[0]
  end
end

n = gets.chomp
n = n.to_i

arr = gets.chomp
arr = arr.split " "
arr.map! {|a| a.to_i}

if (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])
  puts "-1"
else
  puts "1"

  i = 0
  dup = true
  while i <= arr.count - 2
    dup = false if arr[i] != arr[i + 1]
    i = i + 1
  end

  even = (arr.count % 2 == 0)

  if dup and even
    puts "-1"
  else
    puts arr[0]
  end
end

n = gets.chomp
n = n.to_i

arr = gets.chomp
arr = arr.split " "
arr.map! {|a| a.to_i}

if (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])
  puts "-1"
else
  puts "1"

  sum = arr.reduce 0, :+

  if arr[0] == sum - arr[0]
      puts -1
  else
      puts arr[0]
  end
end

n = gets.chomp
n = n.to_i

arr = gets.chomp
arr = arr.split " "
arr.map! {|a| a.to_i}

if (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])
  puts "-1"
else
  puts "1"
  puts arr[-1]
end

n = gets.chomp
n = n.to_i

arr = gets.chomp
arr = arr.split " "
arr.map! {|a| a.to_i}

if (arr.count <= 1) or (arr.count == 2 and arr[0] == arr[1])
  puts "-1"
else
  puts "1"
  arr.sort!
  puts arr[-1]
end


Even if you just leave them be, they will fall to pieces all by themselves. So, someone has to protect them, right?You find yourself playing with Teucer again in the city of Liyue. As you take the eccentric little kid around, you notice something interesting about the structure of the city.Liyue can be represented as a directed graph containing $$$n$$$ nodes. Nodes are labeled from $$$1$$$ to $$$n$$$. There is a directed edge from node $$$a$$$ to node $$$b$$$ if and only if $$$a < b$$$.A path between nodes $$$a$$$ and $$$b$$$ is defined as a sequence of edges such that you can start at $$$a$$$, travel along all of these edges in the corresponding direction, and end at $$$b$$$. The length of a path is defined by the number of edges. A rainbow path of length $$$x$$$ is defined as a path in the graph such that there exists at least 2 distinct colors among the set of $$$x$$$ edges.Teucer's favorite number is $$$k$$$. You are curious about the following scenario: If you were to label each edge with a color, what is the minimum number of colors needed to ensure that all paths of length $$$k$$$ or longer are rainbow paths?Teucer wants to surprise his older brother with a map of Liyue. He also wants to know a valid coloring of edges that uses the minimum number of colors. Please help him with this task!

The only line of input contains two integers $$$n$$$ and $$$k$$$ ($$$2 \leq k < n \leq 1000$$$).

On the first line, output $$$c$$$, the minimum colors you need to satisfy the above requirements. On the second line, print a valid edge coloring as an array of $$$\frac{n(n-1)}{2}$$$ integers ranging from $$$1$$$ to $$$c$$$. Exactly $$$c$$$ distinct colors should exist in the construction. Print the edges in increasing order by the start node first, then by the second node. For example, if $$$n=4$$$, the edge colors will correspond to this order of edges: ($$$1$$$, $$$2$$$), ($$$1$$$, $$$3$$$), ($$$1$$$, $$$4$$$), ($$$2$$$, $$$3$$$), ($$$2$$$, $$$4$$$), ($$$3$$$, $$$4$$$)

NoteThe corresponding construction for the first test case looks like this:    It is impossible to satisfy the constraints with less than $$$2$$$ colors.The corresponding construction for the second test case looks like this:    One can show there exists no construction using less than $$$3$$$ colors.

n,$k=gets.split.map(&:to_i)
def maxpw x,y
  ret=0
  while x!=y
    x,y=x/$k,y/$k
    ret+=1
  end
  return ret
end
puts maxpw(0,n-1)
(n-1).times do|i|
  (n-i-1).times do|j|
    print maxpw(i,i+j+1),' '
  end
end

n,$k=gets.split.map(&:to_i)
def maxpw x,y
  ret=1
  while x!=y
    x,y=x/$k,y/$k
    ret+=1
  end
  return ret
end
puts maxpw(0,n-1)-1
(n-1).times do|i|
  (n-i-1).times do|j|
    print maxpw(i,i+j),' '
  end
end


Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbasaur.Each day, he takes the front page of the newspaper. He cuts out the letters one at a time, from anywhere on the front page of the newspaper to form the word "Bulbasaur" (without quotes) and sticks it on his wall. Bash is very particular about case — the first letter of "Bulbasaur" must be upper case and the rest must be lower case. By doing this he thinks he has caught one Bulbasaur. He then repeats this step on the left over part of the newspaper. He keeps doing this until it is not possible to form the word "Bulbasaur" from the newspaper.Given the text on the front page of the newspaper, can you tell how many Bulbasaurs he will catch today?Note: uppercase and lowercase letters are considered different.

Input contains a single line containing a string s (1  ≤  |s|  ≤  105) — the text on the front page of the newspaper without spaces and punctuation marks. |s| is the length of the string s. The string s contains lowercase and uppercase English letters, i.e. .

Output a single integer, the answer to the problem.

NoteIn the first case, you could pick: Bulbbasaur.In the second case, there is no way to pick even a single Bulbasaur.In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur".

word = gets.chomp
container = {}

"Blbsaur".each_char { |x| container[x] = 0 }

word.each_char do |x|
	if container.has_key?(x)
		container[x] += 1
	end
end

container[ "a" ] /= 2
container[ "u" ] /= 2

puts container.values.min

x,y=['Bulbasaur',gets.chomp].map{|s|
	h=Hash.new 0
	s.chars{|c|h[c]+=1}
	h
}
p x.map{|k,v|y[k]/v}.min

#!/usr/bin/env ruby
count = gets.chomp.chars.reduce(Hash.new(0)) do |count, c|
  count.tap{ |h| h[c] += 1 }
 end
puts [
  count['B'],
  count['u'] / 2,
  count['l'],
  count['b'],
  count['a'] / 2,
  count['s'],
  count['r'],
].min

s = gets.strip
exp_counts = { 'B' => 1, 'u' => 2, 'l' => 1, 'b' => 1, 'a' => 2, 's' => 1, 'r' => 1 }
counts = {}
s.each_char do |c|
    counts[c] = 0 if !counts[c]
    counts[c] += 1
end
act_counts = counts.select { |k, v| exp_counts.keys.include? k }
ans = 0
if act_counts.length == exp_counts.length
    bu_cnt = act_counts['B'] / exp_counts['B']
    u_cnt = act_counts['u'] / exp_counts['u']
    l_cnt = act_counts['l'] / exp_counts['l']
    b_cnt = act_counts['b'] / exp_counts['b']
    a_cnt = act_counts['a'] / exp_counts['a']
    s_cnt = act_counts['s'] / exp_counts['s']
    r_cnt = act_counts['r'] / exp_counts['r']
    ans = [bu_cnt, u_cnt, l_cnt, b_cnt, a_cnt, s_cnt, r_cnt].min
end
puts ans

a=gets.chomp

ans=0
h=Hash.new(0)
"Bulbasaur".chars{|e|
	h[e]=0
}

a.chars{|e|
	if h.key?(e) then
		h[e]+=1
	end
}
h["a"]/=2
h["u"]/=2

ans=h["B"];
h.each{|k,v|
	ans=v if ans>v
}

puts ans

#!/usr/bin/env ruby

newspapper = gets.strip
letter_count = Hash.new(0)
pokemon = 'Bulbasaur'
newspapper.each_char do |char|
  letter_count[char] += 1 if pokemon.include? char
end

def compute_count(letter_count, pokemon)
  count = 0
  loop do
    pokemon.each_char do |char|
      cur_count = letter_count[char]
      return count if cur_count == 0
      letter_count[char] = cur_count - 1
    end
    count += 1
  end
end

puts compute_count(letter_count, pokemon)

s = gets.chomp
required = {'B' => 1, 'u' => 2,'l' => 1, 'b' => 1,'a' => 2,'s' => 1,'r' => 1}
count = Hash.new(0)
s.each_char do |a|
	count[a] += 1
end
val = []
required.each_key do |k|
	val << count[k] / required[k]
end
puts val.min

inp = gets.strip
str = "Bulbasaur"
puts str.chars.map { |c| inp.count(c) / str.count(c) }.min

a=gets.chomp

ans=0
h=Hash.new(0)
"Bulbasaur".chars{|e|
	h[e]=0
}

a.chars{|e|
	if h.key?(e) then
		h[e]+=1
	end
}
h["a"]/=2
ans=h["B"];
h.each{|k,v|
	ans=v if ans>v
}

puts ans


Given an array $$$a$$$ of length $$$n$$$ and an integer $$$k$$$, you are tasked to find any two numbers $$$l$$$ and $$$r$$$ ($$$l \leq r$$$) such that:   For each $$$x$$$ $$$(l \leq x \leq r)$$$, $$$x$$$ appears in $$$a$$$ at least $$$k$$$ times (i.e. $$$k$$$ or more array elements are equal to $$$x$$$).  The value $$$r-l$$$ is maximized. If no numbers satisfy the conditions, output -1.For example, if $$$a=[11, 11, 12, 13, 13, 14, 14]$$$ and $$$k=2$$$, then:   for $$$l=12$$$, $$$r=14$$$ the first condition fails because $$$12$$$ does not appear at least $$$k=2$$$ times.  for $$$l=13$$$, $$$r=14$$$ the first condition holds, because $$$13$$$ occurs at least $$$k=2$$$ times in $$$a$$$ and $$$14$$$ occurs at least $$$k=2$$$ times in $$$a$$$.  for $$$l=11$$$, $$$r=11$$$ the first condition holds, because $$$11$$$ occurs at least $$$k=2$$$ times in $$$a$$$. A pair of $$$l$$$ and $$$r$$$ for which the first condition holds and $$$r-l$$$ is maximal is $$$l = 13$$$, $$$r = 14$$$.

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains the integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \leq k \leq n$$$) — the length of the array $$$a$$$ and the minimum amount of times each number in the range $$$[l, r]$$$ should appear respectively. Then a single line follows, containing $$$n$$$ integers describing the array $$$a$$$ ($$$1 \leq a_i \leq 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case output $$$2$$$ numbers, $$$l$$$ and $$$r$$$ that satisfy the conditions, or "-1" if no numbers satisfy the conditions. If multiple answers exist, you can output any.

gets.to_i.times do
  n, k = gets.split.map(&:to_i)
  as = gets.split.map(&:to_i)
  xs = as.tally.filter_map { |a, count| a if count >= k }.sort
  ys = xs.chunk_while { |a, b| a + 1 == b }.max_by(&:size)
  if ys
    puts "#{ys[0]} #{ys[-1]}"
  else
    p -1
  end
end

gets.to_i.times do
  n, k = gets.split.map(&:to_i)
  freq = Hash.new(0)
  gets.split.map(&:to_i).each { freq[_1] += 1 }
  freq.filter! { |_, v| v >= k }
  keys = freq.keys.sort

  best = [0, nil]
  cur = [0, nil]
  prev = nil

  keys.each do |key|
    if prev && (prev + 1) == key
      cur[0] += 1
    else
      cur[0] = 1
    end
    cur[1] = key
    prev = key
    best = cur.clone if cur[0] > best[0]
  end

  unless best[1]
    p -1
    next
  end

  puts "#{best[1] - best[0] + 1} #{best[1]}"
end

def solve
  _, x = gli
  a = gli.tally.map { |k, v| k if v >= x }.compact.sort
  if a.empty?
    puts(-1)
    return
  end
  ans = 0
  al = a[0]
  cur = 0
  l = a[0]
  (1...a.size).each do |i|
    if a[i - 1] + 1 != a[i]
      if ans < cur
        al = l
        ans = cur
      end
      cur = 0
      l = a[i]
    else
      cur += 1
    end
  end
  if ans < cur
    al = l
    ans = cur
  end
  puts [al, al + ans].join(' ')
end

MOD = 10**9 + 7
def gs = gets.chomp
def gi = gets.to_i
def gli = gets.split.map(&:to_i)
def cyesno(x) = x ? :Yes : :No
def uyesno(x) = x ? :YES : :NO

gets.to_i.times { solve }

main = -> {
  t = int
  t.times do
      n, k = ints
      a = ints.tally
      prev = -1
      prev_l = nil
      count = 0
      ans = -1
      ans_len = -1
      a.keys.sort.each do |key|
          if a[key] >= k
              if prev == key - 1
              else
                  prev_l = key
              end
              if ans_len < key - prev_l
                ans = "#{prev_l} #{key}"
                ans_len = key - prev_l
              end
              prev = key
          end
      end
      puts ans
  end
}

DEBUG = true
MOD = 10**9+7
$yesno = %w(No Yes)
YesNo = %w(No Yes)
YESNO = %w(NO YES)
INF = 10**18

require "set"
require "prime"

def int; gets.to_s.to_i end
def ints; gets.to_s.split.map { |s| s.to_i } end
def int1s; gets.to_s.split.map { |s| s.to_i - 1 } end
def float; gets.to_s.to_f end
def floats; gets.to_s.split.map { |s| s.to_f } end
def array_of(&convert); gets.to_s.split.map(&convert) end
def string; gets.to_s.chomp end
def strings; gets.to_s.split end
def rep(n, &b); Array.new(n, &b) end
def yes; puts $yesno[1] end
def no; puts $yesno[0] end
def yesno t; puts $yesno[t] end
def YesNo t; puts YesNo[t] end
def YESNO t; puts YESNO[t] end
def zip(xs, *yss); Enumerator.new { |y| xs.zip(*yss) { |a| y.yield(*a) } } end
def max(*xs, &block); block_given? ? xs.max_by(&block) : xs.max end
def min(*xs, &block); block_given? ? xs.min_by(&block) : xs.min end
def minmax(*xs, &block); block_given? ? xs.minmax_by(&block) : xs.minmax end
def gcd(*xs); xs.inject(0, :gcd) end
def matrix(h, w, fill=nil, &block); return Array.new(h) { Array.new(w, &block) } if block_given?; Array.new(h) { [fill] * w } end
def debug(x = nil); STDERR.puts (block_given? ? yield(x) : x).inspect if DEBUG; x end
def debug_grid(grid, width = 1); grid.each { |row| STDERR.puts row.map { |x| x.inspect.ljust(width) }.join("") } if DEBUG; grid end
def if_debug; yield if DEBUG end

module Boolean
  def coerce(other); [other, to_i] end
  def +@; to_i end
  def to_int; to_i end
  def *(other); to_i * other end
end

class TrueClass
  include Boolean
  def to_i; 1 end
end

class FalseClass
  include Boolean
  def to_i; 0 end
end

class Integer
  def div_ceil(y); (self + y - 1) / y end
  def mod_inv(mod = MOD); pow(mod-2, mod) end
  def mod_div(y, mod = MOD); self * y.mod_inv(mod) % mod end
  def mod_nCr(r, mod = MOD); x = y = 1; (1..r).each { |i| x = x * (self + 1 - i) % mod; y = y * i % mod }; x.mod_div(y, mod); end
  def factorial(mod = MOD); (2..self).inject(1) { |f, x| f * x % mod } end
  def popcount; x = self; c = 0; while x > 0; c += 1 if x & 1 == 1; x >>= 1 end; c end #TODO: faster
  def bitbrute(&block); (1<<self).times(&block) end
  def nCr(r); x = 1; (1..r).each { |i| x *= self + 1 - i; x /= i }; x; end
  def each_divisor; return Enumerator.new { |y| each_divisor { |k| y << k } } unless block_given?; k = 1; while k * k < self; if self % k == 0; yield k; yield self / k end; k += 1; end; yield k if k * k == self end
  def divisors; each_divisor.to_a end
end

class Range
  def end_open; exclude_end? ? self.end : self.end + 1 end
  def end_close; exclude_end? ? self.end - 1 : self.end end
  def upper_bound; ac, wa = self.begin, self.end_open; while wa - ac > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end
  def lower_bound; ac, wa = self.end_open, self.begin; while ac - wa > 1; if yield((wj = (ac + wa) / 2)); ac = wj else wa = wj end; end; yield(ac) ? ac : nil end
  def shakutori(r2, &pred); Enumerator.new { |y| j, r = r2.begin, r2.end_open; each { |i| j += 1 while j + 1 < r and pred[i, j+1]; y.yield(i, j) } }; end
  def widest(&block); Enumerator.new { |y| j, n = self.begin, self.end_open; each { |i| j += 1 while j < n and block[i, j]; y.yield(i, j) if block[i, j] } } end
end

class Array
  def power(&block); (0 ... 1 << size).each(&block) end
  def sorted_merge(other); a = []; i = j = 0; n, m = size, other.size; if j < m and other[j] < self[i]; a << other[j]; j += 1 else; a << self[i]; i += 1 end while i < n; a.push(*other[j..-1]) if j < m; a end
  def upper_bound; ac, wa = 0, size; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end
  def lower_bound; ac, wa = size, 0; while wa - ac > 1; if yield(self[(wj = (ac + wa) / 2)]); ac = wj else; wa = wj end; end; ac end
  def cum(*xs, &op); a = []; a << xs[0] if xs.size > 0; a << x = self[0]; (1...size).each { |i| a << x = op[x, self[i]] }; a end
  def cumdiff(range); self[range.end_open] - self[range.begin]; end
  def compress(kinds = uniq.sort!); map { |x| kinds.bsearch_index { _1 >= x } }; end
end

module Enumerable
  def sorted_uniq; x = nil; filter { |y| c = x === y; x = y; !c } end
  def cumsum; ys = [0]; each { |x| ys << x + ys[-1] }; ys end
end

main[]


You are given three integers $$$a$$$, $$$b$$$, $$$k$$$.Find two binary integers $$$x$$$ and $$$y$$$ ($$$x \ge y$$$) such that   both $$$x$$$ and $$$y$$$ consist of $$$a$$$ zeroes and $$$b$$$ ones;  $$$x - y$$$ (also written in binary form) has exactly $$$k$$$ ones.  You are not allowed to use leading zeros for $$$x$$$ and $$$y$$$.

The only line contains three integers $$$a$$$, $$$b$$$, and $$$k$$$ ($$$0 \leq a$$$; $$$1 \leq b$$$; $$$0 \leq k \leq a + b \leq 2 \cdot 10^5$$$) — the number of zeroes, ones, and the number of ones in the result.

If it's possible to find two suitable integers, print "Yes" followed by $$$x$$$ and $$$y$$$ in base-2. Otherwise print "No". If there are multiple possible answers, print any of them.

a,b,k = gets.chomp.split(" ").map(&:to_i)
b -= 1
if a == 0 && b == 0 && k == 0
  puts "Yes"
  puts 1
  puts 1
elsif k >= a+b || (k != 0 && a == 0) || (b == 0 && k > 0)
  puts "No"
else
  puts "Yes"
  x = Array.new(a+b,0)
  y = Array.new(a+b,0)
  if b > 0
    y[-1] = 1
    x[-(k+1)] = 1
  end
  i = 0
  (b-1).times do
    while x[i] == 1 || y[i] == 1
      i += 1
    end
    x[i] = 1
    y[i] = 1
    i += 1
  end
  x.unshift("1")
  y.unshift("1")
  puts x.join
  puts y.join
end

zeroes, ones, k = gets.split(/\s+/).map(&:to_i)
x = ('1'*ones + '0'*zeroes).to_i(2)

r = ('1'*k + '0'*[zeroes-k,0].max).to_i(2)
y = x-r

if y > 0 && y.to_s(2).count('1') == ones && y.to_s(2).count('0') == zeroes
  puts "Yes"
  puts x.to_s(2)
  puts y.to_s(2)
else
  puts "No"
end

a,b,k = gets.chomp.split(" ").map(&:to_i)
b -= 1
if k >= a+b || (k != 0 && a == 0)
  puts "No"
else
  puts "Yes"
  x = Array.new(a+b,0)
  y = Array.new(a+b,0)
  y[-1] = 1
  x[-(k+1)] = 1
  i = 0
  (b-1).times do
    while x[i] == 1 || y[i] == 1
      i += 1
    end
    x[i] = 1
    y[i] = 1
    i += 1
  end
  x.unshift("1")
  y.unshift("1")
  puts x.join
  puts y.join
end

a,b,k = gets.chomp.split(" ").map(&:to_i)
if k == a+b || (k != 0 && a == 0)
  puts "No"
else
  puts "Yes"
  x = Array.new(a+b,0)
  y = Array.new(a+b,0)
  y[-1] = 1
  x[-(k+1)] = 1
  i = 0
  (b-1).times do
    while x[i] == 1 || y[i] == 1
      i += 1
    end
    x[i] = 1
    y[i] = 1
    i += 1
  end
  puts x.join
  puts y.join
end


You are given a correct solution of the sudoku puzzle. If you don't know what is the sudoku, you can read about it here.The picture showing the correct sudoku solution:Blocks are bordered with bold black color.Your task is to change at most $$$9$$$ elements of this field (i.e. choose some $$$1 \le i, j \le 9$$$ and change the number at the position $$$(i, j)$$$ to any other number in range $$$[1; 9]$$$) to make it anti-sudoku. The anti-sudoku is the $$$9 \times 9$$$ field, in which:  Any number in this field is in range $$$[1; 9]$$$;  each row contains at least two equal elements;  each column contains at least two equal elements;  each $$$3 \times 3$$$ block (you can read what is the block in the link above) contains at least two equal elements. It is guaranteed that the answer exists.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. Then $$$t$$$ test cases follow. Each test case consists of $$$9$$$ lines, each line consists of $$$9$$$ characters from $$$1$$$ to $$$9$$$ without any whitespaces — the correct solution of the sudoku puzzle.

For each test case, print the answer — the initial field with at most $$$9$$$ changed elements so that the obtained field is anti-sudoku. If there are several solutions, you can print any. It is guaranteed that the answer exists.

gets.to_i.times do
	a = (1..9).map { gets.chomp.split('').map &:to_i }
	(0...9).each do |i|
		j = i % 3 * 3 + i / 3
		a[i][j] = a[i][j] == 9 ? 1 : a[i][j] + 1
	end
	puts a.map(&:join)
end

t = gets.chomp.to_i

(1..t).each{
    (0...9).each{|i|
        s = gets.chomp
        a = i / 3
        b = i % 3

        n = 3*b + a
        if s[n] == '9' then
            s[n] = '1'
        else
            s[n] = (s[n].ord + 1).chr
        end

        puts s
    }
}


Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, n coins of arbitrary values a1, a2, ..., an. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally.As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner.

The first line contains integer n (1 ≤ n ≤ 100) — the number of coins. The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 100) — the coins' values. All numbers are separated with spaces.

In the single line print the single number — the minimum needed number of coins.

NoteIn the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.In the second sample one coin isn't enough for us, too. You can pick coins with values 1, 2 or 2, 2. In any case, the minimum number of coins equals 2.

ln1 = gets
n = ln1.to_i
ln2 = gets
s = ln2.split(' ')
a = Array.new(0)
sum = 0
for i in 0..n-1
  a << s[i].to_i
  sum += a[i]
end
a = a.sort
a = a.reverse
idx = 0
have = 0
for i in 0..n-1
  sum -= a[i]
  have += a[i]
  if(have > sum)
    idx = i
    break
  end
end
p idx + 1

n = gets.to_i
a = gets.split.map(&:to_i)
sum = 0
a.each { |e|
  sum += e
}
a.sort!.reverse!
res = 0
have = 0
n.times { |i|
  sum -= a[i]
  have += a[i]
  (res = i + 1; break) if have > sum
}
p res

n = gets.to_i
a = gets.split.map(&:to_i).sort.reverse
sum = 0
a.each { |e|
  sum += e
}
res = 0
have = 0
n.times { |i|
  sum -= a[i]
  have += a[i]
  (res = i + 1; break) if have > sum
}
p res

n = gets.to_i
m = gets.split(' ').map{|_|_.to_i}.sort{|x,y| y<=>x}
total = m.inject(:+)
sum=0
m.each.with_index do |obj,id|
  sum+=obj
  if sum*2>total
    puts id+1
    break
  end
end

gets
a = gets.strip.split.map(&:to_i)
sum = a.sort!.reverse!.inject(0) {|acc, m| acc + m }
f = 0
i = 0
while f <= sum-f
  f += a[i]
  i += 1
end
puts i

n = gets
coins = gets.chomp.split(' ').map(&:to_i).sort{|x,y| y <=> x}
sum = coins.reduce(:+)
counter = 0
taken_sum = 0
coins.each do |coin|
  taken_sum += coin
  counter += 1
  sum -= coin
  break if taken_sum > sum
end

puts counter

n = gets.chomp.to_i

coins = gets.chomp.split().map { |x| x.to_i }
coins.sort!
coins.reverse!

sumLeft = 0
for i in coins
    sumLeft += i
end

i = 0
sumRight = 0
while i < n
    sumLeft -= coins[i]
    sumRight += coins[i]
    if sumRight > sumLeft
        break
    end
    i += 1
end

puts (i+1)

n = gets.to_i
st = gets.split
i = 0
sum = 0
while i<n do
    st[i] = st[i].to_i
    sum += st[i]
    i += 1
end
st = st.sort.reverse
min = sum/2
coins = 1
s1 = st[0]
j = 0
while s1<=min do
    j += 1
    i = st.size-1
    while (i>j && s1+st[i]<=min) do
        i -= 1
    end
    if i<=j then
        s1 = s1 + st[j]
    else
        s1 = s1 + st[i]
    end
    coins += 1
end
puts "#{coins}"

n = gets.chomp.to_i
m = gets.chomp.split(/ /).map!{|x| x.to_i}
m.sort!.reverse!
sum = 0
for i in 0..m.length-1
	sum += m[i]
end
wsum = 0
ret = 0
for i in 0..m.length-1
	ret += 1
	wsum += m[i]
	rest = sum - wsum
	if rest < wsum
		break
	end
end
puts ret

# cook your code here

n = gets.to_i
a = gets.chomp.split
sum = 0
cum = Array.new

for i in 0...n
    a[i] = a[i].to_i
    sum += a[i]
end

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

cum[0] = a[0]
i = 0

until cum[i] > sum/2
    i+=1
    cum[i] = cum[i-1] + a[i]
end

puts i+1

n,*a=gets(p).split.map &:to_i;z=eval a*?+;p n-a.sort.index{|i|0>=z-=i*2}

n = gets.to_i
a = gets.split.map(&:to_i).sort.reverse
b = []
a.each do |_|
    b << _
    if a.inject(&:+) < b.inject(&:+) * 2
        p b.size
        break
    end
end

n,*a=gets(p).split.map &:to_i;z=eval a*?+;n-=1while 0<z-=a.sort[-n]*2;p n

gets
a=gets.split.map &:to_i
z=a.inject:+
p a.sort.reverse.count{|i|0<=z-=i*2}+1

sum=0
n=gets.to_i
a=gets.split.map(&:to_i)
a.sort!
a.reverse!
a.each{|i| sum+=i }
ans=0
tmp=0
a.each{|i|
        ans+=1
        sum-=i
        tmp+=i
        if tmp>sum
                p ans
                exit
        end
}

n = gets.to_i
a = gets.split.map &:to_i
a.sort!{|a,b|b<=>a}

sumAll = 0
a.each {|el| sumAll += el }

cnt = 0
sum = 0
a.each do |el|
  sum += el
  cnt += 1
  break if sum > sumAll / 2
end
puts cnt

n = gets.chomp.to_i
a = gets.chomp.split(" ").map{|e| e.to_i}.sort!{|a, b| -(a <=> b)}
b = []
c = 0
while a.length > 0 do
  b << a.shift
  c += 1
  if b.inject(0){|s, i| s += i} > a.inject(0){|s, i| s += i}
    break
  end
end

puts c

def sum(numbers)
  total = 0

  numbers.each do |i|
    total += i
  end

  total
end

def quick_sort(numbers, lower_bound, upper_bound)
  if lower_bound < upper_bound
    p = partition(numbers, lower_bound, upper_bound)
    quick_sort(numbers, lower_bound, p - 1)
    quick_sort(numbers, p + 1, upper_bound)
  end

end

def partition(numbers, lower_bound, upper_bound)
  pivot = numbers[upper_bound]
  i, j = lower_bound, lower_bound

  while j <= upper_bound
    if numbers[j] < pivot
      numbers[i], numbers[j] = numbers[j], numbers[i]
      i += 1
    end

    j += 1
  end

  numbers[i], numbers[upper_bound] = numbers[upper_bound], numbers[i]
  i
end

def main
  number_of_coins = gets.to_i
  coins = gets.split.map(&:to_i)

  total_value = sum coins

  quick_sort(coins, 0, number_of_coins - 1)

  coins_needed = 0
  sum = 0

  until sum > total_value / 2
    sum += coins[number_of_coins - coins_needed - 1]
    coins_needed += 1
  end

  puts coins_needed
end

main if __FILE__ == $PROGRAM_NAME

n = STDIN.readline.to_i
coins = STDIN.readline.split.map {|s| s.to_i }
total = coins.inject(0, :+)
sum = 0
count = 0
coins.sort.reverse.each do |coin|
  sum += coin
  count += 1
  break if 2*sum > total
end
puts count

n = gets.chomp.to_i

array = gets.chomp.split(" ").map(&:to_i).sort.reverse
arr_sum = array.inject(&:+)
res = array[0]
ans = 0
(1..n).each{ |elem|
  if( res > arr_sum / 2.0)
    ans = elem
    break
  else
    res += array[elem]
  end
}
puts ans

n = gets.to_i
a = gets.split(" ").map(&:to_i).sort{ |x,y| y <=> x }

for i in 0..n
  l = a[0..i].inject(:+)
  r = a[(i+1)..(a.size)].inject(:+) || 0
  if (l) > (r)
    puts i+1
    break
  end
end

n=gets.to_i
a=gets.split.map(&:to_i).sort{|x,y|y<=>x}
n.times do |i|
  if i+1<a.size&&a.slice(0,i+1).reduce(:+)>a.slice(i+1,a.size-i-1).reduce(:+)
  	p i+1
  	break
  elsif i+1==a.size
  	p i+1
  end
end

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

counter = a.reduce(:+)
xounter = 0
c = 0
for i in 0..n-1
  counter-=a[i]
  xounter+=a[i]
  c+=1
  break if xounter>counter
end

puts c

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

a.sort!.reverse!
$s = a.inject(:+)
#puts "s=#{$s}"

# returns [s1, t]
def find(a,n)
    if n == 1
        return [a.first, 1]
    else
        s1, t = find(a,n-1)
        #puts "s1=#{s1}, t=#{t}"
        s2 = $s - s1
        an = a[n-1]
        if s2>=s1
            s1 += an
            t += 1
        end
        return [s1, t]
    end
end

#p a
s1, t = find(a, a.count)
#p s1
p t

n =gets.chomp.to_i
a= gets.chomp
arr = a.split(/\s/).map(&:to_i)
arr.sort!.reverse!
sum1 =0
count  =0
check =0
arr.each{|x| check+=x }

check =check/2
arr.each do |i|
	sum1+=i
	count+=1
	if sum1>check
		break
	end
end
puts count

n = gets.chomp.to_i
a = gets.chomp.split(/ /).map!{|x| x.to_i}

a = a.sort
s = 0
for i in 0..n-1
    s = s + a[i]
end
ss = 0
nr = 0

i = n-1
begin
    if ss <= s
        ss = ss + a[i]
        s = s - a[i]
        nr = nr + 1
    else
        break
    end
    i = i - 1
end while i >= 0

puts nr

gets
inp = gets.chomp.split.map { |x| x.to_i }.sort
count, total = 0, 0
while total <= inp.inject(0, :+)
  total += inp.pop
  count += 1
end
puts count

n,*a=gets(p).split.map &:to_i;z=eval a*?+;p n-a.sort.index{|i|0>=z-=i*2}

a=gets.chomp.to_i
b=gets.chomp.split(" ")
sum=0
0.upto(a-1) do |i|
   b[i]= b[i].to_i
sum=sum+b[i]
end
r=0
if sum%2==0
    r=1
end

sum=(sum/2.0).ceil

b.sort!
b.reverse!
p=0
0.upto(a-1) do |i|
p=p+b[i].to_i

if ( p>=sum && r==0)
p=i+1
break
end
if  (p>sum && r==1)
p=i+1
break
end
end

puts "#{p}"

require 'pp'

gets
coins = gets.chomp.split(' ').map(&:to_i).sort

i = coins.length - 1
while i >= 0
  head = coins[0..i-1]
  tail = coins[i..-1]
  head_sum = head.inject(&:+)
  tail_sum = tail.inject(&:+)

  debug =  {
    head: head,
    tail: tail,
    head_sum: head_sum,
    tail_sum: tail_sum,
  }

  if tail_sum > head_sum
    break
  end
  # pp debug
  i -= 1
end
puts coins.length - [i, 0].max
#pp coins

n= gets.to_i
a = gets.split.map(&:to_i)
tot, sum, i= 0,0,0
a.each {|x| tot += x}
a.sort! {|x,y| y<=>x}
until sum>tot-sum
  sum += a[i]
  i += 1
end
puts i

def sum( coins )
    sum = 0
    coins.each do |coin|
        sum += coin
    end
    sum
end

gets.chomp
coins = gets.chomp.split(/ /).map(&:to_i)
coins.sort!
my_coins = []
(coins.length - 1).downto(0).each do |coin|
    break if ( sum( my_coins ) > sum( coins ) )
    my_coins << coins.delete_at( coin )
end
puts my_coins.length

n = gets.to_i
a = gets.split.map(&:to_i).push(0).sort
b = [0]
c = 0
loop do
  break if b.inject(:+) > a.inject(:+)
  b << a.pop
  c += 1
end

p c

class C160A
  n = gets.to_i
  a = []
  gets.split.map{|c| a << c.to_i}
  a.sort!
  a.reverse!
  s = 0
  a.map{|c| s += c}
  t = 0
  q = 0
  a.map{|c| t += c; q += 1; break if t * 2 > s}
  puts q
end

a=[]
n=gets.to_i
b=gets.split
n.times{|i|
	a[i]=b[i].to_i}
a.sort!

b=0
ans=0
halfsum=a.inject(:+)/2

n.times{|i|
	break if b>halfsum
	b+=a[-i-1]
	ans+=1}
p ans

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

n = $stdin.gets.to_i
xs = $stdin.gets.split.map(&:to_i).sort.reverse
s = xs.inject 0, :+
acc = 0
xs.each_with_index do |x, i|
  acc += x
  if acc*2 > s
    puts i+1
    break
  end
end

n = gets.to_i
a = gets.chomp.split.map(&:to_i).sort.reverse
sum = a.inject(:+)
count = 0
money = 0

a.each { |i| count += 1; money += i; break if money > (sum/2.0) }

puts count

n = gets.to_i
a = gets.split().map &:to_i
a=a.sort.reverse
sum = a.inject 0 do |x,y| x + y end
s=0
cnt = 0

while s + s <= sum
    s += a[cnt]
    cnt = cnt + 1
end

puts cnt

n = gets.strip.to_i
a = gets.strip.split.map(&:to_i)[0..(n-1)].sort! {|x, y| y <=> x}
sum = a.reduce(:+)
segment = 0
count = 0
a.each do |item|
	segment += item
	count += 1
	if segment * 2 > sum
		break
	end
end
puts count

n = Integer(gets)
input = gets.chomp
nums = input.split
value = Array.new
for i in 0...n
    value[i] = Integer(nums[i])
end

value = value.sort{|x,y| y <=> x}
sum = 0
for i in 0...n
    sum = sum + value[i]
end

v = Array.new
x = 0
for i in 0..n
    if x > sum - x then
        break

    else
        v.push(value[i])
        x = x + value[i]
    end
end

puts v.length

coins = gets.chomp.to_i
values = gets.chomp
values = values.split

total = 0
for i in (0..coins-1)
	for x in (i..coins-1)
		if i != x
			if values[i].to_i < values[x].to_i
				temp = values[i].to_i
				values[i] = values[x].to_i
				values[x] = temp
			end
		end
	end
	total += values[i].to_i
end

test_values = 0
count = 0
for i in (0..coins-1)
	if test_values <= total - test_values
		test_values += values[i].to_i
		count += 1
	else
		break
	end
end

print count

n=gets.to_i
a=gets.split.map(&:to_i)
a.sort!
a.reverse!
#puts a[0]
sum = 0
a.each do
  |t|
  sum += t
end
 res = 1
 sum2=0
a.each do
  |t|
  sum2+=t
  break if sum2 > (sum-sum2)
  res += 1
end
puts res

n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i).sort_by{ |x| -x }

s = a.reduce(&:+)
sum = 0

a.each_with_index do |x, i|
    sum += x
    if sum > s / 2
        puts i + 1
        break
    end
end

def sum(a)
    a.inject(0){|sum,x| sum + x}
end

n = gets.to_i
arr = gets.split(" ").map(&:to_i)
arr.sort!{|x, y| y <=> x}
total = sum(arr)
i = 0
while i < n
    arr_sum = sum arr[0,i+1]
    i += 1
    if arr_sum > total - arr_sum
        puts i
        break
    end

end

def sum(a)
    a.inject(0){|sum,x| sum + x}
end

n = gets.to_i
arr = gets.split(" ").map(&:to_i)
arr.sort!{|x, y| y <=> x}
total = sum(arr)
i = 0
arr_sum = 0
while i < n
    arr_sum += arr[i]
    i += 1
    if arr_sum > total - arr_sum
        puts i
        break
    end

end

gets
cs = gets.split.map(&:to_i).sort.reverse
sum = cs.inject(:+)
puts cs.index{ |x| 0 > sum -= 2*x } + 1

n,*a=gets(p).split.map &:to_i;z=eval a*?+;p n-a.sort.index{|i|0>=z-=i*2}

gets
l = gets.split.map(&:to_i).sort { |x, y| y <=> x }
s = l.reduce(:+)
t = 0
c = 0

l.each { |x|
			c += 1
			t += x
			if t > s - t
				break
			end
		}

puts c

coin_number = gets.chomp.to_i
coin_seq_number = gets.chomp.split
coin_seq_number = coin_seq_number.map{|item| item.to_i}
coin_seq_sum = coin_seq_number.inject {|sum, i| sum + i}
coin_seq_number = coin_seq_number.sort{|a,b| b <=> a}
i = 0
coin_res_sum = 0
begin
  coin_res_sum = coin_seq_number[i] + coin_res_sum
  i = i + 1
end while coin_res_sum < coin_seq_sum / 2
if coin_res_sum == coin_seq_sum/2 then
  p i+1
else
  p i
end

n = STDIN.gets.chomp.to_i
coins = []

coins = STDIN.gets.split.map { |n| n.to_i }

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

total = coins.reduce(:+)

sum = 0
numC = 0
while sum <= total/2
  sum += coins[numC]
  numC += 1
end

puts numC

n = gets.to_i
a = gets.split.map(&:to_i).sort.reverse
sum = a.reduce(:+)

(0...n).each do |i|
  former = a[0..i].reduce(:+)
  if former > sum - former
    puts i + 1
    break
  end
end

n = gets.to_i
a = gets.chomp.split(" ")

for x in 0...a.size
	a[x] = a[x].to_i
end

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

sum1 = 0
sum2 = 0
m = 0

for x in 0...a.size
	sum1 += a[x]
	for y in x+1...a.size
		sum2 += a[y]
	end
	if sum1>sum2
		m = x+1
		break
	end
	sum2 = 0
end

puts m

n, coins = gets.to_i, gets.split.map(&:to_i).sort.reverse
sum = 0
total = coins.inject(:+)
(n + 1).times do |i|
	if sum > total / 2
		puts i
		break
	end
	sum += coins[i]
end

t = gets.to_i
a = gets.split(" ").map(&:to_i)
a = a.sort.reverse
sum=-1
for i in 0..t
    if a[0,i].inject(0, :+)>a[i,t].inject(0, :+)
        sum=i
        break
    end
end
print(sum)

n = gets.chomp.to_i
coins = gets.split.collect{|i| i.to_i}
coins = coins.sort{|x,y| y <=> x}

target = coins.inject(:+) / 2
sum = 0
coins.each_index{|i|
  sum += coins[i]
  if sum > target
    puts i + 1
    break
  end
}

n = gets.to_i
a = gets.split.map(&:to_i)
a = a.sort.reverse
total = a.inject(:+)
s = 0
a.each_with_index do |x, i|
  s += x
  if 2 * s > total
    puts i + 1
    break
  end
end

n=gets.to_i
a=[]
(n-1).times {
a.push gets(' ').to_i
}
a.push gets.to_i

prog=(a.inject{|sum,x| sum + x })/2

suma=0
licznik=0

for i in a.sort.reverse
suma+=i
licznik+=1
if suma>prog
p licznik
break
end
end

gets
a=gets.split.map(&:to_i)
a.sort!
a.reverse!
sum=a.inject{|res,x|res+x}
k=0
for i in 0..a.length-1
 if 2*k<=sum
   k+=a[i]
 end
 if 2*k>sum
   break
 end
end
puts i+1

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

while s.inject(0, &:+) <= a.inject(0, &:+)
  s << a.pop
end

puts s.size

n = gets.to_i
a = gets.split

sum = 0
for i in 0 ... a.size
	a[i] = a[i].to_i
	sum += a[i]
end

a.sort!.reverse!

sum2 = 0
for i in 0 ... a.size
	sum2 += a[i]
	if sum2 > sum / 2 then
		puts((i + 1).to_s)
		break
	end
end

_ = gets.chomp
a = gets.chomp.split(/ /).map(&:to_i).sort { |a,b| b <=> a}
my_count = 0
my = 0
all = a.inject(0) { |sum, x| sum + x }
a.each do |a_i|
  my += a_i
  all -= a_i
  my_count += 1
  break if my > all
end
puts my_count

input = STDIN.read.split("\n")[1].split(" ").map(&:to_i).sort!

count = 0
sum = 0

while !input.empty? and sum <= input.inject {|sum, v| sum += v} do
	sum += input.pop
	count += 1
end

STDOUT.puts count

coinNum = gets.chomp.to_i
coins = gets.chomp.split(' ').map(&:to_i).sort.reverse
ans = 0
coins << 0

for i in (0...coinNum)
	ans += 1
	break if coins[0..i].reduce(:+) > coins[(i + 1)...coins.length].reduce(:+)
end

puts ans

n = gets
coins = gets.chomp.split(' ').map(&:to_i).sort
sum = coins.reduce(:+)
counter = 0
taken_sum = 0
coins.each do |coin|
  taken_sum += coin
  counter += 1
  sum -= coin
  break if taken_sum > sum
end

puts counter

n = gets.to_i
st = gets.split
i = 0
sum = 0
while i<n do
    st[i] = st[i].to_i
    sum += st[i]
    i += 1
end
st = st.sort.reverse
min = sum/2
coins = 1
s1 = st[0]
j = 0
while s1<=min do
    j += 1
    i = st.size-1
    while (i>1 && s1+st[i]<=min) do
        i -= 1
    end
    if i<=1 then s1 = s1 + st[j]
    else
        s1 = s1 + st[i]
    end
    coins += 1
end
puts "#{coins}"

sum=0
n=gets.to_i
a=gets.split.map(&:to_i)
a.sort!
a.reverse!
a.each{|i| sum+=i }
ans=0
tmp=0
a.each{|i|
        ans+=1
        sum-=i
        tmp+=i
        if tmp>i
                p ans
                exit
        end
}

n = gets.chomp.to_i
a = gets.chomp.split(" ").map{|e| e.to_i}.sort!
b = []
c = 0
while a.length > 0 do
  b << a.shift
  c += 1
  if b.inject(0){|s, i| s += i} > a.inject(0){|s, i| s += i}
    break
  end
end

puts c

n = gets.to_i
a = gets.split(" ").map(&:to_i).sort{ |x,y| y <=> x }

for i in 0..n
  l = a[0..i].inject(:+)
  r = a[i..(a.size)].inject(:+) || 0
  if (l) > (r)
    puts i+1
    break
  end
end

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

a.sort!.reverse!
$s = a.inject(:+)
#puts "s=#{$s}"

# returns [s1, t]
def find(a,n)
    if n == 1
        return [a.first, 1]
    else
        s1, t = find(a,n-1)
        #puts "s1=#{s1}, t=#{t}"
        s2 = $s - s1
        an = a[n-1]
        if s2>s1
            s1 += an
            t += 1
        end
        return [s1, t]
    end
end

#p a
s1, t = find(a, a.count)
#p s1
p t

require 'pp'

gets
coins = gets.chomp.split(' ').map(&:to_i).sort.reverse

i = coins.length - 1
while i >= 0
  head = coins[0..i-1]
  tail = coins[i..-1]
  head_sum = head.inject(&:+)
  tail_sum = tail.inject(&:+)

  debug =  {
    head: head,
    tail: tail,
    head_sum: head_sum,
    tail_sum: tail_sum,
  }

  if tail_sum > head_sum
    break
  end
  # pp debug
  i -= 1
end
puts coins.length - [i, 0].max
#pp coins

n = gets.to_i
a = gets.chomp.split(//).sort.reverse.map(&:to_i)
sum = a.inject(:+)
count = 0
money = 0

a.each { |i| count += 1; money += i; break if money > (sum/2.0).ceil }

puts count

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

sum = a.inject 0 do |x,y| x + y end
s=0
cnt = 0

while s + s <= sum
    s += a[cnt]
    cnt = cnt + 1
end

puts cnt

n = Integer(gets)
input = gets.chomp
nums = input.split
value = Array.new
for i in 0...n
	value[i] = Integer(nums[i])
end

value = value.sort{|x,y| y <=> x}
sum = 0
for i in 0...n
	sum = sum + value[i]
end

v = Array.new
x = 0
for i in 0...n
	if x > sum - x
		puts v.length
	else
		v.push(value[i])
		x = x + value[i]
	end
end

n = Integer(gets)
input = gets.chomp
nums = input.split
value = Array.new
for i in 0...n
    value[i] = Integer(nums[i])
end

value = value.sort{|x,y| y <=> x}
sum = 0
for i in 0...n
    sum = sum + value[i]
end

v = Array.new
x = 0
for i in 0..n
    if x > sum - x
        puts v.length
    else
        v.push(value[i])
        x = x + value[i]
    end
end

n=gets.to_i
a=gets.split.map(&:to_i)
a.sort!
sum = 0
a.each do
  |t|
  sum += t
end
 res = 1
 sum2=0
a.each do
  |t|
  sum2+=t
  break if sum2 > (sum-sum2)
  res += 1
end
puts res

def sum(a)
    a.inject(0){|sum,x| sum + x}
end

n = gets.to_i
arr = gets.split(" ").map(&:to_i)
arr.sort!{|x, y| y <=> x}
total = sum(arr)
i = 0
while i < n
    arr_sum = sum arr[0,i+1]
    i += 1
    if arr_sum >= total - arr_sum
        puts i
        break
    end

end

coin_number = gets.chomp.to_i
coin_seq_number = gets.chomp.split

coin_seq_number = coin_seq_number.map{|item| item.to_i}
coin_seq_sum = coin_seq_number.inject {|sum, i| sum + i}

i = 0
coin_res_sum = 0
begin
  coin_res_sum = coin_seq_number[i] + coin_res_sum
  i = i + 1
end while coin_res_sum < coin_seq_sum / 2
if coin_number < i+1  then
  p coin_number
else
  p i+1
end

coin_number = gets.chomp.to_i
coin_seq_number = gets.chomp.split

coin_seq_number = coin_seq_number.map{|item| item.to_i}
coin_seq_sum = coin_seq_number.inject {|sum, i| sum + i}

i = 0
coin_res_sum = 0
begin
  coin_res_sum = coin_seq_number[i] + coin_res_sum
  i = i + 1
end while coin_res_sum < coin_seq_sum / 2
p i+1

t = gets.to_i
a = gets.split(" ").map(&:to_i)
a = a.sort
sum=-1
for i in 0..t
    if a[0,i].inject(0, :+)>a[i,t].inject(0, :+)
        sum=i
        break
    end
end
print(sum)

a=gets.chomp.to_i
b=gets.chomp.split(" ").sort.reverse
sum=0
0.upto(a-1) do |i|
sum=sum+b[i].to_i
end
sum=(sum/2)+1
p=0
0.upto(a-1) do |i|
p=p+b[i].to_i
if  p>sum
p=i+1
break
end
end

puts "#{p}"

a=gets.chomp.to_i
b=gets.chomp.split(" ")
sum=0
0.upto(a-1) do |i|
   b[i]= b[i].to_i
sum=sum+b[i]
end
r=0
if sum%2==0
    r=1
end

sum=(sum/2.0).ceil
b.sort!
b.reverse!
p=0
0.upto(a-1) do |i|
p=p+b[i].to_i

if  p>=sum && r==0
p=i+1
break
end
if  p>sum && r==1
p=i+1
break
end
end

a=gets.chomp.to_i
b=gets.chomp.split(" ")
sum=0
0.upto(a-1) do |i|
   b[i]= b[i].to_i
sum=sum+b[i]
end
sum=(sum/2.0).ceil
b.sort!
b.reverse!
p=0
0.upto(a-1) do |i|
p=p+b[i].to_i
if  p>sum
p=i+1
break
end
end

puts "#{p}"

n=gets.to_i
a=[]
(n-1).times {
a.push gets(' ').to_i
}
a.push gets.to_i

prog=(a.inject{|sum,x| sum + x })/2

suma=0
licznik=0

for i in a.sort
suma+=i
licznik+=1
if suma>prog
p licznik
break
end
end

_ = gets.chomp
a = gets.chomp.split(/ /).map(&:to_i).sort { |a,b| b <=> a}
my_count = 0
my = 0
twins = 0
a.each do |a_i|
  if twins + a_i >= my
    my += a_i
    my_count += 1
  else
    twins += a_i
  end
end
puts my_count

_ = gets.chomp
a = gets.chomp.split(/ /).map(&:to_i)
my_count = 0
my = 0
twins = 0
a.each do |a_i|
  if twins + a_i >= my
    my += a_i
    my_count += 1
  else
    twins += a_i
  end
end
puts my_count

input = STDIN.read.split("\n")[1].split(" ").map(&:to_i).sort!
count = 0

while !input.empty? and count < input.inject {|sum, v| sum += v} do
	input.pop
	count += 1
end

STDOUT.puts count


Pashmak has fallen in love with an attractive girl called Parmida since one year ago...Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones.

The first line contains four space-separated x1, y1, x2, y2 ( - 100 ≤ x1, y1, x2, y2 ≤ 100) integers, where x1 and y1 are coordinates of the first tree and x2 and y2 are coordinates of the second tree. It's guaranteed that the given points are distinct.

If there is no solution to the problem, print -1. Otherwise print four space-separated integers x3, y3, x4, y4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them.  Note that x3, y3, x4, y4 must be in the range ( - 1000 ≤ x3, y3, x4, y4 ≤ 1000).

x1, y1, x2, y2 = gets.split.map &:to_i

def evaluate_vertical_side x1, x2, y1, y2
  delta_y = (y2 - y1).abs
  if x1 + delta_y <= 1000
    x3 = x1 + delta_y
    return [x3, y1, x3, y2]
  elsif x1 - delta_y >= -1000
    x3 = x1 - delta_y
    return [x3, y1, x3, y2]
  else
    return -1
  end
end

if x1 == x2 #vertical side
  new_points = evaluate_vertical_side x1, x2, y1, y2
  puts new_points == -1? "-1" : "#{new_points[0]} #{new_points[1]} #{new_points[2]} #{new_points[3]}"
elsif y1 == y2 #horizontal side
  x1, y1 = y1, x1
  x2, y2 = y2, x2
  new_points = evaluate_vertical_side x1, x2, y1, y2
  puts new_points == -1? "-1" : "#{new_points[1]} #{new_points[0]} #{new_points[3]} #{new_points[2]}"
elsif (y2 - y1).abs == (x2 - x1).abs #diagonal
  x3 = x1
  y3 = y2
  x4 = x2
  y4 = y1
  puts "#{x3} #{y3} #{x4} #{y4}"
else #not squar
  puts "-1"
end

x, y, a, b = gets.split.map(&:to_i)
x, y, a, b = [[x, y], [a, b]].min[0], [[x, y], [a, b]].min[1], [[x, y], [a, b]].max[0], [[x, y], [a, b]].max[1]
if x == a
  puts [x + (y - b).abs, y, a + (y - b).abs, b].map(&:to_s).join(" ")
elsif y == b
  puts [x, y + (x - a).abs, a, b + (x - a).abs].map(&:to_s).join(" ")
else
  if a > x && b > y
    if a - x == b - y
      puts [x, b, a, y].map(&:to_s).join(" ")
    else
      puts "-1"
    end
  else
    if a - x == y - b
      puts [x, b, a, y].map(&:to_s).join(" ")
    else
      puts "-1"
    end
  end
end

x1,y1,x2,y2 = gets.split.map(&:to_i)
dx = (x2-x1)
dy = (y2-y1)

if dx != 0 and dy != 0 and dx.abs != dy.abs
  puts -1
elsif dx == 0
  puts "#{x1+dy} #{y1} #{x1+dy} #{y1+dy}"
elsif dy == 0
  puts "#{x1} #{y1+dx} #{x1+dx} #{y1+dx}"
else
  puts "#{x1} #{y1+dy} #{x1+dx} #{y1}"
end

x1, y1, x2, y2 = gets.chomp.split(/ /).map(&:to_i)
x3, y3, x4, y4 = [0, 0, 0, 0]
invalid = false
if x1 == x2
    diff = (y2 - y1).abs
    x3, x4 = x1 + diff, x2 + diff
    y3, y4 = y1, y2
elsif y1 == y2
    diff = (x2 - x1).abs
    x3, x4 = x1, x2
    y3, y4 = y1 + diff, y2 + diff
elsif (x2 - x1).abs == (y2 - y1).abs
    x3, y3, x4, y4 = x1, y2, x2, y1
else
    invalid = true
end
if !invalid
    puts "#{x3} #{y3} #{x4} #{y4}"
else
    puts "-1"
end

x1,y1,x2,y2=gets.split.map{|e| e.to_i}

dx=x2-x1
dy=y2-y1
dx2=dx.abs
dy2=dy.abs
if dx2==0 && dy2==0 then
	puts -1
elsif dx2==dy2 then
	puts [x1,y2,x2,y1]*" "
elsif dx2==0 then
	puts [x1+dy,y1,x2+dy,y2]*" "
elsif dy2==0 then
	puts [x1,y1+dx,x2,y2+dx]*" "
else
	puts -1
end

class Point
  def initialize(x_c,y_c)
    @x_coord=x_c
    @y_coord=y_c
  end
  def x
    return @x_coord
  end
  def y
    return @y_coord
  end
end

a,b,c,d = gets.split(" ").map {|x| x.to_i}

p1=Point.new(a,b)
p2=Point.new(c,d)

if p1.x==p2.x
  d = (p1.y-p2.y).abs
  print "#{p1.x+d} #{p1.y} #{p2.x+d} #{p2.y}"
  exit
end

if p1.y==p2.y
  d = (p1.x-p2.x).abs
  print "#{p1.x} #{p1.y+d} #{p2.x} #{p2.y+d}"
  exit
end

if (p1.x-p2.x).abs!=(p1.y-p2.y).abs
  print "-1"
  exit
end

print "#{p1.x} #{p2.y} #{p2.x} #{p1.y}"

# coding: utf-8

# if __FILE__ == $0
# end

x1, y1, x2, y2 = gets.split.map(&:to_i)
# -100..100
if x1 == x2
    # vertical edge
    len = (y1 - y2).abs
    puts "#{x1 + len} #{y1} #{x2 + len} #{y2}"
elsif y1 == y2
    # horizontal edge
    len = (x1 - x2).abs
    puts "#{x1} #{y1 + len} #{x2} #{y2 + len}"
elsif (x1-x2).abs == (y1-y2).abs
    # diagonal edge (must be square)
    if x1 < x2
        puts "#{x1} #{y2} #{x2} #{y1}"
    else
        puts "#{x2} #{y1} #{x1} #{y2}"
    end
else
    # impossible
    puts -1
end

xxyy = gets.chomp
xxyy = xxyy.split
x1 = xxyy[0].to_i
y1 = xxyy[1].to_i
x2 = xxyy[2].to_i
y2 = xxyy[3].to_i

if x1 == x2 && y1 != y2
	print x1 + [y1, y2].max - [y1,y2].min
	print " "
	print [y1, y2].max
	print " "
	print x1 + [y1, y2].max - [y1,y2].min
	print " "
	print [y1,y2].min
elsif y1 == y2 && x1 != x2
	print [x1,x2].min
	print " "
	print y1 - ([x1,x2].max - [x1,x2].min)
	print " "
	print [x1,x2].max
	print " "
	print y1 - ([x1,x2].max - [x1,x2].min)
else
	if (x1 - x2).abs == (y1 - y2).abs
		print x1
		print " "
		print y2
		print " "
		print x2
		print " "
		print y1
	else
		print -1
	end
end

x1, y1, x2, y2 = gets.split(' ').map(&:to_i)

if x1 != x2  &&  y1 != y2
  if (x1-x2).abs != (y1-y2).abs
    puts -1
  else
    puts "#{x1} #{y2} #{x2} #{y1}"
  end
elsif x1 != x2
  delta = (x1 - x2).abs
  puts "#{x1} #{y1+delta} #{x2} #{y2+delta}"
elsif y1 != y2
  delta = (y1 - y2).abs
  puts "#{x1+delta} #{y1} #{x2+delta} #{y2}"
else
  puts -1
end

line = gets
x1, y1, x2, y2 = line.split.map(&:to_i)
if y1 == y2
	l = (x1 - x2).abs
	y3 = y1 + l
	x3 = x1
	y4 = y2 + l
	x4 = x2
	puts [x3, y3, x4, y4].join " "
elsif x1 == x2
	l = (y1 - y2).abs
	x3 = x1 + l
	y3 = y1
	x4 = x2 + l
	y4 = y2
	puts [x3, y3, x4, y4].join " "
elsif (x1 - x2).abs == (y1 - y2).abs
	l = (x1 - x2).abs
	x3 = x1
	y3 = if y1 > y2
		y1 - l
	else
		y1 + l
	end
	x4 = if x1 > x2
		x1 - l
	else
		x1 + l
	end

	y4 = y1
	puts [x3, y3, x4, y4].join " "
else
	puts "-1"
end

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

x, y, a, b = [[x, y], [a, b]].min[0], [[x, y], [a, b]].min[1],
              [[x, y], [a, b]].max[0], [[x, y], [a, b]].max[1]

if x == a
  puts [x + (y-b).abs, y, a + (y-b).abs, b].map(&:to_s).join(" ")
elsif y == b
  puts [x, y + (x-a).abs, a, b + (x-a).abs].map(&:to_s).join(" ")
else
  if a > x && b > y
    if a - x == b - y
      puts [x, b, a, y].map(&:to_s).join(" ")
    else
      puts "-1"
    end
  else
    if a - x == y - b
      puts [x, b, a, y].map(&:to_s).join(" ")
    else
      puts "-1"
    end
  end
end

x1, y1, x2, y2 = gets.split.map &:to_i

def evaluate_vertical_side x1, x2, y1, y2
  delta_y = (y2 - y1).abs
  if x1 + delta_y <= 1000
    x3 = x1 + delta_y
    return [x3, y1, x3, y2]
  elsif x1 - delta_y >= -1000
    x3 = x1 - delta_y
    return [x3, y1, x3, y2]
  else
    return -1
  end
end

if x1 == x2 #vertical side
  new_points = evaluate_vertical_side x1, x2, y1, y2
  puts new_points == -1? "-1" : "#{new_points[0]} #{new_points[1]} #{new_points[2]} #{new_points[3]}"
elsif y1 == y2 #horizontal side
  x1, y1 = y1, x1
  x2, y2 = y2, x2
  new_points = evaluate_vertical_side x1, x2, y1, y2
  puts new_points == -1? "-1" : "#{new_points[0]} #{new_points[1]} #{new_points[2]} #{new_points[3]}"
elsif (y2 - y1).abs == (x2 - x1).abs #diagonal
  x3 = x1
  y3 = y2
  x4 = x2
  y4 = y1
  puts "#{x3} #{y3} #{x4} #{y4}"
else #not squar
  puts "-1"
end

x1, y1, x2, y2 = gets.split.map &:to_i

def evaluate_vertical_side x1, x2, y1, y2
  if x1 + (y2 - y1) <= 1000
    x3 = x1 + (y2 - y1)
    return [x3, y1, x3, y2]
  elsif x1 - (y2 - y1) >= -1000
    x3 = x1 - (y2 - y1)
    return [x3, y1, x3, y2]
  else
    return -1
  end
end

if x1 == x2 #vertical side
  new_points = evaluate_vertical_side x1, x2, y1, y2
  puts new_points == -1? "-1" : "#{new_points[0]} #{new_points[1]} #{new_points[2]} #{new_points[3]}"
elsif y1 == y2 #horizontal side
  x1, y1 = y1, x1
  x2, y2 = y2, x2
  new_points = evaluate_vertical_side x1, x2, y1, y2
  puts new_points == -1? "-1" : "#{new_points[0]} #{new_points[1]} #{new_points[2]} #{new_points[3]}"
elsif (y2 - y1).abs == (x2 - x1).abs #diagonal
  x3 = x1
  y3 = y2
  x4 = x2
  y4 = y1

  puts "#{x3} #{y3} #{x4} #{y4}"
else #not squar
  puts "-1"
end

x1, y1, x2, y2 = gets.chomp.split(/ /).map(&:to_i)
x3, y3, x4, y4 = [0, 0, 0, 0]
invalid = false
if x1 == x2
    diff = (y2 - y1).abs
    x3, x4 = x1 + diff, x2 + diff
    y3, y4 = y1, y2
elsif y1 == y2
    diff = (y2 - y1).abs
    x3, x4 = x1, x2
    y3, y4 = y1 + diff, y2 + diff
elsif (x2 - x1).abs == (y2 - y1).abs
    x3, y3, x4, y4 = x1, y2, x2, y1
else
    invalid = true
end
if !invalid
    puts "#{x3} #{y3} #{x4} #{y4}"
else
    puts "-1"
end

x1,y1,x2,y2=gets.split.map{|e| e.to_i}

dx=x2-x1
dy=y2-y1
if dx==0 && dy==0 then
	puts -1
elsif dx==dy then
	puts [x1,y1+dx,x2,y2-dy]*" "
elsif dx==0 then
	puts [x1+dy,y1,x2+dy,y2]*" "
elsif dy==0 then
	puts [x1,y1+dx,x2,y2+dx]*" "
else
	puts -1
end

x1,y1,x2,y2 = gets.split.map(&:to_i)
dx = (x2-x1)
dy = (y2-y1)

if dx != 0 and dy != 0 and dx.abs != dy.abs
  puts -1
elsif dx == 0
  puts "#{x1+dx} #{y1} #{x1+dx} #{y1+dy}"
elsif dy == 0
  puts "#{x1} #{y1+dy} #{x1+dx} #{y1+dy}"
else
  puts "#{x1} #{y1+dy} #{x1+dx} #{y1}"
end

x1,y1,x2,y2 = gets.split.map(&:to_i)
dx = (x2-x1)
dy = (y2-y1)
if dx != 0 and dy != 0 and dx != dy
  puts -1
elsif dx == 0
  puts "#{x1+dy} #{y1} #{x1+dy} #{y1+dy}"
elsif dy == 0
  puts "#{x1} #{y1+dx} #{x1+dx} #{y1+dx}"
else
  puts "#{x1} #{y1+dx} #{x1+dx} #{y1}"
end

line = gets
x1, y1, x2, y2 = line.split.map(&:to_i)
if y1 == y2
	l = (x1 - x2).abs
	y3 = y1 + l
	x3 = x1
	y4 = y2 + l
	x4 = x2
	puts [x3, y3, x4, y4].join " "
elsif x1 == x2
	l = (y1 - y2).abs
	x3 = x1 + l
	y3 = y1
	x4 = x2 + l
	y4 = y2
	puts [x3, y3, x4, y4].join " "
elsif (x1 - x2).abs == (y1 - y2).abs
	l = (x1 - x2).abs
	x3 = x1
	y3 = y1 + l
	x4 = x1 + l
	y4 = y1
	puts [x3, y3, x4, y4].join " "
else
	puts "-1"
end


A bracket sequence is a string containing only characters "(" and ")".A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()", "(())" are regular (the resulting expressions are: "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not.You are given $$$n$$$ bracket sequences $$$s_1, s_2, \dots , s_n$$$. Calculate the number of pairs $$$i, j \, (1 \le i, j \le n)$$$ such that the bracket sequence $$$s_i + s_j$$$ is a regular bracket sequence. Operation $$$+$$$ means concatenation i.e. "()(" + ")()" = "()()()".If $$$s_i + s_j$$$ and $$$s_j + s_i$$$ are regular bracket sequences and $$$i \ne j$$$, then both pairs $$$(i, j)$$$ and $$$(j, i)$$$ must be counted in the answer. Also, if $$$s_i + s_i$$$ is a regular bracket sequence, the pair $$$(i, i)$$$ must be counted in the answer.

The first line contains one integer $$$n \, (1 \le n \le 3 \cdot 10^5)$$$ — the number of bracket sequences. The following $$$n$$$ lines contain bracket sequences — non-empty strings consisting only of characters "(" and ")". The sum of lengths of all bracket sequences does not exceed $$$3 \cdot 10^5$$$.

In the single line print a single integer — the number of pairs $$$i, j \, (1 \le i, j \le n)$$$ such that the bracket sequence $$$s_i + s_j$$$ is a regular bracket sequence.

NoteIn the first example, suitable pairs are $$$(3, 1)$$$ and $$$(2, 2)$$$.In the second example, any pair is suitable, namely $$$(1, 1), (1, 2), (2, 1), (2, 2)$$$.

n = gets.to_i
seqs = []
n.times do |i|
  seqs << gets.strip
end

hsh = {}

seqs.each do |seq|
  b = 0
  balanced = true
  seq.each_char do |c|
    if c == '('
      b += 1
    end
    if c == ')'
      b -= 1
    end
    balanced = false if b < 0
  end
  hsh[b] = (hsh[b] || 0) + 1 if balanced

  b = 0
  balanced = true
  seq.reverse.each_char do |c|
    if c == '('
      b += 1
    end
    if c == ')'
      b -= 1
    end
    balanced = false if b > 0
  end
  hsh[b] = (hsh[b] || 0) + 1 if balanced && b<0
end

# puts hsh
ans = 0
ans += (hsh[0] * hsh[0]) if hsh[0]
pos_ub = hsh.keys.select{|x| x>0}
pos_ub.each do |pub|
  nub = -1 * pub
  ans += (hsh[pub] * (hsh[nub] || 0))
end
puts ans

# http://codeforces.com/problemset/problem/990/C

def count_seq
  n = gets.to_i
  h = {}
  regular = 0
  0.upto(n - 1) do |i|
    bs = gets.chomp
    ret = parse(bs)
    next if ret.nil?

    if ret == ''
      regular += 1
    elsif
      h[ret] ||= 0
      h[ret] += 1
    end
  end

  c = regular * regular
  # puts h.inspect

  h.each do |key, count|
    next if key[0] == ')'

    other_key = [')', key[1]]
    other_c = h[other_key]
    # puts "other_c #{other_c}"
    if other_c
      c += other_c * count
    end
  end

  c
end

def parse(bs)
  a = []
  bs.each_char do |c|
    if a.empty? || a.last == c
      a << c
      next
    end

    if a.last == '('
      a.slice!(a.size - 1)
    else
      a << c
    end
  end

  return '' if a.empty?
  return nil if a.first != a.last

  return [a.first, a.size]
end

puts count_seq

def left_stack(a)
  stack = []
  a.each_char do |c|
    if c == '('
      stack.push(c)
    else
      if stack.pop != '('
        return nil
      end
    end
  end
  stack
end

def right_stack(a)
  stack = []
  a.reverse.each_char do |c|
    if c == ')'
      stack.push(c)
    else
      if stack.pop != ')'
        return nil
      end
    end
  end
  return stack
end

def left_sign_stack(a)
  stack = left_stack(a)
  stack && stack.length
end

def right_sign_stack(a)
  stack = right_stack(a)
  stack && stack.length
end

left_count = Hash.new(0)
right_count = Hash.new(0)

n = gets.to_i
n.times do
  s = gets.chomp
  left_sign = left_sign_stack(s)
  right_sign = right_sign_stack(s)
  left_count[left_sign] += 1 if left_sign
  right_count[right_sign] += 1 if right_sign
end

res = 0
left_count.each do |sign, cnt1|
  res += cnt1 * right_count[sign]
end

puts res

n = gets.to_i
seqs = []
n.times do |i|
  seqs << gets.strip
end

hsh = {}

seqs.each do |seq|
  b = 0
  balanced = true
  seq.each_char do |c|
    if c == '('
      b += 1
    end
    if c == ')'
      b -= 1
    end
    balanced = false if b < 0
  end
  balanced = false if b > 0
  hsh[0] = (hsh[0] || 0) + 1 if balanced
  if b < 0
    hsh[b] = (hsh[b] || 0) + 1
  end
  if b > 0
    hsh[b] = (hsh[b] || 0) + 1
  end
end

ans = 0
ans += (hsh[0] * hsh[0]) if hsh[0]
pos_ub = hsh.keys.select{|x| x>0}
pos_ub.each do |pub|
  nub = -1 * pub
  ans += (hsh[pub] * (hsh[nub] || 0))
end
puts ans

# http://codeforces.com/problemset/problem/990/C

def count_seq
  n = gets.to_i
  h = {}
  regular = 0
  0.upto(n - 1) do |i|
    bs = gets.chomp
    ret = parse(bs)
    next if ret.nil?

    if ret == ''
      regular += 1
    elsif
      h[ret] ||= 0
      h[ret] += 1
    end
  end

  c = regular * regular
  # puts h.inspect

  h.each do |key, count|
    next if key[0] == ')'

    other_key = ['(', key[1]]
    other_c = h[other_key]
    if other_c
      c += other_c * count
    end
  end

  c
end

def parse(bs)
  a = []
  bs.each_char do |c|
    if a.empty? || a.last == c
      a << c
      next
    end

    if a.last == '('
      a.slice!(a.size - 1)
    else
      a << c
    end
  end

  return '' if a.empty?
  return nil if a.first != a.last

  return [a.first, a.size]
end

puts count_seq

# http://codeforces.com/problemset/problem/990/C

def count_seq
  n = gets.to_i
  h = {}
  regular = 0
  0.upto(n - 1) do |i|
    bs = gets.chomp
    ret = parse(bs)
    if ret.nil?
      regular += 1
    else
      h[ret] ||= 0
      h[ret] += 1
    end
  end

  c = regular * regular
  # puts h.inspect

  h.each do |key, count|
    next if key[0] == 'r'

    other_key = ['r', key[1]]
    other_c = h[other_key]
    if other_c
      c += other_c * count
    end
  end

  c
end

def parse(bs)
  l = 0
  r = 0
  bs.each_char do |c|
    (c == '(') ? (l += 1) : (r += 1)
  end

  return nil if l == r

  if l > r
    ['l', l - r]
  else
    ['r', r - l]
  end
end

puts count_seq


Valera considers a number beautiful, if it equals 2k or -2k for some integer k (k ≥ 0). Recently, the math teacher asked Valera to represent number n as the sum of beautiful numbers. As Valera is really greedy, he wants to complete the task using as few beautiful numbers as possible. Help Valera and find, how many numbers he is going to need. In other words, if you look at all decompositions of the number n into beautiful summands, you need to find the size of the decomposition which has the fewest summands.

The first line contains string s (1 ≤ |s| ≤ 106), that is the binary representation of number n without leading zeroes (n > 0).

Print a single integer — the minimum amount of beautiful numbers that give a total of n.

NoteIn the first sample n = 2 is a beautiful number.In the second sample n = 7 and Valera can decompose it into sum 23 + ( - 20).In the third sample n = 109 can be decomposed into the sum of four summands as follows: 27 + ( - 24) + ( - 22) + 20.

x, y = 0, 1
s = readline.strip
s.each_char do |c|
	m = [x, y].min + 1
	if c == '0'
		y = m
	else
		x = m
	end
end
puts x