You are given a problemset consisting of $$$n$$$ problems. The difficulty of the $$$i$$$-th problem is $$$a_i$$$. It is guaranteed that all difficulties are distinct and are given in the increasing order.You have to assemble the contest which consists of some problems of the given problemset. In other words, the contest you have to assemble should be a subset of problems (not necessary consecutive) of the given problemset. There is only one condition that should be satisfied: for each problem but the hardest one (the problem with the maximum difficulty) there should be a problem with the difficulty greater than the difficulty of this problem but not greater than twice the difficulty of this problem. In other words, let $$$a_{i_1}, a_{i_2}, \dots, a_{i_p}$$$ be the difficulties of the selected problems in increasing order. Then for each $$$j$$$ from $$$1$$$ to $$$p-1$$$ $$$a_{i_{j + 1}} \le a_{i_j} \cdot 2$$$ should hold. It means that the contest consisting of only one problem is always valid.Among all contests satisfying the condition above you have to assemble one with the maximum number of problems. Your task is to find this number of problems.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of problems in the problemset. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — difficulties of the problems. It is guaranteed that difficulties of the problems are distinct and are given in the increasing order.

Print a single integer — maximum number of problems in the contest satisfying the condition in the problem statement.

NoteDescription of the first example: there are $$$10$$$ valid contests consisting of $$$1$$$ problem, $$$10$$$ valid contests consisting of $$$2$$$ problems ($$$[1, 2], [5, 6], [5, 7], [5, 10], [6, 7], [6, 10], [7, 10], [21, 23], [21, 24], [23, 24]$$$), $$$5$$$ valid contests consisting of $$$3$$$ problems ($$$[5, 6, 7], [5, 6, 10], [5, 7, 10], [6, 7, 10], [21, 23, 24]$$$) and a single valid contest consisting of $$$4$$$ problems ($$$[5, 6, 7, 10]$$$).In the second example all the valid contests consist of $$$1$$$ problem.In the third example are two contests consisting of $$$3$$$ problems: $$$[4, 7, 12]$$$ and $$$[100, 150, 199]$$$.

n = gets.to_i
a = gets.split.map(&:to_i)
puts a.chunk_while { _1 * 2 >= _2 }.map(&:size).max

def compute(n, as)
  last = nil
  max = 0
  crt = 0

  as.each do |a|
    if last
      if last * 2 >= a
        crt += 1
      else
        crt = 1
      end
    else
      crt += 1
    end

    max = [crt, max].max
    last = a
  end

  max

end

def solution
  n = read_int
  as = read_ints

  puts compute(n, as)
end

def read_int
  gets.to_i
end

def read_ints
  gets.split.map(&:to_i)
end

def read_string
  gets.chomp
end

solution unless ENV['TEST__MODE']

#! /usr/bin/ruby

gets
input = gets.chomp.split ' '
input.map! { |word| word.to_i  }

i = 0
j = 0
ans = 0

while j < input.size - 1
  if input[j + 1] <= 2 * input[j]
    j += 1
  else
    ans = [ans, j - i + 1].max
    j += 1
    i = j
  end
end

ans = [ans, j - i + 1].max

puts ans

N = gets.to_i
as = gets.split.map(&:to_i)
ans = 1
len = 1
now = as[0]
(1...N).each do |i|
    if now*2 >= as[i]
        now = as[i]
        len += 1
        ans = len if ans < len
    else
        len = 1
        now = as[i]
    end
end
puts ans

class Node
	attr_accessor :prev
	attr_accessor :next
	attr_accessor :data

	def initialize(p,n,d)
		@prev = p
		@next = n
		@data = d
	end
end

class Que
	def initialize()
		@front = nil
		@rear = nil
		@size = 0
	end

	def pushl(k)
		@size += 1
		a = Node.new(@rear,nil,k)
		if(@front == nil)
			@front = a
			@rear = a
		else
			@rear.next = a
			@rear = a
		end
	end

	def popf()
		@size -= 1
		rem = @front
		@front = @front.next
		# @front.prev = nil
		if (@size == 0)
			@rear = nil
		else
			@front.prev = nil
		end
		return rem.data
	end

	def contains(k)
		now = @front
		while(now != nil)
			if (now.data == k)
				return true
			else
				now = now.next
			end
		end
		return false
	end

	def pushf(k)
		@size += 1
		a = Node.new(nil,@front,k)
		@front = a
		if(@front == nil)
			@rear = a
		end
	end

	def popl()
		@size -= 1
		a = @rear
		if(@size == 0)
			@front = nil
			@rear = nil
		else
			@rear = @rear.prev
			@rear.next = nil
		end
		return a.data
	end
	def front()
		return @front.data
	end

	def size()
		return @size
	end

	def rear()
		return @rear.data
	end
end

useless = gets.chomp.to_i
inp = gets.chomp.split(" ")
arr = Array.new()
for i in inp
	arr << i.to_i
end
if useless == 1
	print(1)
	exit
end
q = Que.new()
q.pushl(arr[0])
max = -10
cur = 1
i = 1
marked = true
until i == useless
	if (marked)
		q.pushl(arr[i])
	end
	if(arr[i] <= q.front*2)
		cur += 1
		if(max < cur)
			max= cur
		end
		marked = true
	else
		q.popf
		if(q.size == 1)
			cur = 0
		end
		i -= 1
		marked = false
	end
	i += 1
end

print(max)

def binary_search(range)
  lower = 0
  upper = range.size
  while lower < upper
    mi = (lower + upper)/2
    yield(range[mi]) ? upper = mi : lower = mi + 1
  end
  [range[upper], upper]
end

n = gets.to_i
a = gets.split.map(&:to_i)
dp = Array.new(n)
e = Array.new(n)
dp[0] = 1
e[0] = 0
(1...n).each do |i|
  if 2*a[e[i-1]] >= a[i]
    e[i] = i
    dp[i] = dp[i-1]+1
  elsif 2*a[i-1] >= a[i]
    e[i] = i
    dp[i] = 2
  else
    e[i] = e[i-1]
    dp[i] = dp[i-1]
  end
end
puts dp.max

class Node
	attr_accessor :prev
	attr_accessor :next
	attr_accessor :data

	def initialize(p,n,d)
		@prev = p
		@next = n
		@data = d
	end
end

class Que
	def initialize()
		@front = nil
		@rear = nil
		@size = 0
	end

	def pushl(k)
		@size += 1
		a = Node.new(@rear,nil,k)
		if(@front == nil)
			@front = a
			@rear = a
		else
			@rear.next = a
			@rear = a
		end
	end

	def popf()
		@size -= 1
		rem = @front
		@front = @front.next
		# @front.prev = nil
		if (@size == 0)
			@rear = nil
		else
			@front.prev = nil
		end
		return rem.data
	end

	def contains(k)
		now = @front
		while(now != nil)
			if (now.data == k)
				return true
			else
				now = now.next
			end
		end
		return false
	end

	def pushf(k)
		@size += 1
		a = Node.new(nil,@front,k)
		@front = a
		if(@front == nil)
			@rear = a
		end
	end

	def popl()
		@size -= 1
		a = @rear
		if(@size == 0)
			@front = nil
			@rear = nil
		else
			@rear = @rear.prev
			@rear.next = nil
		end
		return a.data
	end
	def front()
		return @front.data
	end

	def size()
		return @size
	end

	def rear()
		return @rear.data
	end
end

useless = gets.chomp.to_i
inp = gets.chomp.split(" ")
arr = Array.new()
for i in inp
	arr << i.to_i
end
if useless == 1
	print(1)
	exit
end
q = Que.new()
q.pushl(arr[0])
max = -10
cur = 1
i = 1
marked = true
until i == useless
	if (marked)
		q.pushl(arr[i])
	end
	if(arr[i] <= q.front*2)
		cur += 1
		if(max < cur)
			max= cur
		end
		marked = true
	else
		q.popf
		cur -= 1
		i -= 1
		marked = false
	end
	i += 1
end

print(max)


Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an n by n square grid of integers. A good lab is defined as a lab in which every number not equal to 1 can be expressed as the sum of a number in the same row and a number in the same column. In other words, for every x, y such that 1 ≤ x, y ≤ n and ax, y ≠ 1, there should exist two indices s and t so that ax, y = ax, s + at, y, where ai, j denotes the integer in i-th row and j-th column.Help Okabe determine whether a given lab is good!

The first line of input contains the integer n (1 ≤ n ≤ 50) — the size of the lab.  The next n lines contain n space-separated integers denoting a row of the grid. The j-th integer in the i-th row is ai, j (1 ≤ ai, j ≤ 105).

Print "Yes" if the given lab is good and "No" otherwise. You can output each letter in upper or lower case.

NoteIn the first sample test, the 6 in the bottom left corner is valid because it is the sum of the 2 above it and the 4 on the right. The same holds for every number not equal to 1 in this table, so the answer is "Yes".In the second sample test, the 5 cannot be formed as the sum of an integer in the same row and an integer in the same column. Thus the answer is "No".

n = gets.strip.to_i
grid = Array.new(n)
n.times do |i|
    grid[i] = gets.strip.split.map(&:to_i)
end
i = 0
ans = true
while i < n && ans
    j = 0
    while j < n && ans
        cell = grid[i][j]
        if cell != 1
            found = false
            x = 0
            while x < n && !found
                y = 0
                while y < n && !found
                    if x != i && y != j
                        a = grid[i][y]
                        b = grid[x][j]
                        sum = a + b
                        found = true if sum == cell
                    end
                    y += 1
                end
                x += 1
            end
            ans = found
        end
        j += 1
    end
    i += 1
end
puts ans ? "Yes" : "No"


Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers.Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly: is it possible to sort the array a (in increasing order) by reversing exactly one segment of a? See definitions of segment and reversing in the notes.

The first line of the input contains an integer n (1 ≤ n ≤ 105) — the size of array a. The second line contains n distinct space-separated integers: a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ 109).

Print "yes" or "no" (without quotes), depending on the answer. If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them.

NoteSample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.Sample 3. No segment can be reversed such that the array will be sorted.DefinitionsA segment [l, r] of array a is the sequence a[l], a[l + 1], ..., a[r].If you have an array a of size n and you reverse its segment [l, r], the array will become:a[1], a[2], ..., a[l - 2], a[l - 1], a[r], a[r - 1], ..., a[l + 1], a[l], a[r + 1], a[r + 2], ..., a[n - 1], a[n].

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

def sign n
  n == 0 ? 0 : n.abs / n
end
if a.length > 1
  segment_directions = []
  #negative descending, positive ascending
  direction = sign(a[1] - a[0])
  start_index = 0
  end_index = 1

  for i in 2 ... n
    local_direction = sign(a[i] - a[i - 1])
    if local_direction == direction
      end_index = i
    else
      segment_directions << [direction, start_index, end_index]
      direction = local_direction
      start_index = i - 1
      end_index = i
    end
  end
  segment_directions << [direction, start_index, end_index]

  descending_segments = segment_directions.select {|d| d[0] == -1}

  if descending_segments.length > 1
    puts "no"
  elsif descending_segments.length == 1
    reverse_start_index = descending_segments[0][1]
    reverse_end_index = descending_segments[0][2]
    seg_strt_gt_pre = reverse_start_index > 0? a[reverse_end_index] > a [reverse_start_index - 1] : true
    seg_end_lt_nxt = reverse_end_index < n - 1 ? a[reverse_start_index] < a[reverse_end_index + 1] : true;
    if seg_strt_gt_pre &&  seg_end_lt_nxt
      puts "yes"
      puts "#{reverse_start_index + 1} #{reverse_end_index + 1}"
    else
      puts "no"
    end
  else
    puts "yes"
    puts "1 1"
  end
else
  puts "yes", "1 1"
end

N = gets.to_i
arr = gets.chomp.split(' ').map(&:to_i)

rra = arr.sort

if rra == arr
  puts "yes\n1 1"
  exit
end

l = ((0...arr.size).find_index {|i| arr[i] != rra[i]}).to_i
r = ((0...arr.size).to_a.reverse.find {|i| arr[i] != rra[i]}).to_i

brr = []
brr = arr.first(l) + arr[l..r].reverse + arr.last(arr.size - 1 - r)

if brr == rra
  puts 'yes'
  puts "#{l + 1} #{r + 1}"
else
  puts 'no'
end

n = gets.to_i
a = gets.split.map(&:to_i)
b = a.sort
s = a.zip(b).index{|x, y| x != y} || 0
e = a.zip(b).rindex{|x, y| x != y} || 0
a[s..e] = a[s..e].reverse
if a == b
  puts 'yes', "#{s + 1} #{e + 1}"
else
  puts 'no'
end

n = gets.to_i
a = gets.split.map &:to_i
l = n
(1...n).each do |i|
  if a[i] < a[i - 1] then
    l = i
    break
  end
end
if l == n then
  puts 'yes'
  puts '1 1'
else
  r = n
  (l...n).each do |i|
    if a[i] > a[i - 1] then
      r = i
      break
    end
  end
  flag = true
  (0...(l-1)).each do |i|
    if a[i] > a[r - 1] then
      flag = false
      break
    end
  end
  if flag then
    (r...n).each do |i|
      if a[i] < a[i - 1] || a[i] < a[l-1] then
        flag = false
        break
      end
    end
  end
  if flag then
    puts 'yes'
    puts l.to_s + ' ' + r.to_s
  else
    puts 'no'
  end
end

n = gets.to_i;
arr = gets.chomp.split(' ').map(&:to_i);
sorted = arr.sort;

if (arr == sorted)
  puts "yes\n1 1";
  exit;
end

left  = (0...n).find_index  {|i| arr[i] != sorted[i]};
right = (0...n).to_a.rindex {|i| arr[i] != sorted[i]};

arr = arr.first(left) + arr[left..right].reverse + arr.last(n - right - 1);

if (arr == sorted)
  puts "yes\n#{left + 1} #{right + 1}\n";
else
  puts "no";
end

n=gets.to_i
a=gets.chomp.split.map(&:to_i).unshift(0)
a[n+1]=1000000001
i=1
while i<n
	break if a[i]>a[i+1]
	i+=1
end
if i==n
	puts "yes"
	puts "1 1"
else
	j=n
	while j>1
		break if a[j]<a[j-1]
		j-=1
	end
	k=i
	while k<j
		break if a[k]<a[k+1]
		k+=1
	end
	if k!=j||a[i]>a[j+1]||a[i-1]>a[j]
		puts "no"
	else
		puts"yes"
		puts "#{i} #{j}"
	end
end

N = gets.to_i
arr = gets.chomp.split(' ').map(&:to_i)
rra = arr.sort

if rra == arr
  puts "yes\n1 1"
  exit
end

l = ((0...arr.size).find_index {|i| arr[i] != rra[i]}).to_i
r = ((0...arr.size).to_a.reverse.find {|i| arr[i] != rra[i]}).to_i

brr = []
brr = arr.first(l) + arr[l..r].reverse + arr.last(arr.size - 1 - r)

if brr == rra
  puts "yes"
  puts "#{l + 1} #{r + 1}"
else
  puts "no"
end

size = gets.to_i

numbers = gets.split(' ').map(&:to_i)

sorted_array = numbers.sort

if numbers == sorted_array
  puts 'yes'
  puts '1 1'
else
  i = 0
  j = size - 1

  while numbers[i] == sorted_array[i]
    i += 1

    break if i == size
  end

  while numbers[j] == sorted_array[j]
    j -= 1

    break if j == -1
  end

  numbers[i..j] = numbers[i..j].reverse

  if numbers == sorted_array
    puts 'yes'
    puts "#{i + 1} #{j + 1}"
  else
    puts 'no'
  end
end

n=gets.to_i
a=gets.split.map{|i| i.to_i}
b=a.clone.sort
if a==b
	puts "yes\n1 1"
	exit
end
l=0
n.times{|x| l=x; break if a[x]!=b[x]}
r=0
n.times{|x| r=n-1-x; break if a[n-x-1]!=b[n-x-1]}
if a[0,l]+a[l..r].reverse+a[r+1..-1] == b
	puts "yes\n#{l+1} #{r+1}"
elsif
	puts 'no'
end

n = gets.rstrip.to_i
arr = gets.rstrip.split(' ').map(&:to_i)

sorted_arr = arr.sort

l = r = 0
for i in 0..(n - 1)
  if arr[i] != sorted_arr[i]
    l = i
    break
  end
end

j = n - 1
while j >= 0 do
  if arr[j] != sorted_arr[j]
    r = j
    break
  end
  j -= 1
end

j = r
for i in l..r
  if arr[i] != sorted_arr[j]
    puts 'no'
    exit
  else
    j -= 1
  end
end

puts 'yes'
puts "#{l + 1} #{r + 1}"

n=gets.to_i
x=gets.split.map{|e| e.to_i}
c=""
arr=""
minP=0
maxP=0
(x.size-1).times{|i|
	s=""
	if x[i]<x[i+1] then
		s="+"
	else
		s="-"
	end
	if(s!=c) then
		arr<<s
		c=s
		if c=="-" then
			minP=i
		end
	end
	if c=="-" then
		maxP=i+1
	end
}

case arr
when "+",""
	puts "yes"
	puts "1 1"
when "-","+-","-+","+-+"
	ok=true
	if minP>0 then
		x1=x.slice(0..(minP-1))
		x2=x.slice(minP..maxP)
		if x1.max>x2.min then
			ok=false
		end
	end
	if maxP<(x.size-1) then
		x1=x.slice(minP..maxP)
		x2=x.slice(maxP+1,x.size)
		if x1.max>x2.min then
			ok=false
		end
	end
	if ok==false then
		puts "no"
	else
		puts "yes"
		puts [minP+1,maxP+1]*" "
	end
else
	puts "no"
end

n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)
s = 0
e = 0
for i in 0..n-2
	if a[i]>a[i+1]
		s = i
		break
	end
end
(n-1).downto(1) do |i|
	if a[i]<a[i-1]
		e = i
		break
	end

end
	poss = true
for i in s..e-1
	if a[i] < a[i+1]
		poss = false
		break
	end
end

if (s == 0 or a[e] > a[s-1] ) && (e == n-1 or a[s]<a[e+1]) && poss
	poss = true
else
	poss = false
end

if poss
	puts "yes"
	puts "#{s+1} #{e+1}"
else
	puts "no"
end

# coding: utf-8

# if __FILE__ == $0
# end

n = gets.to_i
a = gets.split.map(&:to_i)
prev = -1
chp = []
a.each_with_index { |i, index|
    if i - prev < 0
        chp << index
    end

    prev = i
}
if chp.length == 0
    puts "yes"
    puts "1 1"
elsif chp.length != chp.last - (chp.first - 1)
    puts "no"
else
    fidx = chp.first - 1
    lidx = chp.last
    item_before_fidx = -1
    item_after_lidx = 10**9 + 1
    if fidx > 0
        item_before_fidx = a[fidx - 1]
    end

    if lidx < (n-1)
        item_after_lidx = a[lidx + 1]
    end

    if item_before_fidx <= a[lidx] && item_after_lidx >= a[fidx]
        puts "yes"
        puts "#{fidx+1} #{lidx+1}" # 1-based indices
    else
        puts "no"
    end
end

# if yes: print 'yes' and show begin/end index
# else no

n = gets.to_i
arr =gets.split(" ").map(&:to_i)
prev = arr[0]
seg = nil
seg_start = nil
seg_end = nil
ans = true
seg_found = false
(1..n-1).each do |i|
	if arr[i] >= prev
		if seg
			seg = nil
			seg_end = i - 1
		end
	else
		unless seg
			seg = true
			seg_found = true
			seg_start = i - 1
		end
	end
	prev = arr[i]
end
if seg_found
	seg_end = n - 1 if !seg_end && seg && seg_start
	# puts "#{seg_start} #{seg_end}"
	first_part = arr[0..seg_start - 1] unless seg_start == 0
	last_part = arr[seg_end+1..n-1]
	mid_part = arr[seg_start..seg_end].reverse if arr[seg_start..seg_end]
	new_arr =  (first_part || [] )+ (mid_part || []) +  (last_part ||  [])
	# puts "#{first_part} #{arr[seg_start..seg_end].reverse} #{arr[seg_end+1..n-1]}"
	ans = false unless  new_arr == arr.sort
else
	if arr == arr.sort
		seg_start = 0
		seg_end = 0
	else
		ans = false
	end
end

if ans
	puts "yes"
	puts "#{seg_start+1} #{seg_end+1}"
else
	puts "no"
end

def isSorted(a)
  a.inject([-1, true]) { |p, v|
    [v, (p[1] and p[0] <= v)]
  }[1]
end

n = gets.to_i
a = gets.split.map(&:to_i)
p1 = -1
p2 = -1

prev = -1
a.each_with_index { |val, idx|
  if p1 == -1
    if prev > val
      p1 = idx-1
    end
  else
    if prev < val
      p2 = idx-1
      break
    end
  end
  prev = val
}

if p1 == -1 and p2 == -1
  p1 = p2 = 0
elsif p2 == -1
  p2 = n-1
end
sorted = a[0...p1] + a[p1..p2].reverse + a[p2+1...n]

if isSorted sorted
  puts "yes"
  puts "#{p1+1} #{p2+1}"
else
  puts "no"
end

def find_point(a)
  p1 = -1
  p2 = -1
  prev = -1
  a.each_with_index do |val, idx|
    if p1 == -1
      if prev > val
        p1 = idx-1
      end
    else
      if prev < val
        p2 = idx-1
        break
      end
    end
    prev = val
  end
  [p1, p2]
end

n = gets.to_i
a = gets.split.map(&:to_i)
p1,p2 = find_point a
if p1 == -1 and p2 == -1
  p1 = p2 = 0
elsif p2 == -1
  p2 = n-1
end
sorted = a[0...p1] + a[p1..p2].reverse + a[p2+1...n]

if sorted == a.sort
  puts "yes"
  puts "#{p1+1} #{p2+1}"
else
  puts "no"
end

n = gets.to_i
a = gets.split.map(&:to_i)
b = a.sort
s = nil
e = nil
n.times do |i|
  s = i if a[i] != b[i] && s == nil
  e = i if a[i] != b[i]
end
s = e = 0 if s == nil || e == nil
aa = [a[0...s], a[s..e].reverse, a[e + 1..-1]]
if aa.join == b.join
  puts "yes"
  puts "#{s + 1} #{e + 1}"
else
  puts "no"
end

# coding: utf-8

n = readline.to_i
arr = readline.chomp.split(' ').map(&:to_i)

sarr = arr.sort

if sarr == arr then
    puts 'yes'
    puts '1 1'
else

    l = ((0..arr.size-1).find_index {|i| arr[i] != sarr[i]}).to_i
    r = ((0..arr.size-1).to_a.reverse.find {|i| arr[i] != sarr[i]}).to_i

    parr = []
    parr = arr.first(l) + arr[l..r].reverse + arr.last(arr.size-1-r)

    if parr == sarr then
        puts 'yes'
        puts "#{l+1} #{r+1}"
    else
        puts 'no'
    end
end

# coding: utf-8

n = readline.to_i
arr = readline.chomp.split(' ').map(&:to_i)

sarr = arr.sort

if sarr == arr then
    puts 'yes'
    puts '1 1'
    STDOUT.flush
    exit! 0
end

l = ((0..arr.size-1).find_index {|i| arr[i] != sarr[i]}).to_i
r = ((0..arr.size-1).to_a.reverse.find {|i| arr[i] != sarr[i]}).to_i

parr = []
parr = arr.first(l) + arr[l..r].reverse + arr.last(arr.size-1-r)

if parr == sarr then
    puts 'yes'
    puts "#{l+1} #{r+1}"
else
    puts 'no'
end

length = gets.split.map{|_|_.to_i}
array = gets.split.map{|_|_.to_i}

sorted_array = array.sort
started = 0
ended = 0
switch = 0
index = 0

while index <= array.length
  if sorted_array[index] != array[index]
    if switch % 2 == 0
      started = index
      switch += 1
    else
      ended = index
    end
  end

  index += 1
end

if switch == 0 || sorted_array[started..ended] == array[started..ended].reverse
  puts "yes"
  puts [started + 1, ended + 1].join(" ")
else
  puts "no"
end

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

sorted_list = list.sort
diff_pos = []

for i in 0..(n - 1)
  if list[i] != sorted_list[i]
    diff_pos << i
  end
end

if diff_pos.empty?
  l = 0
  r = 0
else
  l = diff_pos[0]
  r = diff_pos[-1]
end

reverse_segment = list[l..r].dup

for i in 0..((reverse_segment.length - 1)/ 2.0)
  temp = reverse_segment[i]
  reverse_segment[i] = reverse_segment[reverse_segment.length - 1 - i]
  reverse_segment[reverse_segment.length - 1 - i] = temp
end

list[l..r] = reverse_segment

if list == sorted_list
  puts "yes"
  print l + 1, " ", r + 1
else
  puts "no"
end

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

l = 0
r = a.size

a.unshift 0
a.push 10 ** 9 + 1

while l < r && a[l] < a[l+1]
  l += 1
end

while r > l && a[r] > a[r-1]
  r -= 1
end

if a[l] < a[r+1] && a[r] > a[l-1] && (l+1..r).all? { |i| a[i-1] > a[i] }
  puts "yes"
  puts "#{l} #{r}"
else
  puts "no"
end

n = gets.to_i
a = gets.chomp.split.map(&:to_i)
p = q = nil
(0...n - 1).each { |i|
  if a[i] > a[i + 1]
    if q
      puts 'no'
      exit
    end
    p = i unless p
  else
    q = i if p && !q
  end
}
p = n - 1 unless p
q = n - 1 if p && !q
puts (p == 0 || a[p - 1] < a[q]) && (q == n - 1 || a[p] < a[q + 1]) ? "yes\n#{[p + 1, q + 1].join(' ')}" : 'no'

def no;puts "no";exit;end
n=gets.to_i
a=gets.split.map{|s|s.to_i}
l = nil
r = nil
(n-1).times do |i|
  if r
    no if a[i] > a[i+1]
  elsif l
    r = i if a[i] < a[i+1]
  else
    l = i if a[i] > a[i+1]
  end
end
l || (l, r = 0, 0)
r ||= n-1
no if r < n-1 && a[l] > a[r+1]
no if l > 0 && a[l-1] > a[r]
puts "yes"
puts [l+1, r+1].join(" ")

N = gets.to_i
arr = gets.chomp.split(' ').map(&:to_i)

rra = arr.sort

if rra == arr
  puts 'yes'
  puts '1 1'
  exit! 0
end

l = ((0...arr.size).find_index {|i| arr[i] != rra[i]}).to_i
r = ((0...arr.size).to_a.reverse.find {|i| arr[i] != rra[i]}).to_i

brr = []
brr = arr.first(l) + arr[l..r].reverse + arr.last(arr.size - 1 - r)

if brr == rra
  puts 'yes'
  puts "#{l + 1} #{r + 1}"
else
  puts 'no'
end

N = gets.to_i
arr = gets.chomp.split(' ').map(&:to_i)
rra = arr.sort

if rra == arr
  puts "yes\n1 1"
  exit
end

l = ((0...arr.size).find_index {|i| arr != rra[i]}).to_i
r = ((0...arr.size).to_a.reverse.find {|i| arr[i] != rra[i]}).to_i

brr = []
brr = arr.first(l) + arr[l..r].reverse + arr.last(arr.size - 1 - r)

if brr == rra
  puts "yes"
  puts "#{l + 1} #{r + 1}"
else
  puts "no"
end

size = gets.to_i

numbers = gets.split(' ').map(&:to_i)

sorted_array = numbers.sort

if numbers == sorted_array
  puts 'yes'
  puts '1 1'
else
  i = 0
  j = size - 1

  while numbers[i] == sorted_array[i]
    i += 1
  end

  while numbers[j] == sorted_array[j]
    j -= 1
  end

  left_index = i
  right_index = j

  while left_index <= right_index
    break if numbers[i] != sorted_array[j]
    left_index +=1
    right_index -= 1
  end

  if left_index < right_index
    puts 'no'
  else
    puts 'yes'
    puts "#{i + 1} #{j + 1}"
  end

  # numbers[i..j] = numbers[i..j].reverse

  # if numbers == sorted_array
  #   puts 'yes'
  #   puts "#{i + 1} #{j + 1}"
  # else
  #   puts 'no'
  # end

end

size = gets.to_i

numbers = gets.split(' ').map(&:to_i)

sorted_array = numbers.sort

if numbers == sorted_array
  puts 'yes'
  puts '1 1'
else
  i = 0
  j = size - 1

  while numbers[i] == sorted_array[i]
    i += 1
  end

  while numbers[j] == sorted_array[j]
    j -= 1
  end

  left_index = i
  right_index = j

  while left_index < right_index
    break if numbers[i] != numbers[j]
    left_index +=1
    right_index -= 1
  end

  if left_index < right_index
    puts 'no'
  else
    puts 'yes'
    puts "#{i + 1} #{j + 1}"
  end

  # numbers[i..j] = numbers[i..j].reverse

  # if numbers == sorted_array
  #   puts 'yes'
  #   puts "#{i + 1} #{j + 1}"
  # else
  #   puts 'no'
  # end

end

size = gets.to_i

numbers = gets.split(' ').map(&:to_i)

sorted_array = numbers.sort

if numbers == sorted_array
  puts 'yes'
  puts '1 1'
else
  i = 0
  j = size - 1

  while numbers[i] == sorted_array[i]
    i += 1
  end

  while numbers[j] == sorted_array[j]
    j -= 1
  end

  left_index = i
  right_index = j

  not_sorted = false

  while left_index <= right_index
    if numbers[left_index] != sorted_array[right_index]
      not_sorted = true
      break
    end
    left_index +=1
    right_index -= 1
  end

  if not_sorted
    puts 'no'
  else
    puts 'yes'
    puts "#{i + 1} #{j + 1}"
  end

  # numbers[i..j] = numbers[i..j].reverse

  # if numbers == sorted_array
  #   puts 'yes'
  #   puts "#{i + 1} #{j + 1}"
  # else
  #   puts 'no'
  # end
end

size = gets.to_i

numbers = gets.split(' ').map(&:to_i)

sorted_array = numbers.sort

if numbers == sorted_array
  puts 'yes'
  puts '1 1'
else
  i = 0
  j = size - 1

  while numbers[i] == sorted_array[i]
    i += 1
  end

  while numbers[j] == sorted_array[j]
    j -= 1
  end

  left_index = i
  right_index = j

  while left_index <= right_index
    break if numbers[i] != numbers[j]
    left_index +=1
    right_index -= 1
  end

  if left_index < right_index
    puts 'no'
  else
    puts 'yes'
    puts "#{i + 1} #{j + 1}"
  end

  # numbers[i..j] = numbers[i..j].reverse

  # if numbers == sorted_array
  #   puts 'yes'
  #   puts "#{i + 1} #{j + 1}"
  # else
  #   puts 'no'
  # end

end

size = gets.to_i

numbers = gets.split(' ').map(&:to_i)

sorted_array = numbers.sort

if size == 1
  puts 'yes'
  puts '1 1'
else
  i = 0
  j = size

  while numbers[i] == sorted_array[i]
    i += 1
  end

  while numbers[j] == sorted_array[j]
    j -= 1
  end

  numbers[i..j] = numbers[i..j].reverse

  puts numbers == sorted_array ? 'yes' : 'no'
end

size = gets.to_i

numbers = gets.split(' ').map(&:to_i)

sorted_array = numbers.sort

if size == 1
  puts 'yes'
  puts '1 1'
else
  i = 0
  j = 1
  while i < size - 1
    b = numbers.dup
    b[i..j] = b[i..j].reverse!
    if b == sorted_array
      puts 'yes'
      puts "#{i + 1} #{j + 1}"
      break
    end
    j += 1
    if j == size
      i += 1
      j = i + 1
    end
  end
  puts 'no' if i >= size - 1
end

size = gets.to_i

numbers = gets.split(' ').map(&:to_i)

sorted_array = numbers.sort

if numbers == sorted_array
  puts 'yes'
  puts '1 1'
else
  i = 0
  j = size - 1

  while numbers[i] == sorted_array[i]
    i += 1
  end

  while numbers[j] == sorted_array[j]
    j -= 1
  end

  left_index = i
  right_index = j

  while left_index <= right_index
    break if numbers[left_index] != sorted_array[right_index]
    left_index +=1
    right_index -= 1
  end

  if left_index <= right_index
    puts 'no'
  else
    puts 'yes'
    puts "#{i + 1} #{j + 1}"
  end

  # numbers[i..j] = numbers[i..j].reverse

  # if numbers == sorted_array
  #   puts 'yes'
  #   puts "#{i + 1} #{j + 1}"
  # else
  #   puts 'no'
  # end
end

n = gets.rstrip.to_i
arr = gets.rstrip.split(' ').map(&:to_i)

l = 0
arr.each_with_index do |v, i|
  if arr[i + 1] && arr[i] > arr[i + 1]
    l = i
    break
  end
end

r = l
while arr[l] >= arr[r] && r < arr.size - 1 do
  r += 1
end

r -= 1 if r != (arr.size - 1)
r -= 1 if arr[r] > arr[l]

sorted_arr = arr.sort
arr[l], arr[r] = arr[r], arr[l]

if sorted_arr == arr
  puts 'yes'
  puts "#{l + 1} #{r + 1}"
else
  puts 'no'
end

n = gets.rstrip.to_i
arr = gets.rstrip.split(' ').map(&:to_i)

l = 0
arr.each_with_index do |v, i|
  if arr[i + 1] && arr[i] > arr[i + 1]
    l = i
    break
  end
end

r = l
while arr[l] >= arr[r] && r < arr.size - 1 do
  r += 1
end

r -= 1 if r != (arr.size - 1)
r -= 1 if arr[r] > arr[l]

sorted_arr = arr.sort
arr[l], arr[r] = arr[r], arr[l]

if sorted_arr == arr
  puts 'yes'
  puts "#{arr[l]} #{arr[r]}"
else
  puts 'no'
end

n=gets.to_i
x=gets.split.map{|e| e.to_i}
c=""
arr=""
minP=0
maxP=0
(x.size-1).times{|i|
	s=""
	if x[i]<x[i+1] then
		s="+"
	else
		s="-"
	end
	if(s!=c) then
		arr<<s
		c=s
		if c=="-" then
			minP=i
		end
	end
	if c=="-" then
		maxP=i+1
	end
}

case arr
when "+"
	puts "yes"
	puts "1 1"
when "-","+-","-+","+-+"
	ok=true
	if minP>0 then
		x1=x.slice(0..(minP-1))
		x2=x.slice(minP..maxP)
		if x1.max>x2.min then
			ok=false
		end
	end
	if maxP<(x.size-1) then
		x1=x.slice(minP..maxP)
		x2=x.slice(maxP+1,x.size)
		if x1.max>x2.min then
			ok=false
		end
	end
	if ok==false then
		puts "no"
	else
		puts "yes"
		puts [minP+1,maxP+1]*" "
	end
else
	puts "no"
end

n, k = gets.split.map{|_|_.to_i}
a = gets.split.map{|_|_.to_i}

length = gets.split.map{|_|_.to_i}
array = gets.split.map{|_|_.to_i}

sorted_array = array.sort
started = -1
ended = -1
switch = 0
index = 0

while index <= array.length
  if sorted_array[index] != array[index]
    if switch % 2 == 0
      started = index
      switch += 1
    else
      ended = index
    end
  end

  index += 1
end

if switch == 0 || sorted_array[started..ended] == array[started..ended].reverse
  puts "yes"
  puts [started + 1, ended + 1].join(" ")
else
  puts "no"
end

length = gets.split.map{|_|_.to_i}
array = gets.split.map{|_|_.to_i}

sorted_array = array.sort
started = -1
ended = -1
switch = 0
index = 0

while index <= array.length
  if sorted_array[index] != array[index]
    if switch % 2 == 0
      started = index
      switch += 1
    else
      ended = index
    end
  end

  index += 1
end

if sorted_array[started..ended] == array[started..ended].reverse
  puts "yes"
  puts [started + 1, ended + 1].join(" ")
else
  puts "no"
end

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

sorted_list = list.sort

if sorted_list == list
  puts "yes"
  print 1, " ", n
else
  diff_pos = []

  for i in 0..(n - 1)
    if list[i] != sorted_list[i]
      diff_pos << i
    end
  end

  l = diff_pos[0]
  r = diff_pos[-1]

  reverse_segment = list[l..r].dup

  for i in 0..((reverse_segment.length - 1)/ 2.0)
    temp = reverse_segment[i]
    reverse_segment[i] = reverse_segment[reverse_segment.length - 1 - i]
    reverse_segment[reverse_segment.length - 1 - i] = temp
  end

  list[l..r] = reverse_segment

  if list == sorted_list
    puts "yes"
    print l + 1, " ", r + 1
  else
    puts "no"
  end
end

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

temp_list = list.dup
result = []

for r in 0..(n - 1)
  for l in 0..r
    temp = list[r]
    list[r] = list[l]
    list[l] = temp
    if list == list.sort
      break result = [l + 1, r + 1]
    end
  end

  list = temp_list
end

if result.empty?
  puts "no"
else
  puts "yes"
  print result[0], " ", result[1]
end


Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.

The first line contains integer n (1 ≤ n ≤ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.

In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.

NoteIn the first test you can make only one number that is a multiple of 90 — 0.In the second test you can make number 5555555550, it is a multiple of 90.

n,res0,res5 = gets.chomp.to_i, 0, 0
a = gets.chomp.split.map(&:to_i)
a.each { |x| if x==5; res5+=1 else res0+=1 end }
if res0>0; puts '5'*(res5/9*9)+'0'*(res5>8?res0:1) else puts '-1' end

n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
res0, res5 = 0, 0
a.each { |x| if x==5; res5+=1 else res0+=1 end }
if res0>0
  puts '5'*(res5/9*9)+'0'*(res5>8?res0:1)
else
  puts '-1'
end

cnt = gets.to_i
cards = gets.split
n0 = n5 = 0
cards.each {|c|
	if c == "0"
		n0 += 1
	else
		n5 += 1
	end
}
if n0 == 0
	print -1
elsif n5 < 9
	print 0
else
	print "5" * ((n5/9)*9) + "0" * n0
end

f=gets.chomp.to_i
z=gets.chomp.split(" ").count('0')
f=f-z
if z==0 ||(f<9 && z==0)
puts "-1"
elsif f<9 && z>0
puts "0"
else
p="555555555"*(f/9)+("0"*z)
puts p
end

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

if a.select { |i| i.zero? }.size.zero?
  puts "-1"
  exit
end

sum = 0
count = 0
mx = 0
a.each { |e|
  if e == 5
    sum += 5
    count += 1
  end
  if sum % 9 == 0
    mx = count
  end
}

if mx.zero?
  puts "0"
  exit
end
mx.times { print '5' }
(a.size - count).times { print '0' }
puts ""

n=gets.to_i
x=gets.split.map{|e| e.to_i}
if x.index(0) then
	y=x.count{|e|
		e==5
	}
	z=x.size-y
	while (y*50)%90!=0
		y-=1
	end

	if y==0 then
		puts 0
	else

		y.times{
			print 5
		}
		z.times{
			print 0
		}
		puts ""
	end
else
	puts -1
end

n = gets.chomp.to_i
a = gets.chomp.split

a_zero = a.count "0"
a_five = a.count "5"

if a_five >= 9 && a_zero >= 1
  puts "5" * (a_five / 9 * 9) + "0" * a_zero
elsif a_zero >= 1
    puts 0
else
    puts -1
end

cnt=[0]*6
a = $<.to_a[1].split.map(&:to_i)
a.each do |x|
  cnt[x] += 1
end
if cnt[5] >= 9 and cnt[0] > 0
  puts '5' * (cnt[5] - cnt[5] % 9) + '0' * cnt[0]
elsif cnt[0] > 0
  puts '0'
else
  puts '-1'
end

c=Array.new(6,0)
gets
gets.split.map(&:to_i).each{|i|c[i]+=1}
a,b=c[0],c[5]-c[5]%9
if a == 0
	p (-1)
elsif b == 0
	p 0
else
	puts "5"*b+"0"*a
end

n = gets.to_i
a = gets.split(' ').map{|e| e.to_i}
c = Hash.new(0)
a.each{|e|
    c[e] += 1;
}

if c[5]/9 > 0 and c[0] > 0 then
    (c[5]/9 * 9).times{ print 5 }
    c[0].times{print 0}
elsif c[0] > 0
    print 0
else
    print -1
end
puts

#! /usr/bin/env ruby

n = STDIN.gets.to_i
numbers = STDIN.gets.to_s.split(' ').map(&:to_i)

if numbers.length != n
  raise ArgumentError.new
end

def check(numbers, n)
  if numbers.none?(&:zero?)
    return nil
  end
  numbers.sort!.reverse!

  while numbers.first == 5
    sum = numbers.count{|i| i == 5} * 5
    if sum % 9 == 0
      return numbers.join.to_i
    end
    numbers.shift
  end

  0
end

answer = check(numbers, n)
if answer.nil?
  puts "-1"
else
  puts answer
end

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

c0 = a.count 0
c5 = a.count 5

if c0 == 0
	puts -1
elsif c5 < 9
	puts 0
else
	puts '5' * (c5 / 9 * 9) + '0' * c0
end

n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
res0, res5 = 0, 0
a.each { |x| if x==5; res5+=1 else res0+=1 end }
puts '5'*(res5/3*3)+'0'*(res5>2?res0:1)

n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
res0, res5 = 0, 0
a.each { |x| if x==5; res5+=1 else res0+=1 end }
if res0>0
  puts '5'*(res5/3*3)+'0'*(res5>2?res0:1)
else
  puts '-1'
end

n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
res0, res5 = 0, 0
a.each { |x| if x==5; res5+=1 else res0+=1 end }
puts '5'*(res5/5*5)+'0'*res0

cnt = gets.to_i
cards = gets.split
n0 = n5 = 0
cards.each {|c|
	if c == "0"
		n0 += 1
	else
		n5 += 1
	end
}
if n0 == 0
	print -1
elsif n5 < 9
	print 0
else
	print "9" * ((n5/9)*9) + "0" * n0
end

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

if a.select { |i| i.zero? }.size.zero?
  puts "-1"
  exit
end

sum = 0
count = 0
mx = 0
a.each { |e|
  if e == 5
    sum += 5
    count += 1
  end
  if sum % 9 == 0
    mx = count
  end
}

mx.times { print '5' }
(a.size - count).times { print '0' }
puts ""

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

if a.select { |i| i.zero? }.size.zero?
  puts "-1"
  exit
end

sum = 0
count = 0
mx = 0
a.each { |e|
  if e == 5
    sum += 5
    count += 1
  end
  if sum % 9 == 0
    mx = count
  end
}

mx.times { print '5' }
puts '0'

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

if a.select { |i| i.zero? }.size.zero?
  puts "-1"
  exit
end

if a.select { |i| i.zero? }.size == 0
  puts "0"
  exit
end

sum = 0
count = 0
mx = 0
a.each { |e|
  if e == 5
    sum += 5
    count += 1
  end
  if sum % 9 == 0
    mx = count
  end
}

mx.times { print '5' }
(a.size - count).times { print '0' }
puts ""

n = gets.chomp.to_i
a = gets.chomp.split

a_zero = a.count "0"
a_five = a.count "5"

s = ""
divideds = []
(0..1000).each do |i|
  s_zero = (s + "0")
  s_five = (s + "5")
  if s_zero.to_i % 90 == 0 and
     s_zero.count("0") <= a_zero and
     s_zero.count("5") <= a_five then
    divideds << s_zero
  end
  if s_five.to_i % 90 == 0 and
     s_five.count("0") <= a_zero and
     s_five.count("5") <= a_five then
    divideds << s_five
  end
  s += "5"
end

ans = divideds.sort[-1]
puts ans ? ans : -1

n = gets.chomp.to_i
a = gets.chomp.split

a_five = a.count "5"
a_zero = a.count "0"

s = ""
divideds = []
(0...a_five).each do |i|
  if (s+"0").to_i % 90 == 0
    divideds << (s+"0").to_i
  end
  if (s+"5").to_i % 90 == 0
    divideds << (s+"5").to_i
  end
  s += "5"
end

ans = divideds.reject{|i| i % 90 != 0}.sort[-1]
if ans
  puts ans
else
  puts -1
end

n = gets.chomp.to_i
a = gets.chomp.split

a_zero = a.count "0"
a_five = a.count "5"

if a_five >= 9 and a_zero >= 1
  puts "5" * a_five + "0" * a_zero
elsif a_zero >= 1
  puts 0
else
  puts -1
end

n = gets.chomp.to_i
a = gets.chomp.split

a_zero = a.count "0"
a_five = a.count "5"

s = ""
divideds = []
(0...1000).each do |i|
  s_zero = (s + "0")
  s_five = (s + "5")
  if s_zero.to_i % 90 == 0 and
     s_zero.count("0") <= a_zero and
     s_zero.count("5") <= a_five then
    divideds << s_zero
  end
  if s_five.to_i % 90 == 0 and
     s_five.count("0") <= a_zero and
     s_five.count("5") <= a_five then
    divideds << s_five
  end
  s += "5"
end

ans = divideds.sort[-1]
puts ans ? ans : -1

n = gets.chomp.to_i
a = gets.chomp.split

a_zero = a.count "0"
a_five = a.count "5"

if a_five >= 9 and a_zero >= 1
  puts ("5" * a_five + "0" * a_zero).gsub("000000000","555555555")
elsif a_zero >= 1
  puts 0
else
  puts -1
end

n = gets.chomp.to_i
a = gets.chomp.split

a_five = a.count "5"
a_zero = a.count "0"

s = ""
divideds = []
(0...a_five).each do |i|
  if (s+"0").to_f % 90 == 0
    divideds << (s+"0").to_i
  end
  if (s+"5").to_f % 90 == 0
    divideds << (s+"5").to_i
  end
  s += "5"
end

ans = divideds.reject{|i| i % 90 != 0}.sort[-1]
if ans
  puts ans
else
  puts -1
end

n = gets.chomp.to_i
a = gets.chomp.split

a_zero = a.count "0"
a_five = a.count "5"

if a_five >= 9
  puts "5" * (a_five / 9 * 9) + "0" * a_zero
elsif a_zero >= 1
    puts 0
else
    puts -1
end

n = gets.chomp.to_i
a = gets.chomp.split

a_zero = a.count "0"
a_five = a.count "5"

if a_five >= 9
  puts "5" * (a_five / 9) + "0" * a_zero
elsif a_zero >= 1
    puts 0
else
    puts -1
end

n = gets.chomp.to_i
a = gets.chomp.split

a_zero = a.count "0"
a_five = a.count "5"

s = ""
divideds = []
(0...a_five).each do |i|
  s_zero = (s + "0")
  s_five = (s + "5")
  if s_zero.to_i % 90 == 0 and
     s_zero.count("0") <= a_zero and
     s_five.count("5") <= a_five then
    divideds << s_zero
  end
  if s_five.to_i % 90 == 0 and
     s_zero.count("0") <= a_zero and
     s_five.count("5") <= a_five then
    divideds << s_five
  end
  s += "5"
end

ans = divideds.sort[-1]
if ans
  puts ans
else
  puts -1
end

cnt=[0]*6
a = $<.to_a[1].split.map(&:to_i)
a.each do |x|
  cnt[x] += 1
end
if cnt[5] >= 9
  puts '5' * (cnt[5] - cnt[5] % 9) + '0' * cnt[0]
elsif cnt[0] > 0
  puts '0'
else
  puts '-1'
end

cnt=[0]*6
a = $<.to_a[1].split.map(&:to_i)
a.each do |x|
  cnt[x] += 1
end
if cnt[5] >= 9
  puts '5' * (cnt[5] - cnt[5] % 9) + '0' * cnt[0]
elsif cnt[0]
  puts '0'
else
  puts '-1'
end

n = gets.to_i
a = gets.split(' ').map{|e| e.to_i}
c = Hash.new(0)
a.each{|e|
    c[e] += 1;
}

if c[5]/9 > 0 and c[0] > 0 then
    c[5]/9.times{
        print 5
    }
    puts 0
else
    puts 0
end

n = gets.to_i
a = gets.split(' ').map{|e| e.to_i}
c = Hash.new(0)
a.each{|e|
    c[e] += 1;
}

if c[5]/9 > 0 and c[0] > 0 then
    c[5]/9.times{
        print 5
    }
    puts 0
else
    puts -1
end

n = gets.to_i
a = gets.split(' ').map{|e| e.to_i}
c = Hash.new(0)
a.each{|e|
    c[e] += 1;
}

if c[5]/9 > 0 and c[0] > 0 then
    c[5]/9.times{
        print 5
    }
    puts 0
elsif c[0] > 0
    puts 0
else
    puts -1
end

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

c0 = a.count 0
c5 = a.count 5

if c0 == 0 and c5 < 9
	puts -1
elsif c5 < 9
	puts 0
else
	puts '5' * (c5 / 9 * 9) + '0' * c0
end


This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution.Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of n computers, some of them are connected by a cable. The computers are indexed by integers from 1 to n. It's known that any two computers connected by cable directly or through other computersPolycarpus decided to find out the network's topology. A network topology is the way of describing the network configuration, the scheme that shows the location and the connections of network devices.Polycarpus knows three main network topologies: bus, ring and star. A bus is the topology that represents a shared cable with all computers connected with it. In the ring topology the cable connects each computer only with two other ones. A star is the topology where all computers of a network are connected to the single central node.Let's represent each of these network topologies as a connected non-directed graph. A bus is a connected graph that is the only path, that is, the graph where all nodes are connected with two other ones except for some two nodes that are the beginning and the end of the path. A ring is a connected graph, where all nodes are connected with two other ones. A star is a connected graph, where a single central node is singled out and connected with all other nodes. For clarifications, see the picture.    (1) — bus, (2) — ring, (3) — star You've got a connected non-directed graph that characterizes the computer network in Polycarpus' corporation. Help him find out, which topology type the given network is. If that is impossible to do, say that the network's topology is unknown.

The first line contains two space-separated integers n and m (4 ≤ n ≤ 105; 3 ≤ m ≤ 105) — the number of nodes and edges in the graph, correspondingly. Next m lines contain the description of the graph's edges. The i-th line contains a space-separated pair of integers xi, yi (1 ≤ xi, yi ≤ n) — the numbers of nodes that are connected by the i-the edge. It is guaranteed that the given graph is connected. There is at most one edge between any two nodes. No edge connects a node with itself.

In a single line print the network topology name of the given graph. If the answer is the bus, print "bus topology" (without the quotes), if the answer is the ring, print "ring topology" (without the quotes), if the answer is the star, print "star topology" (without the quotes). If no answer fits, print "unknown topology" (without the quotes).

bus topology
ring topology
star topology
unknown topology

class List
  attr_accessor :element, :next_elem

  def initialize(element, next_elem)
    @element = element
    @next_elem = next_elem
  end
end

class Graph
  attr_accessor :vertices

  def initialize(vertices)
    @vertices = vertices
  end

  def add_edge(number1, number2)
    if vertices[number1].nil? then
      vertices[number1] = List.new(number2, nil)
    else
      vertices[number1] = List.new(number2, vertices[number1])
    end
  end

  def print_edges
    vertices.each_with_index do |vertex, index|
      # next if vertex == ""
      while !vertex.nil? do
        puts "edge #{index} - #{vertex.element}"
        vertex = vertex.next_elem
      end
    end
  end

end

network = Graph.new([])
n, m = gets.strip.split(" ").map(&:to_i)
number_of_connected_vertices = Array.new(n, 0)
m.times do
  vertex1, vertex2 = gets.strip.split(" ").map{|num| num.to_i - 1}
  network.add_edge(vertex1, vertex2)
  network.add_edge(vertex2, vertex1)
  number_of_connected_vertices[vertex2] += 1
  number_of_connected_vertices[vertex1] += 1
end
results = number_of_connected_vertices.group_by{|i| i}
if results[n - 1] && results[n - 1].count == 1 &&
   results[1] && results[1].count == n - 1
   answer = 'star topology'
elsif results[1] && results[1].count == 2 &&
  results[2] && results[2].count == n - 2
  answer = 'bus topology'
elsif results[2] &&  results[2].count == n
  answer = 'ring topology'
else
  answer = 'unknown topology'
end
puts answer

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

edges = m.times.map{ gets.split.map(&:to_i) }
v = n.times.map{ 0 }

if m == n
  edges.each do |e|
    v[e[0] - 1] += 1
    v[e[1] - 1] += 1
    if v[e[1] - 1] > 2 || v[e[0] - 1] >2
      puts 'unknown topology'
      exit
    end
  end
  puts 'ring topology'
  exit
elsif m + 1 == n
  edges.each do |e|
    v[e[0] - 1] += 1
    v[e[1] - 1] += 1
  end
  v.sort!
  if v[0] == 1 && v[1] == 1 && v[2] == 2
    puts 'bus topology'
    exit
  elsif v[-1] == m
    puts 'star topology'
    exit
  end
end

puts 'unknown topology'

begin
  input = gets.chomp.split(" ")
  n = input[0].to_i
  m = input[1].to_i

  v1s = []
  v2s = []

  count_arr = []

  edges = []

  twos = 0
  nontwos = 0

  m.times do |i|
    input = gets.chomp.split(" ")

    v1 = input[0].to_i
    v2 = input[1].to_i

    v1s << v1
    v2s << v2

    count_arr[v1] ||= 0
    count_arr[v2] ||= 0

    count_arr[v1] += 1
    count_arr[v2] += 1

    if count_arr[v1] == m || count_arr[v2] == m
      puts "star topology"
      abort
    end
    edges << i
  end

  count_arr.compact!

  count_arr.each do |el|
    if el == 2
      twos += 1
    else
      if el > 2
        puts "unknown topology"
        abort
      else
        nontwos += 1
      end
    end
  end

  if (twos == count_arr.size - 2) && (nontwos == 2)
    puts "bus topology"
    abort
  end

  if n == m
    puts "ring topology"
    abort
  end

  puts "unknown topology"
rescue Exception
end

at_exit do
  vertex_count, edge_count = get_numbers_from_line[0..1]
  linked_count = [0]*vertex_count
  edge_count.times do
    x,y = get_numbers_from_line[0..1]
    linked_count[x-1] += 1
    linked_count[y-1] += 1
  end

  counts = {}
  linked_count.each do |count|
    counts[count] ||= 0
    counts[count] += 1
  end
  one_count = counts[1] || 0
  two_count = counts[2] || 0

  if one_count == 2 && two_count == vertex_count - 2 && edge_count == vertex_count-1
    puts 'bus topology'
  elsif one_count == 0 && two_count == vertex_count && edge_count == vertex_count
    puts 'ring topology'
  elsif one_count == vertex_count-1 && counts[vertex_count-1] == 1 && edge_count == vertex_count - 1
    puts 'star topology'
  else
    puts 'unknown topology'
  end

end

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


The zombies are gathering in their secret lair! Heidi will strike hard to destroy them once and for all. But there is a little problem... Before she can strike, she needs to know where the lair is. And the intel she has is not very good.Heidi knows that the lair can be represented as a rectangle on a lattice, with sides parallel to the axes. Each vertex of the polygon occupies an integer point on the lattice. For each cell of the lattice, Heidi can check the level of Zombie Contamination. This level is an integer between 0 and 4, equal to the number of corners of the cell that are inside or on the border of the rectangle.As a test, Heidi wants to check that her Zombie Contamination level checker works. Given the output of the checker, Heidi wants to know whether it could have been produced by a single non-zero area rectangular-shaped lair (with axis-parallel sides).

The first line of each test case contains one integer N, the size of the lattice grid (5 ≤ N ≤ 50). The next N lines each contain N characters, describing the level of Zombie Contamination of each cell in the lattice. Every character of every line is a digit between 0 and 4. Cells are given in the same order as they are shown in the picture above: rows go in the decreasing value of y coordinate, and in one row cells go in the order of increasing x coordinate. This means that the first row corresponds to cells with coordinates (1, N), ..., (N, N) and the last row corresponds to cells with coordinates (1, 1), ..., (N, 1).

The first line of the output should contain Yes if there exists a single non-zero area rectangular lair with corners on the grid for which checking the levels of Zombie Contamination gives the results given in the input, and No otherwise.

NoteThe lair, if it exists, has to be rectangular (that is, have corners at some grid points with coordinates (x1, y1), (x1, y2), (x2, y1), (x2, y2)), has a non-zero area and be contained inside of the grid (that is, 0 ≤ x1 < x2 ≤ N, 0 ≤ y1 < y2 ≤ N), and result in the levels of Zombie Contamination as reported in the input.

left = nil
top = nil
right = nil
bot = nil

lat = gets.to_i.times.map { gets.chomp.split('').map(&:to_i) }

lat.each_with_index { |line, i|
  break if left
  line.each_with_index { |cell, j|
    if cell == 4
      left = j
      top = i
      break
    end
  }
}

lat.each_with_index.reverse_each { |line, i|
  break if right
  line.each_with_index.reverse_each { |cell, j|
    if cell == 4
      right = j
      bot = i
      break
    end
  }
}

ex = -> {
  puts 'No'
  exit
}

ex.() if !left

lat.each_with_index { |line, i|
  line.each_with_index { |cell, j|
    if j < left-1 || j > right+1 || i < top-1 || i > bot+1
      ex.() if cell != 0
    else
      corn = 0
      corn += 1 if j == left-1 || j == right+1
      corn += 1 if i == top-1 || i == bot+1

      if corn == 0
        ex.() if cell != 4
      elsif corn == 1
        ex.() if cell != 2
      elsif corn == 2
        ex.() if cell != 1
      end
    end
  }
}

puts 'Yes'


Your favorite shop sells $$$n$$$ Kinder Surprise chocolate eggs. You know that exactly $$$s$$$ stickers and exactly $$$t$$$ toys are placed in $$$n$$$ eggs in total.Each Kinder Surprise can be one of three types:  it can contain a single sticker and no toy;  it can contain a single toy and no sticker;  it can contain both a single sticker and a single toy. But you don't know which type a particular Kinder Surprise has. All eggs look identical and indistinguishable from each other.What is the minimum number of Kinder Surprise Eggs you have to buy to be sure that, whichever types they are, you'll obtain at least one sticker and at least one toy?Note that you do not open the eggs in the purchasing process, that is, you just buy some number of eggs. It's guaranteed that the answer always exists.

The first line contains the single integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of queries. Next $$$T$$$ lines contain three integers $$$n$$$, $$$s$$$ and $$$t$$$ each ($$$1 \le n \le 10^9$$$, $$$1 \le s, t \le n$$$, $$$s + t \ge n$$$) — the number of eggs, stickers and toys. All queries are independent.

Print $$$T$$$ integers (one number per query) — the minimum number of Kinder Surprise Eggs you have to buy to be sure that, whichever types they are, you'll obtain at least one sticker and one toy

NoteIn the first query, we have to take at least $$$6$$$ eggs because there are $$$5$$$ eggs with only toy inside and, in the worst case, we'll buy all of them.In the second query, all eggs have both a sticker and a toy inside, that's why it's enough to buy only one egg.In the third query, we have to buy both eggs: one with a sticker and one with a toy.

T = gets.to_i
T.times do
  n,s,t = gets.split.map(&:to_i)
  a = s+t-n
  t = [s-a,t-a].sort
  p t[1]+1
end

T = gets.to_i
T.times do
	n, s, t = gets.split.map(&:to_i)
	s, t = t, s if s < t
	if s + t <= n
		puts s + 1
	elsif
		cross = s + t - n
		puts s + 1 - cross
	end
end

gets.to_i.times {
  n, s, t = gets.split.map &:to_i
  p [n - s + 1, n - t + 1].max
}

T = gets.to_i
T.times do
  n,s,t = gets.split.map(&:to_i)
  a = s+t-n
  t = [a,s-a,t-a].sort
  ans = t[0]+t[1]+1
  p [ans,n].min
end


Winters are just damn freezing cold in Nvodsk! That's why a group of n friends prefers to take a taxi, order a pizza and call girls. The phone numbers in the city consist of three pairs of digits (for example, 12-34-56). Each friend has a phonebook of size si (that's the number of phone numbers). We know that taxi numbers consist of six identical digits (for example, 22-22-22), the numbers of pizza deliveries should necessarily be decreasing sequences of six different digits (for example, 98-73-21), all other numbers are the girls' numbers.You are given your friends' phone books. Calculate which friend is best to go to when you are interested in each of those things (who has maximal number of phone numbers of each type). If the phone book of one person contains some number two times, you should count it twice. That is, each number should be taken into consideration the number of times it occurs in the phone book.

The first line contains an integer n (1 ≤ n ≤ 100) — the number of friends.  Then follow n data blocks that describe each friend's phone books. Each block is presented in the following form: first goes the line that contains integer si and string namei (0 ≤ si ≤ 100) — the number of phone numbers in the phone book of the i-th friend and the name of the i-th friend. The name is a non-empty sequence of uppercase and lowercase Latin letters, containing no more than 20 characters. Next si lines contain numbers as "XX-XX-XX", where X is arbitrary digits from 0 to 9.

In the first line print the phrase "If you want to call a taxi, you should call: ". Then print names of all friends whose phone books contain maximal number of taxi phone numbers.  In the second line print the phrase "If you want to order a pizza, you should call: ". Then print names of all friends who have maximal number of pizza phone numbers.  In the third line print the phrase "If you want to go to a cafe with a wonderful girl, you should call: ". Then print names of all friends who have maximal number of girls' phone numbers.  Print the names in the order in which they are given in the input data. Separate two consecutive names with a comma and a space. Each line should end with exactly one point. For clarifications concerning the output form, see sample tests. It is necessary that you follow the output form strictly. Extra spaces are not allowed.

If you want to call a taxi, you should call: Rogulenko.
If you want to order a pizza, you should call: Fedorov, Rogulenko, Kaluzhin.
If you want to go to a cafe with a wonderful girl, you should call: Melnikov.

If you want to call a taxi, you should call: Gleb.
If you want to order a pizza, you should call: Gleb, Serega.
If you want to go to a cafe with a wonderful girl, you should call: Melnik.

If you want to call a taxi, you should call: Pachocki.
If you want to order a pizza, you should call: Kulczynski, Pachocki.
If you want to go to a cafe with a wonderful girl, you should call: Kulczynski.

NoteIn the first sample you are given four friends. Fedorov's phone book contains one taxi number and one pizza delivery number, Melnikov's phone book only has 3 numbers of girls, Rogulenko's one has 6 taxi numbers and one pizza delivery number, Kaluzhin's one contains 2 taxi numbers and one pizza delivery number.Thus, if you need to order a taxi, you should obviously call Rogulenko, if you need to order a pizza you should call anybody of the following: Rogulenko, Fedorov, Kaluzhin (each of them has one number). Melnikov has maximal number of phone numbers of girls.

n = gets.to_i
a = []
Array.new(n) do
    m, w = gets.split
    b = [0, 0, 0, w]
    m.to_i.times do
        s = gets.gsub(/\D/, '')
        if s =~ /^(.)\1*$/
            b[0] += 1
        elsif s.chars.to_a.sort.uniq * '' == s.reverse
            b[1] += 1
        else
            b[2] += 1
        end
    end
    a << b
end
b = ['call a taxi', 'order a pizza', 'go to a cafe with a wonderful girl']

3.times do |i|
    c = a.map{|_| _[i]}.max
    d = a.select{|_| _[i] == c}.map{|_| _[3]}
    puts "If you want to #{b[i]}, you should call: #{d * ', '}."
end

n=gets.to_i
shop=[]
taxi=[]
max=[0,0,0]
10.times{|k|
        taxi.push(k.to_s*6)
}
n.times{
        res=[0,0,0]
        k,name=gets.split
        k.to_i.times{
                a1,a2,a3=gets.split[0].split('-')
                t=a1+a2+a3
                if taxi.include?(t)
                        res[0]+=1
                else
                        v=Array.new(6){0}
                        6.times{|i| v[i]=t[i].to_i }
                        ok=true
                        5.times{|i|
                                ok=false if v[i]<=v[i+1]
                        }
                        if ok
                                res[1]+=1
                        else
                                res[2]+=1
                        end
                end
        }
        3.times{|i|
                max[i]=[max[i],res[i]].max
        }
        shop.push([name,res])
}
output=["If you want to call a taxi, you should call: ", "If you want to order a pizza, you should call: ","If you want to go to a cafe with a wonderful girl, you should call: "]
3.times{|k|
        print output[k]
        start=true
        shop.each{|t|
                if (t[1][k]==max[k]) then
                        print ", " unless start
                        start=false
                        print t[0]
                end
        }
        puts "."
}

#! /usr/bin/env ruby

t = gets.chomp.to_i
d = {}
name_list = []
(1..t).each do |x|
  n, name = gets.chomp.split
  n = n.to_i
  d[name] = {}
  name_list << name
  d[name]['taxi'] = 0
  d[name]['pizza'] = 0
  d[name]['girl'] = 0
  (1..n).each do |y|
    num = gets.chomp.split("-")
    if num.uniq.size == 1 and num.uniq.first.split(//).uniq.size == 1
      d[name]['taxi'] = (d[name]['taxi'] || 0) + 1
    elsif num.join.split(//).map(&:to_i) == num.join.split(//).map(&:to_i).sort.reverse.uniq
      d[name]['pizza'] = (d[name]['pizza'] || 0) + 1
    else
      d[name]['girl'] = (d[name]['girl'] || 0) + 1
    end
  end
end
max_taxi = d.keys.map { |i| [d[i]['taxi'] || 0, i] }.sort.max.first
max_pizza = d.keys.map { |i| [d[i]['pizza'] || 0, i] }.sort.max.first
max_girl = d.keys.map { |i| [d[i]['girl'] || 0, i] }.sort.max.first
taxi = name_list.select {|i| d[i]['taxi'] == max_taxi }.join(", ") + "."
pizza = name_list.select {|i| d[i]['pizza'] == max_pizza }.join(", ") + "."
girl = name_list.select {|i| d[i]['girl'] == max_girl }.join(", ") + "."
print ("If you want to call a taxi, you should call: " + taxi +"\n").to_s
print ("If you want to order a pizza, you should call: " + pizza +"\n").to_s
print ("If you want to go to a cafe with a wonderful girl, you should call: " + girl +"\n").to_s

#! /usr/bin/env ruby

def type_of_phone_number(number)
  return :taxi if number.uniq.size.equal? 1
  return :pizza if number.each_cons(2).all? {|x, y| x > y}
  return :girl
end

d = {}
k = [:taxi, :pizza, :girl]
k.each {|x| d[x] = [0, []]}

gets.to_i.times do |x|
  n, name = gets.chomp.split
  numbers = n.to_i.times.map {type_of_phone_number(gets.scan(/[0-9]/).map(&:to_i))}
  k.each do |x|
    if numbers.count(x) > d[x].first
      d[x] = [numbers.count(x), [name]]
    elsif numbers.count(x) == d[x].first
      d[x].last << name
    end
  end
end

puts "If you want to call a taxi, you should call: %s." %(d[:taxi][1] * ", ")
puts "If you want to order a pizza, you should call: %s." %(d[:pizza][1] * ", ")
puts "If you want to go to a cafe with a wonderful girl, you should call: %s." %(d[:girl][1] * ", ")

#! /usr/bin/env ruby

t = gets.chomp.to_i
d = {}
name_list = []
(1..t).each do |x|
  n, name = gets.chomp.split
  n = n.to_i
  d[name] = {}
  name_list << name
  d[name]['taxi'], d[name]['pizza'], d[name]['girl'] = 0, 0, 0
  (1..n).each do |y|
    num = gets.chomp.split("-")
    if num.uniq.size == 1 and num.uniq.first.split(//).uniq.size == 1
      d[name]['taxi'] = d[name]['taxi'] + 1
    elsif num.join.split(//).map(&:to_i) == num.join.split(//).map(&:to_i).sort.reverse.uniq
      d[name]['pizza'] = d[name]['pizza'] + 1
    else
      d[name]['girl'] = d[name]['girl'] + 1
    end
  end
end

max_taxi = d.keys.map { |i| [d[i]['taxi'], i] }.sort.max.first
max_pizza = d.keys.map { |i| [d[i]['pizza'], i] }.sort.max.first
max_girl = d.keys.map { |i| [d[i]['girl'], i] }.sort.max.first

taxi = name_list.select {|i| d[i]['taxi'] == max_taxi }.join(", ") + "."
pizza = name_list.select {|i| d[i]['pizza'] == max_pizza }.join(", ") + "."
girl = name_list.select {|i| d[i]['girl'] == max_girl }.join(", ") + "."

print ("If you want to call a taxi, you should call: " + taxi +"\n").to_s
print ("If you want to order a pizza, you should call: " + pizza +"\n").to_s
print ("If you want to go to a cafe with a wonderful girl, you should call: " + girl +"\n").to_s

require 'set'

def is_taxi(s)
  tmp = s.split("").select{|c| c != '-'}
  set = Set.new tmp
  set.length == 1
end

def is_pizza(s)
  flag = true
  tmp = nil
  s.split("").each do |c|
    if c != '-'
      if tmp == nil
        tmp = c.to_i
      else
        if tmp <= c.to_i
          flag = false
          break
        else
          tmp = c.to_i
        end
      end
    end
  end
  flag
end

def max_names(hash)
  max = hash.values.max
  names = hash.select{ |k, v|
    v == max
  }
  names.keys.join ', '
end

n = gets.chomp.to_i

taxi = {}
pizza = {}
girl = {}

n.times do
  tmp = gets.chomp.split " "
  s = tmp[0].to_i
  name = tmp[1]

  taxi[name] = 0
  pizza[name] = 0
  girl[name] = 0

  s.times do
    tmp2 = gets.chomp
    if is_taxi(tmp2)
      taxi[name] += 1
    elsif is_pizza(tmp2)
      pizza[name] += 1
    else
      girl[name] += 1
    end
  end
end

puts "If you want to call a taxi, you should call: " + max_names(taxi) + "."
puts "If you want to order a pizza, you should call: " + max_names(pizza) + "."
puts "If you want to go to a cafe with a wonderful girl, you should call: " + max_names(girl) + "."

def pizza?(num)
  num = num.gsub(/-/,'').chars.map(&:to_i)
  prev = 10
  num.each do |n|
    if prev > n
      prev = n
    else
      return false
    end
  end
  true
end

def taxi?(num)
  a = num[0]
  num.gsub(/[#{a}\-]/,'').size.zero?
end

def girl?(num)
  !taxi?(num) && !pizza?(num)
end

def which(num)
  return :taxi if taxi?(num)
  return :pizza if pizza?(num)
  return :girl
end

dics = {}
n = STDIN.gets.chomp.to_i
n.times do
  i, name = STDIN.gets.chomp.split(/ /)
  i = i.to_i
  dics[name] = {taxi: 0, pizza: 0, girl: 0}

  i.times do
    num = STDIN.gets.chomp
    dics[name][which(num)] += 1
  end
end

{taxi: "If you want to call a taxi, you should call: ",
 pizza: "If you want to order a pizza, you should call: ",
 girl: "If you want to go to a cafe with a wonderful girl, you should call: "}.each do |type, head|
  max = dics.map{|k,v| v[type] }.max
  puts head+dics.select{|k,v| v[type] == max }.keys.join(", ")+"."
end

name,taxi,girls,pizza,maxt,maxp,maxg=[],[],[],[],0,0,0
n=gets.to_i
n.times do |i|
	taxi[i],pizza[i],girls[i]=0,0,0
	t,name[i]=gets.chomp.split
	t=t.to_i
	t.times do |j|
		str=gets.chomp.delete('-').split('')
		if str.uniq.count==1
			taxi[i]+=1
		elsif str[0]>str[1] && str[1]>str[2] && str[2]>str[3] && str[3]>str[4] && str[4]>str[5]
			pizza[i]+=1
		else
			girls[i]+=1
		end
	end
end
maxt,maxg,maxp=taxi.max,girls.max,pizza.max
print "If you want to call a taxi, you should call: "
post=0
for i in 0...n
	if maxt==taxi[i]
		post+=1
		print (post==1) ? name[i] : ", #{name[i]}"
	end
end
puts "."
print "If you want to order a pizza, you should call: "
post=0
for i in 0...n
	if maxp==pizza[i]
		post+=1
		print (post==1) ? name[i] : ", #{name[i]}"
	end
end
puts "."
print "If you want to go to a cafe with a wonderful girl, you should call: "
post=0
for i in 0...n
	if maxg==girls[i]
		post+=1
		print (post==1) ? name[i] : ", #{name[i]}"
	end
end
puts "."

n = gets.to_i
pb = []
n.times do |i|
  a  = [i]
  c,nm = gets.split
  a << nm
  h = Hash.new(0)
  c.to_i.times do
    pn = gets.strip.gsub(/-/,"").split(//)
    pn.uniq.sort.reverse
    if pn.uniq.size == 1
      h[:t] += 1
    elsif pn.uniq.sort.reverse == pn
      h[:p] += 1
    else
      h[:g] += 1
    end
  end
  a << h
  pb << a
end

mx = pb.map{|a| a[2][:t]}.max
tx = pb.select{|a| a[2][:t] == mx }

mx = pb.map{|a| a[2][:p]}.max
pz = pb.select{|a| a[2][:p] == mx }

mx = pb.map{|a| a[2][:g]}.max
gf = pb.select{|a| a[2][:g] == mx }

puts "If you want to call a taxi, you should call: #{tx.map{|a| a[1]}.join(", ")}."
puts "If you want to order a pizza, you should call: #{pz.map{|a| a[1]}.join(", ")}."
puts "If you want to go to a cafe with a wonderful girl, you should call: #{gf.map{|a| a[1]}.join(", ")}."

#!/usr/bin/ruby
class Number
  def initialize
  @mas=Array.new(6)
  end
  def mas
    @mas
  end
  def mas=(mas)
    @mas=mas
  end
  def isPizza()
    return @mas==@mas.uniq() && @mas==@mas.sort{|a,b| b<=>a}
  end
  def isTaxi()
     return @mas.uniq().size()==1
  end
end
class Person
  def initialize
  @name=String.new
  @taxiElements=0
  @girlElements=0
  @pizzaElements=0
  @numberArray=[]
  end
  def taxiElements
    @taxiElements
  end
  def pizzaElements
    @pizzaElements
  end
  def girlElements
    @girlElements
  end
  def name
    @name
  end
  def name=(name)
    @name=name
  end
  def numberArray
    @numberArray
  end
  def numberArray=(numberArray)
    @numberArray=numberArray
  end
  def countElements()
    for i in 0..(@numberArray.size()-1)
      element=@numberArray[i]
     if element.isTaxi()
    @taxiElements=@taxiElements+1
     elsif (element.isPizza())
    @pizzaElements=@pizzaElements+1
     else
    @girlElements=@girlElements+1
      end
    end
  end
end

require 'scanf'
count=(scanf("%d\n"))[0]
array=Array.new(count)
for i in 0..(count-1)
  array[i]=Person.new
  temp=scanf("%d %s\n")
  elements=temp[0]
  array[i].name=temp[1]
  array[i].numberArray=Array.new(elements)
  for j in 0..(elements-1)
    array[i].numberArray[j]=Number.new
    array[i].numberArray[j].mas=scanf("%c%c-%c%c-%c%c\n")
  end

end

array.each do |i|
  i.countElements()
end
maxPizza=(array.map{|x|x.pizzaElements}).max
maxTaxi=(array.map{|x|x.taxiElements}).max
maxGirl=(array.map{|x|x.girlElements}).max
outTaxi="If you want to call a taxi, you should call: "
outPizza="If you want to order a pizza, you should call: "
outGirl="If you want to go to a cafe with a wonderful girl, you should call: "
wasTaxi=false
wasPizza=false
wasGirl=false
array.each do |i|
  if i.taxiElements==maxTaxi
    if wasTaxi
      outTaxi+=", "
    end
    wasTaxi=true
    outTaxi+=i.name
  end
  if i.pizzaElements==maxPizza
    if wasPizza
      outPizza+=", "
    end
    wasPizza=true
    outPizza+=i.name
  end
  if i.girlElements==maxGirl
    if wasGirl
      outGirl+=", "
    end
    wasGirl=true
    outGirl+=i.name
  end
end
outTaxi+="."
outPizza+="."
outGirl+="."
puts outTaxi
puts outPizza
puts outGirl

n = gets.to_i
CON = [:taxi,:pizza,:girl]
friends = []
names = []
n.times do
	m,name = gets.chomp.split(" ")
	names << name
	m = m.to_i
	nos = Hash.new(0)
	m.times do
		ans = nil
		x,y,z = gets.chomp.split("-")
		a,b,c = x.to_i,y.to_i,z.to_i
		arr = [x.split(''),y.split(''),z.split('')].flatten

		# puts "#{one} #{two} #{three} #{four} #{five} #{six}"
		# puts "#{b} #{c}"
		# puts "#{(one.to_i > two.to_i) && (three.to_i > four.to_i) && (five.to_i > six.to_i)}"
		if a == b && b == c && arr.each_cons(2).all?{|l,m| l == m}
			ans = CON[0]
		elsif a > b && b > c && arr.each_cons(2).all?{|l,m| l > m}
			ans = CON[1]
		else
			ans = CON[2]
		end
		nos[ans] += 1
	end
	friends << nos
end
taxi = []
pizza = []
girl = []
# puts "#{friends}"
friends.each_with_index do |f,i|
	taxi[i] = f[CON[0]]
	pizza[i] = f[CON[1]]
	girl[i] = f[CON[2]]
end

list = []
max = taxi.max
taxi.each_with_index do |t,i|
	list << names[i] if t == max
end

puts "If you want to call a taxi, you should call: #{list.join(', ')}."

list = []
max = pizza.max
pizza.each_with_index do |t,i|
	list << names[i] if t == max
end

puts "If you want to order a pizza, you should call: #{list.join(', ')}."

list = []
max = girl.max
girl.each_with_index do |t,i|
	list << names[i] if t == max
end

puts "If you want to go to a cafe with a wonderful girl, you should call: #{list.join(', ')}."

#

def is_taxi(number)
  prev_char = ''
  taxi = true
  number.each_char do |char|
    taxi = false if (prev_char != '' && char != prev_char)
    prev_char = char
  end
  taxi
end

def is_pizza(number)
  prev_char = ''
  pizza = true
  number.each_char do |char|
    pizza = false if (prev_char != '' && char.to_i >= prev_char)
    prev_char = char.to_i
  end
  pizza
end

friends_count = gets.to_i

names = []
pizza_n = []
taxi_n = []
girl_n = []

pizza_max = 0
taxi_max = 0
girl_max = 0

friends_count.times do
  numbers_count, name = gets.split(' ')
  names << name
  taxi_count = 0
  pizza_count = 0
  numbers_count.to_i.times do
    number = gets.gsub('-', '').chomp
    prev_char = ''
    taxi_count += 1 if is_taxi number
    pizza_count += 1 if is_pizza number
  end
  girl_count = numbers_count.to_i - taxi_count - pizza_count

  girl_n << name if girl_count == girl_max
  girl_n = [name] if girl_count > girl_max
  girl_max = girl_count if girl_count >= girl_max

  taxi_n << name if taxi_count == taxi_max
  taxi_n = [name] if taxi_count > taxi_max
  taxi_max = taxi_count if taxi_count >= taxi_max

  pizza_n << name if pizza_count == pizza_max
  pizza_n = [name] if pizza_count > pizza_max
  pizza_max = pizza_count if pizza_count >= pizza_max
end

puts "If you want to call a taxi, you should call: " + taxi_n.join(', ') + "."
puts "If you want to order a pizza, you should call: " + pizza_n.join(', ') + "."
puts "If you want to go to a cafe with a wonderful girl, you should call: " + girl_n.join(', ') + "."

class Array
  def uniq?
    self.uniq.size == 1
  end

  def desc?
    (1...self.size).each { |i|
      return false if self[i] >= self[i - 1]
    }
    true
  end
end

people = {}

(0...gets.to_i).each {
  numbers_count, name = gets.chomp.split
  people[name] = Array.new(3, 0)
  (0...numbers_count.to_i).each {
    phone_digits = gets.chomp.gsub(/-/, '').split('').map(&:to_i)
    people[name][phone_digits.uniq? ? 0 : phone_digits.desc? ? 1 : 2] += 1
  }
}

['call a taxi', 'order a pizza', 'go to a cafe with a wonderful girl'].each_with_index { |action, index|
  max = people.values.map { |a| a[index] }.max
  printf "If you want to %s, you should call: %s.\n", action, people.select { |_, a| a[index] == max }.keys.join(', ')
}

t = STDIN.gets.to_i

ar = []

def taxi?(phone)
  !!(phone =~ /(.)\1-\1\1-\1\1/)
end

def pizza?(phone)
  phone.scan(/\d/).map(&:to_i).each_cons(2) {|a,b| return false if a <= b }
  return true
end

maxt, maxp, maxg = 0, 0, 0

t.times do
  n, name = STDIN.gets.chomp.split
  ntaxi, npizza, ngirl = 0, 0, 0

  n.to_i.times do

    phone = STDIN.gets.chomp

    if taxi?(phone)
      ntaxi += 1
    elsif pizza?(phone)
      npizza += 1
    else
      ngirl += 1
    end
  end

  ar << [name, ntaxi, npizza, ngirl]
  maxt = ntaxi if maxt < ntaxi
  maxp = npizza if maxp < npizza
  maxg = ngirl if maxg < ngirl

end

msg1 = "If you want to call a taxi, you should call: "
msg2 = "If you want to order a pizza, you should call: "
msg3 = "If you want to go to a cafe with a wonderful girl, you should call: "

ta = []
pa = []
ga = []

ar.each do |el|
  ta << el[0] if maxt == el[1]
  pa << el[0] if maxp == el[2]
  ga << el[0] if maxg == el[3]
end

puts msg1 << ta.join(", ") << "."
puts msg2 << pa.join(", ") << "."
puts msg3 << ga.join(", ") << "."

person = []
gets.to_i.times{ |i|
 a, b = gets.split
 person[i] = [b, 0, 0, 0]
 a.to_i.times{
  d = gets.gsub(/[^\d]/, "").split("").map(&:to_i)
  same, dec = true, true
  d.each_with_index{ |x,j|
   same = false if x != d[0]
   dec = false if j > 0 && x >= d[j-1]
  }
  if same
   person[i][1] += 1
  elsif dec
   person[i][2] += 1
  else
   person[i][3] += 1
  end
 }
}

mx = (1..3).map{ |i| person.max_by{ |e| e[i] }[i] }
["call a taxi" ,"order a pizza", "go to a cafe with a wonderful girl"].each_with_index{ |s,i|
 puts "If you want to " + s + ", you should call: " +
 person.select{ |e| e[i+1] == mx[i] }.map{ |e| e[0] }*", " + "."
}

def which_phone_no(numbers)
	return :taxi if numbers.uniq.size==1
	return :pizza if numbers.each_cons(2).all?{|a,b|a>b}
	return :girl
end
call={}
k=[:taxi,:pizza,:girl]
k.each{|_k|call[_k]=[0,[]]}
gets.to_i.times{
	s,name=gets.split
	books=s.to_i.times.map{which_phone_no(gets.scan(/[0-9]/).map(&:to_i))}
	k.each{|_k|
		m=books.count(_k)
		if m>call[_k][0]
			call[_k][0]=m
			call[_k][1]=[name]
		elsif call[_k][0]==m
			call[_k][1]<<name
		end
	}
}
puts "If you want to call a taxi, you should call: %s."%(call[:taxi][1]*", ")
puts "If you want to order a pizza, you should call: %s."%(call[:pizza][1]*", ")
puts "If you want to go to a cafe with a wonderful girl, you should call: %s."%(call[:girl][1]*", ")

res = {:taxi => Hash.new(0), :pizza => Hash.new(0), :girl => Hash.new(0)}
sum = {:taxi => [], :pizza => [], :girl => []}
names = []

class String
	def which?
		n = self.gsub('-', '')
		n = n.split('').map &:to_i
		if    n.count == n.count(n[0])
			'taxi'
		elsif       n == n.uniq.sort.reverse
			'pizza'
		else
			'girl'
		end
	end
end

gets; while g = gets
	g = g.chop.split
	n = g[0].to_i
	names.push g[1].to_sym
	n.times do
		num = gets.chop!
		res[num.which?.to_sym][g[1].to_sym] += 1
	end
end

res.each do |key, hash|
	max = hash.values.max
	hash.each { |k, v| sum[key].push(k) if v == max }
end

{
	:taxi => 'call a',
	:pizza => 'order a',
	:girl => 'go to a cafe with a wonderful'
}.each do |k, v|
	print "If you want to #{v} #{k}, you should call: "
	print sum[k].empty? ? names.join(', ') : sum[k].join(', ')
	puts "."
end

#! /usr/bin/env ruby

t = gets.chomp.to_i
d = {}
name_list = []
(1..t).each do |x|
  n, name = gets.chomp.split
  n = n.to_i
  d[name] = {}
  name_list << name
  (1..n).each do |y|
    num = gets.chomp.split("-")
    if num.uniq.size == 1 and num.uniq.first.split(//).uniq.size == 1
      d[name]['taxi'] = (d[name]['taxi'] || 0) + 1
    elsif num.join.split(//).map(&:to_i) == num.join.split(//).map(&:to_i).sort.reverse.uniq
      d[name]['pizza'] = (d[name]['pizza'] || 0) + 1
    else
      d[name]['girl'] = (d[name]['girl'] || 0) + 1
    end
  end
end
max_taxi = d.keys.map { |i| [d[i]['taxi'] || 0, i] }.sort.max.first
max_pizza = d.keys.map { |i| [d[i]['pizza'] || 0, i] }.sort.max.first
max_girl = d.keys.map { |i| [d[i]['girl'] || 0, i] }.sort.max.first
taxi = name_list.select {|i| d[i]['taxi'] == max_taxi }.join(", ") + "."
pizza = name_list.select {|i| d[i]['pizza'] == max_pizza }.join(", ") + "."
girl = name_list.select {|i| d[i]['girl'] == max_girl }.join(", ") + "."
print ("If you want to call a taxi, you should call: " + taxi +"\n").to_s
print ("If you want to order a pizza, you should call: " + pizza +"\n").to_s
print ("If you want to go to a cafe with a wonderful girl, you should call: " + girl +"\n").to_s

#! /usr/bin/env ruby

def type_of_phone_number(number)
  return :taxi if number.uniq.size.equal? 1
  return :pizza if number.each_cons(2).all? {|x, y| x > y}
  return :girl
end

d = {}
k = [:taxi, :pizza, :girl]
k.each {|x| d[x] = [0, []]}

gets.to_i.times do |x|
  n, name = gets.chomp.split
  numbers = n.to_i.times.map {type_of_phone_number(gets.scan(/[0-9]/).map(&:to_i))}
  k.each do |x|
    d[x] = [numbers.count(x), [name]] if numbers.count(x) > d[x].first
    d[x].last << name if numbers.count(x) > d[x].first
  end
end

puts "If you want to call a taxi, you should call: %s." %(d[:taxi][1] * ", ")
puts "If you want to order a pizza, you should call: %s." %(d[:pizza][1] * ", ")
puts "If you want to go to a cafe with a wonderful girl, you should call: %s." %(d[:girl][1] * ", ")

#! /usr/bin/env ruby

def type_of_phone_number(number)
  return :taxi if number.uniq.size.equal? 1
  return :pizza if number.each_cons(2).all? {|x, y| x > y}
  return :girl
end

d = {}
k = [:taxi, :pizza, :girl]
k.each {|x| d[x] = [0, []]}

gets.to_i.times do |x|
  n, name = gets.chomp.split
  numbers = n.to_i.times.map {type_of_phone_number(gets.scan(/[0-9]/).map(&:to_i))}
  k.each do |x|
    d[x] = [numbers.count(x), [name]] if numbers.count(x) > d[x].first
    d[x].last << name if numbers.count(x) > d[x].first
  end
end

p "If you want to call a taxi, you should call: %s." %(d[:taxi][1] * ", ")
p "If you want to order a pizza, you should call: %s." %(d[:pizza][1] * ", ")
p "If you want to go to a cafe with a wonderful girl, you should call: %s." %(d[:girl][1] * ", ")

#! /usr/bin/env ruby

t = gets.chomp.to_i
d = {}
name_list = []
(1..t).each do |x|
  n, name = gets.chomp.split
  n = n.to_i
  d[name] = {}
  name_list << name
  (1..n).each do |y|
    num = gets.chomp.split("-")
    if num.uniq.size == 1 and num.uniq.first.split(//).uniq.size == 1
      d[name]['taxi'] = (d[name]['taxi'] || 0) + 1
    elsif num.join.split(//).map(&:to_i) == num.join.split(//).map(&:to_i).sort.reverse.uniq
      d[name]['pizza'] = (d[name]['pizza'] || 0) + 1
    else
      d[name]['girl'] = (d[name]['girl'] || 0) + 1
    end
  end
end
max_taxi = d.keys.map { |i| [d[i]['taxi'] || 0, i] }.sort.max.first
max_pizza = d.keys.map { |i| [d[i]['pizza'] || 0, i] }.sort.max.first
max_girl = d.keys.map { |i| [d[i]['girl'] || 0, i] }.sort.max.first
taxi = name_list.select {|i| d[i]['taxi'] == max_taxi }.join(", ") + "."
pizza = name_list.select {|i| d[i]['pizza'] == max_pizza }.join(", ") + "."
girl = name_list.select {|i| d[i]['girl'] == max_girl }.join(", ") + "."
p ("If you want to call a taxi, you should call: " + taxi).to_s.strip
p "If you want to order a pizza, you should call: " + pizza
p "If you want to go to a cafe with a wonderful girl, you should call: " + girl

require 'set'

def is_taxi(s)
  tmp = s.split "-"
  set = Set.new tmp
  if set.length == 1
    true
  else
    false
  end
end

def is_pizza(s)
  flag = true
  tmp = nil
  s.split("").each do |c|
    if c != '-'
      if tmp == nil
        tmp = c.to_i
      else
        if tmp <= c.to_i
          flag = false
          break
        else
          tmp = c.to_i
        end
      end
    end
  end
  flag
end

def max_names(hash)
  max = hash.values.max
  names = hash.select{ |k, v|
    v == max
  }
  names.keys.join ', '
end

n = gets.chomp.to_i

taxi = {}
pizza = {}
girl = {}

n.times do
  tmp = gets.chomp.split " "
  s = tmp[0].to_i
  name = tmp[1]

  taxi[name] = 0
  pizza[name] = 0
  girl[name] = 0

  s.times do
    tmp2 = gets.chomp
    if is_taxi(tmp2)
      taxi[name] += 1
    elsif is_pizza(tmp2)
      pizza[name] += 1
    else
      girl[name] += 1
    end
  end
end

puts "If you want to call a taxi, you should call: " + max_names(taxi) + "."
puts "If you want to order a pizza, you should call: " + max_names(pizza) + "."
puts "If you want to go to a cafe with a wonderful girl, you should call: " + max_names(girl) + "."

def pizza?(num)
  num = num.gsub(/-/,'').chars.map(&:to_i)
  prev = 10
  num.each do |n|
    if prev > n
      prev = n
    else
      return false
    end
  end
  true
end

def taxi?(num)
  a = num[0]
  num.gsub(/[#{a}\-]/,'').size.zero?
end

def girl?(num)
  !taxi?(num) && !pizza?(num)
end

def which(num)
  return :taxi if taxi?(num)
  return :pizza if pizza?(num)
  return :girl
end

dics = {}
n = STDIN.gets.chomp.to_i
n.times do
  i, name = STDIN.gets.chomp.split(/ /)
  i = i.to_i
  dics[name] = {taxi: 0, pizza: 0, girl: 0}
  already = []

  i.times do
    num = STDIN.gets.chomp
    next if already.include?(num)
    already << num
    dics[name][which(num)] += 1
  end
end

{taxi: "If you want to call a taxi, you should call: ",
 pizza: "If you want to order a pizza, you should call: ",
 girl: "If you want to go to a cafe with a wonderful girl, you should call: "}.each do |type, head|
  max = dics.map{|k,v| v[type] }.max
  puts head+dics.select{|k,v| v[type] == max }.keys.join(", ")+"."
end

def pizza?(num)
  num = num.gsub(/-/,'').chars.map(&:to_i)
  prev = 10
  num.each do |n|
    if prev > n
      prev = n
    else
      return false
    end
  end
  true
end

def taxi?(num)
  a = num[0]
  num.gsub(/[#{a}\-]/,'').size.zero?
end

def girl?(num)
  !taxi?(num) && !pizza?(num)
end

def which(num)
  return :taxi if taxi?(num)
  return :pizza if pizza?(num)
  return :girl
end

dics = {}
n = STDIN.gets.chomp.to_i
n.times do
  i, name = STDIN.gets.chomp.split(/ /)
  i = i.to_i
  dics[name] = {taxi: 0, pizza: 0, girl: 0}
  already = []

  i.times do
    num = STDIN.gets.chomp
    next if already.include?(num)
    already << num
    dics[name][which(num)] += 1
  end
end

{taxi: "If you want to call a taxi, you should call: ",
 pizza: "If you want to order a pizza, you should call: ",
 girl: "If you want to go to a cafe with a wonderful girl, you should call: "}.each do |type, head|
  max = dics.max{|(k,v)| v[type] }[1][type]
  puts head+dics.select{|k,v| v[type] == max }.keys.join(", ")+"."
end

def pizza?(num)
  num = num.gsub(/-/,'').chars.map(&:to_i)
  prev = 10
  num.each do |n|
    if prev > n
      prev = n
    else
      return false
    end
  end
  true
end

def taxi?(num)
  a = num[0]
  num.gsub(/[#{a}\-]/,'').size.zero?
end

def girl?(num)
  !taxi?(num) && !pizza?(num)
end

def which(num)
  return :taxi if taxi?(num)
  return :pizza if pizza?(num)
  return :girl
end

dics = {}
n = STDIN.gets.chomp.to_i
n.times do
  i, name = STDIN.gets.chomp.split(/ /)
  i = i.to_i
  dics[name] = {taxi: 0, pizza: 0, girl: 0}
  already = []

  i.times do
    num = STDIN.gets.chomp
    next if already.include?(num)
    already << num
    dics[name][which(num)] += 1
  end
end

{taxi: "If you want to call a taxi, you should call: ",
 pizza: "If you want to order a pizza, you should call: ",
 girl: "If you want to go to a cafe with a wonderful girl, you should call: "}.each do |type, head|
  max = dics.max{|(k,v)| v[type] }[1][type]
  puts head+dics.select{|k,v| v[type] == max }.keys.join(", ")
end

n = gets.to_i
pb = []
n.times do |i|
  a  = [i]
  c,nm = gets.split
  a << nm
  h = Hash.new(0)
  c.to_i.times do
    pn = gets.strip.gsub(/-/,"").split(//)
    pn.uniq.sort.reverse
    if pn.uniq.size == 1
      h[:t] += 1
    elsif pn.uniq.sort.reverse == pn
      h[:p] += 1
    else
      h[:g] += 1
    end
  end
  a << h
  pb << a
end

mx = pb.map{|a| a[2][:t]}.max
tx = pb.select{|a| a[2][:t] == mx }

mx = pb.map{|a| a[2][:p]}.max
pz = pb.select{|a| a[2][:p] == mx }

mx = pb.map{|a| a[2][:g]}.max
gf = pb.select{|a| a[2][:g] == mx }

puts "If  want to order a pizza, you should call: #{tx.map{|a| a[1]}.join(", ")}."
puts "If you want to call a taxi, you should call: #{pz.map{|a| a[1]}.join(", ")}."
puts "If you want to go to a cafe with a wonderful girl, you should call: #{gf.map{|a| a[1]}.join(", ")}."

#!/usr/bin/ruby
class Number
  def initialize
  @mas=Array.new(6)
  end
  def mas
    @mas
  end
  def mas=(mas)
    @mas=mas
  end
  def isPizza()
    return @mas==@mas.uniq() && @mas==@mas.sort{|a,b| b<=>a}
  end
  def isTaxi()
     return @mas.uniq().size()==1
  end
end
class Person
  def initialize
  @name=""
  @taxiElements=0
  @girlElements=0
  @pizzaElements=0
  @numberArray=[]
  end
  def taxiElements
    @taxiElements
  end
  def pizzaElements
    @pizzaElements
  end
  def girlElements
    @girlElements
  end
  def name
    @name
  end
  def name=(name)
    @name=name
  end
  def numberArray
    @numberArray
  end
  def numberArray=(numberArray)
    @numberArray=numberArray
  end
  def countElements()
    for i in 0..(@numberArray.size()-1)
      element=@numberArray[i]
     if element.isTaxi()
	@taxiElements=@taxiElements+1
     elsif (element.isPizza())
	@pizzaElements=@pizzaElements+1
     else
	@girlElements=@girlElements+1
      end
    end
  end
end

require 'scanf'
count=(scanf("%d"))[0]
array=Array.new(count)
for i in 0..(count-1)
  array[i]=Person.new
  temp=scanf("%d %s")
  elements=temp[0]
  array[i].name=temp[1]
  array[i].numberArray=Array.new(elements)
  for j in 0..(elements-1)
    array[i].numberArray[j]=Number.new
    array[i].numberArray[j].mas=scanf("%c%c-%c%c-%c%c")
  end

end

array.each do |i|
  i.countElements()
end
maxPizza=(array.map{|x|x.pizzaElements}).max
maxTaxi=(array.map{|x|x.taxiElements}).max
maxGirl=(array.map{|x|x.girlElements}).max
outTaxi="If you want to call a taxi, you should call: "
outPizza="If you want to order a pizza, you should call: "
outGirl="If you want to go to a cafe with a wonderful girl, you should call: "
wasTaxi=false
wasPizza=false
wasGirl=false
array.each do |i|
  if i.taxiElements==maxTaxi
    if wasTaxi
      outTaxi+=", "
    end
    wasTaxi=true
    outTaxi+=i.name
  end
  if i.pizzaElements==maxPizza
    if wasPizza
      outPizza+=", "
    end
    wasPizza=true
    outPizza+=i.name
  end
  if i.girlElements==maxGirl
    if wasGirl
      outGirl+=", "
    end
    wasGirl=true
    outGirl+=i.name
  end
end
outTaxi+="."
outPizza+="."
outGirl+="."
if wasTaxi
  puts outTaxi
end
if wasPizza
  puts outPizza
end
if wasGirl
  puts outGirl
end

#!/usr/bin/ruby
class Number
  def initialize
  @mas=Array.new(6)
  end
  def mas
    @mas
  end
  def mas=(mas)
    @mas=mas
  end
  def isPizza()
    return @mas==@mas.uniq() && @mas==@mas.sort{|a,b| b<=>a}
  end
  def isTaxi()
     return @mas.uniq().size()==1
  end
end
class Person
  def initialize
  @name=String.new
  @taxiElements=0
  @girlElements=0
  @pizzaElements=0
  @numberArray=[]
  end
  def taxiElements
    @taxiElements
  end
  def pizzaElements
    @pizzaElements
  end
  def girlElements
    @girlElements
  end
  def name
    @name
  end
  def name=(name)
    @name=name
  end
  def numberArray
    @numberArray
  end
  def numberArray=(numberArray)
    @numberArray=numberArray
  end
  def countElements()
    for i in 0..(@numberArray.size()-1)
      element=@numberArray[i]
     if element.isTaxi()
    @taxiElements=@taxiElements+1
     elsif (element.isPizza())
    @pizzaElements=@pizzaElements+1
     else
    @girlElements=@girlElements+1
      end
    end
  end
end

require 'scanf'
count=(scanf("%d\n"))[0]
array=Array.new(count)
for i in 0..(count-1)
  array[i]=Person.new
  temp=scanf("%d %s\n")
  puts  temp
  elements=temp[0]
  array[i].name=temp[1]
  array[i].numberArray=Array.new(elements)
  for j in 0..(elements-1)
    array[i].numberArray[j]=Number.new
    array[i].numberArray[j].mas=scanf("%c%c-%c%c-%c%c\n")
  end

end

array.each do |i|
  i.countElements()
end
maxPizza=(array.map{|x|x.pizzaElements}).max
maxTaxi=(array.map{|x|x.taxiElements}).max
maxGirl=(array.map{|x|x.girlElements}).max
outTaxi="If you want to call a taxi, you should call: "
outPizza="If you want to order a pizza, you should call: "
outGirl="If you want to go to a cafe with a wonderful girl, you should call: "
wasTaxi=false
wasPizza=false
wasGirl=false
array.each do |i|
  if i.taxiElements==maxTaxi
    if wasTaxi
      outTaxi+=", "
    end
    wasTaxi=true
    outTaxi+=i.name
  end
  if i.pizzaElements==maxPizza
    if wasPizza
      outPizza+=", "
    end
    wasPizza=true
    outPizza+=i.name
  end
  if i.girlElements==maxGirl
    if wasGirl
      outGirl+=", "
    end
    wasGirl=true
    outGirl+=i.name
  end
end
outTaxi+="."
outPizza+="."
outGirl+="."
puts outTaxi
puts outPizza
puts outGirl

#!/usr/bin/ruby
class Number
  def initialize
  @mas=Array.new(6)
  end
  def mas
    @mas
  end
  def mas=(mas)
    @mas=mas
  end
  def isPizza()
    return @mas==@mas.uniq() && @mas==@mas.sort{|a,b| b<=>a}
  end
  def isTaxi()
     return @mas.uniq().size()==1
  end
end
class Person
  def initialize
  @name=""
  @taxiElements=0
  @girlElements=0
  @pizzaElements=0
  @numberArray=[]
  end
  def taxiElements
    @taxiElements
  end
  def pizzaElements
    @pizzaElements
  end
  def girlElements
    @girlElements
  end
  def name
    @name
  end
  def name=(name)
    @name=name
  end
  def numberArray
    @numberArray
  end
  def numberArray=(numberArray)
    @numberArray=numberArray
  end
  def countElements()
    for i in 0..(@numberArray.size()-1)
      element=@numberArray[i]
     if element.isTaxi()
	@taxiElements=@taxiElements+1
     elsif (element.isPizza())
	@pizzaElements=@pizzaElements+1
     else
	@girlElements=@girlElements+1
      end
    end
  end
end

require 'scanf'
count=(scanf("%d"))[0]
array=Array.new(count)
for i in 0..(count-1)
  array[i]=Person.new
  temp=scanf("%d %s")
  elements=temp[0]
  array[i].name=temp[1]
  array[i].numberArray=Array.new(elements)
  for j in 0..(elements-1)
    array[i].numberArray[j]=Number.new
    array[i].numberArray[j].mas=scanf("%c%c-%c%c-%c%c")
  end

end

array.each do |i|
  i.countElements()
end
maxPizza=(array.map{|x|x.pizzaElements}).max
maxTaxi=(array.map{|x|x.taxiElements}).max
maxGirl=(array.map{|x|x.girlElements}).max
outTaxi="If you want to call a taxi, you should call: "
outPizza="If you want to order a pizza, you should call: "
outGirl="If you want to go to a cafe with a wonderful girl, you should call: "
wasTaxi=false
wasPizza=false
wasGirl=false
array.each do |i|
  if i.taxiElements==maxTaxi
    if wasTaxi
      outTaxi+=", "
    end
    wasTaxi=true
    outTaxi+=i.name
  end
  if i.pizzaElements==maxPizza
    if wasPizza
      outPizza+=", "
    end
    wasPizza=true
    outPizza+=i.name
  end
  if i.girlElements==maxGirl
    if wasGirl
      outGirl+=", "
    end
    wasGirl=true
    outGirl+=i.name
  end
end
outTaxi+="."
outPizza+="."
outGirl+="."
puts outTaxi
puts outPizza
puts outGirl

n = gets.to_i
CON = [:taxi,:pizza,:girl]
friends = []
names = []
n.times do
	m,name = gets.chomp.split(" ")
	names << name
	m = m.to_i
	nos = Hash.new(0)
	m.times do
		ans = nil
		x,y,z = gets.chomp.split("-")
		a,b,c = x.to_i,y.to_i,z.to_i
		arr = [x.split(''),y.split(''),z.split('')].flatten

		# puts "#{one} #{two} #{three} #{four} #{five} #{six}"
		# puts "#{b} #{c}"
		# puts "#{(one.to_i > two.to_i) && (three.to_i > four.to_i) && (five.to_i > six.to_i)}"
		if a == b && b == c && arr.each_cons(2).all?{|l,m| l == m}
			ans = CON[0]
		elsif a > b && b > c && arr.each_cons(2).all?{|l,m| l > m}
			ans = CON[1]
		else
			ans = CON[2]
		end
		nos[ans] += 1
	end
	friends << nos
end
taxi = []
pizza = []
girl = []
puts "#{friends}"
friends.each_with_index do |f,i|
	taxi[i] = f[CON[0]]
	pizza[i] = f[CON[1]]
	girl[i] = f[CON[2]]
end

list = []
max = taxi.max
taxi.each_with_index do |t,i|
	list << names[i] if t == max
end

puts "If you want to call a taxi, you should call: #{list.join(', ')}."

list = []
max = pizza.max
pizza.each_with_index do |t,i|
	list << names[i] if t == max
end

puts "If you want to order a pizza, you should call: #{list.join(', ')}."

list = []
max = girl.max
girl.each_with_index do |t,i|
	list << names[i] if t == max
end

puts "If you want to go to a cafe with a wonderful girl, you should call: #{list.join(', ')}."

n = gets.to_i
CON = [:taxi,:pizza,:girl]
friends = []
names = []
n.times do
	m,name = gets.chomp.split(" ")
	names << name
	m = m.to_i
	nos = Hash.new(0)
	m.times do
		ans = nil
		x,y,z = gets.chomp.split("-")
		a,b,c = x.to_i,y.to_i,z.to_i
		one,two = x.split('')
		three,four = y.split('')
		five,six = z.split('')
		# puts "#{one} #{two} #{three} #{four} #{five} #{six}"
		# puts "#{b} #{c}"
		# puts "#{(one.to_i > two.to_i) && (three.to_i > four.to_i) && (five.to_i > six.to_i)}"
		if a == b && b == c
			ans = CON[0]
		elsif a > b && b > c && (one.to_i > two.to_i) && (three.to_i > four.to_i) && (five.to_i > six.to_i)
			ans = CON[1]
		else
			ans = CON[2]
		end
		nos[ans] += 1
	end
	friends << nos
end
taxi = []
pizza = []
girl = []

friends.each_with_index do |f,i|
	taxi[i] = f[CON[0]]
	pizza[i] = f[CON[1]]
	girl[i] = f[CON[2]]
end

list = []
max = taxi.max
taxi.each_with_index do |t,i|
	list << names[i] if t == max
end

puts "If you want to call a taxi, you should call: #{list.join(', ')}."

list = []
max = pizza.max
pizza.each_with_index do |t,i|
	list << names[i] if t == max
end

puts "If you want to order a pizza, you should call: #{list.join(', ')}."

list = []
max = girl.max
girl.each_with_index do |t,i|
	list << names[i] if t == max
end

puts "If you want to go to a cafe with a wonderful girl, you should call: #{list.join(', ')}."

n = gets.to_i
CON = [:taxi,:pizza,:girl]
friends = []
names = []
n.times do
	m,name = gets.chomp.split(" ")
	names << name
	m = m.to_i
	nos = Hash.new(0)
	m.times do
		ans = nil
		x,y,z = gets.chomp.split("-")
		a,b,c = x.to_i,y.to_i,z.to_i
		arr = [x.split(''),y.split(''),z.split('')].flatten

		# puts "#{one} #{two} #{three} #{four} #{five} #{six}"
		# puts "#{b} #{c}"
		# puts "#{(one.to_i > two.to_i) && (three.to_i > four.to_i) && (five.to_i > six.to_i)}"
		if a == b && b == c
			ans = CON[0]
		elsif a > b && b > c && arr.each_cons(2).all?{|l,m| l > m}
			ans = CON[1]
		else
			ans = CON[2]
		end
		nos[ans] += 1
	end
	friends << nos
end
taxi = []
pizza = []
girl = []
# puts "#{friends}"
friends.each_with_index do |f,i|
	taxi[i] = f[CON[0]]
	pizza[i] = f[CON[1]]
	girl[i] = f[CON[2]]
end

list = []
max = taxi.max
taxi.each_with_index do |t,i|
	list << names[i] if t == max
end

puts "If you want to call a taxi, you should call: #{list.join(', ')}."

list = []
max = pizza.max
pizza.each_with_index do |t,i|
	list << names[i] if t == max
end

puts "If you want to order a pizza, you should call: #{list.join(', ')}."

list = []
max = girl.max
girl.each_with_index do |t,i|
	list << names[i] if t == max
end

puts "If you want to go to a cafe with a wonderful girl, you should call: #{list.join(', ')}."

person = []
gets.to_i.times{ |i|
 a, b = gets.split
 person[i] = [b, 0, 0, 0]
 a.to_i.times{
  d = gets.gsub(/[^\d]/, "").split("").map(&:to_i)
  same, dec = true, true
  d.each_with_index{ |x,j|
   same = false if x != d[0]
   dec = false if j > 0 && x >= d[j-1]
  }
  if same
   person[i][1] += 1
  elsif dec
   person[i][2] += 1
  else
   person[i][3] += 1
  end
 }
}

mx = (1..3).map{ |i| person.max_by{ |e| e[i] }[i] }
["taxi" ,"pizza", "cafe with a wonderful girl"].each_with_index{ |s,i|
 puts "If you want to call a " + s + ", you should call: " +
 person.select{ |e| e[i+1] == mx[i] }.map{ |e| e[0] }*", " + "."
}

res = {:taxi => Hash.new(0), :pizza => Hash.new(0), :girl => Hash.new(0)}
sum = {:taxi => [], :pizza => [], :girl => []}

class String
	def which?
		n = self.gsub('-', '')
		n = n.split('').map &:to_i
		if    n.count == n.count(n[0])
			'taxi'
		elsif       n == n.uniq.sort.reverse
			'pizza'
		else
			'girl'
		end
	end
end

gets; while g = gets
	g = g.chop.split
	g[0].to_i.times do |i|
		num = gets.chop!
		res[num.which?.to_sym][g[1].to_sym] += 1
	end
end

res.each do |key, hash|
	max = hash.values.max
	hash.each { |k, v| sum[key].push(k) if v == max }
end

{
	:taxi => 'call a',
	:pizza => 'order a',
	:girl => 'go to a cafe with a wonderful'
}.each do |k, v|
	print "If you want to #{v} #{k}, you should call: "
	print sum[k].join(', ')
	puts "."
end


A number $$$a_2$$$ is said to be the arithmetic mean of two numbers $$$a_1$$$ and $$$a_3$$$, if the following condition holds: $$$a_1 + a_3 = 2\cdot a_2$$$. We define an arithmetic mean deviation of three numbers $$$a_1$$$, $$$a_2$$$ and $$$a_3$$$ as follows: $$$d(a_1, a_2, a_3) = |a_1 + a_3 - 2 \cdot a_2|$$$.Arithmetic means a lot to Jeevan. He has three numbers $$$a_1$$$, $$$a_2$$$ and $$$a_3$$$ and he wants to minimize the arithmetic mean deviation $$$d(a_1, a_2, a_3)$$$. To do so, he can perform the following operation any number of times (possibly zero):  Choose $$$i, j$$$ from $$$\{1, 2, 3\}$$$ such that $$$i \ne j$$$ and increment $$$a_i$$$ by $$$1$$$ and decrement $$$a_j$$$ by $$$1$$$ Help Jeevan find out the minimum value of $$$d(a_1, a_2, a_3)$$$ that can be obtained after applying the operation any number of times.

The first line contains a single integer $$$t$$$ $$$(1 \le t \le 5000)$$$  — the number of test cases. The first and only line of each test case contains three integers $$$a_1$$$, $$$a_2$$$ and $$$a_3$$$ $$$(1 \le a_1, a_2, a_3 \le 10^{8})$$$.

For each test case, output the minimum value of $$$d(a_1, a_2, a_3)$$$ that can be obtained after applying the operation any number of times.

NoteNote that after applying a few operations, the values of $$$a_1$$$, $$$a_2$$$ and $$$a_3$$$ may become negative.In the first test case, $$$4$$$ is already the Arithmetic Mean of $$$3$$$ and $$$5$$$.$$$d(3, 4, 5) = |3 + 5 - 2 \cdot 4| = 0$$$In the second test case, we can apply the following operation:$$$(2, 2, 6)$$$ $$$\xrightarrow[\text{increment $$$a_2$$$}]{\text{decrement $$$a_1$$$}}$$$ $$$(1, 3, 6)$$$$$$d(1, 3, 6) = |1 + 6 - 2 \cdot 3| = 1$$$It can be proven that answer can not be improved any further.In the third test case, we can apply the following operations:$$$(1, 6, 5)$$$ $$$\xrightarrow[\text{increment $$$a_3$$$}]{\text{decrement $$$a_2$$$}}$$$ $$$(1, 5, 6)$$$ $$$\xrightarrow[\text{increment $$$a_1$$$}]{\text{decrement $$$a_2$$$}}$$$ $$$(2, 4, 6)$$$$$$d(2, 4, 6) = |2 + 6 - 2 \cdot 4| = 0$$$

gets.to_i.times do

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

puts (a + b + c) % 3 == 0 ? 0 : 1

end

gets.to_i.times do

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

puts ((a + b + c) % 3).abs

end