n=gets
s=gets.chomp

arr=[]
"a".upto("z"){|e|
	arr<<e
}
c1=0
s.chars{|e|
	if arr.index(e) then
		arr.delete(e)
	else
		c1+=1
	end
}
if c1<=arr.size then
	puts c1
else
	puts -1
end

#!/usr/bin/ruby
n=gets.to_i
h={}
gets.chomp.chars{|c|h[c]=1}
p n>26 ? -1 : n-h.size

# http://codeforces.com/contest/672/problem/B
n = gets.chomp.to_i
chars = gets.chomp.chars

if n > 26
  puts "-1"
else
  puts n - chars.uniq.length
end

n = readline.to_i
str = readline.strip.each_char.to_a
n = str.length
m = str.uniq.length
if n > 26
  puts -1
else
  puts n - m
end

n=gets.chomp.to_i
a=gets.chomp.split("")
if n>26
puts"-1"
else
n=n-a.uniq.length
puts"#{n}"
end

n = gets.chomp.to_i
s = gets.chomp.split ""
rep = 0
store = Array.new(255, 0)
s.each do |c|
    store[c.ord] += 1
    rep += store[c.ord] if store[c.ord] == 1
end
if n > 26
    puts "-1"
else
    puts n - rep
end

a = Hash.new(0)
n = gets.chomp.to_i
s = gets.chomp
for i in 0..n-1
	a[s[i]]+=1
end
sum = 0
for i in'a'..'z'
	sum += a[i]-1 if a[i]>1
end
if n > 26
	puts "-1"
else
	puts sum
end

# coding: utf-8

n = gets.to_i
s = gets.chomp
counter = {}
subcnt = 0
for c in s.split(//)
  counter[c] ||= 0
  counter[c] += 1

  if counter[c] > 1
    subcnt += 1
  end
end

if 26 - (subcnt + counter.length) >= 0
  puts subcnt
else
  puts -1
end

n = gets.to_i
puts n <= 26 ? n - gets.chomp.chars.uniq.size : -1

input = gets.chomp.to_i
str = gets.chomp
flag = {}
dupCount = 0
blank = 0

if str.length > 26
	puts '-1'
	exit
end

str.each_char do |c|
	if flag.has_key? c
		flag[c] += 1
	else
		flag[c] = 1
	end
end

for c in ('a'..'z') do
	blank += 1 if !flag.has_key?(c)
end

flag.each do |k, v|
	dupCount += (v - 1) if v > 1
end

ans = 0

#puts "Dup : #{dupCount}"
#puts "Blank #{blank}"

until dupCount == 0 || blank == 0
	blank -= 1
	dupCount -= 1
	ans += 1
end

puts ans

gets

s = gets.chomp

let = Hash.new
let.default = 0

if s.length > 26
  print -1
  exit
end

res = 0

s.length.times { |num|
  ch = s[num]
  if let[ch] == 0
    let[ch] = 1
  else
    let[ch] += 1
    res += 1
  end
}

puts res

# qwertyuiopasdfghjklzxcvbnm
# mmmmmmmmmmmmmmmmmmmmmmmmmm

# coding: utf-8

n = gets.to_i
s = gets.chomp
counter = {}
subcnt = 0
for c in s.split(//)
  counter[c] ||= 0
  counter[c] += 1

  if counter[c] > 1
    subcnt += 1
  end
end

puts subcnt

n = gets.to_i
puts n - gets.chomp.chars.uniq.size

input = gets.chomp.to_i
str = gets.chomp
flag = {}
dupCount = 0
blank = 0

if str.length > 26
	puts '-1'
	exit
end

str.each_char do |c|
	if flag.has_key? c
		flag[c] += 1
	else
		flag[c] = 1
	end
end

for c in ('a'..'z') do
	blank += 1 if !flag.has_key?(c)
end

flag.each do |k, v|
	dupCount += 1 if v > 1
end

ans = 0

until dupCount == 0 || blank == 0
	blank -= 1
	dupCount -= 1
	ans += 1
end

puts ans


n,v=gets.split.map(&:to_i)
a=1.step(n).select{|i|
gets.split.map(&:to_i)[1..-1].any?{|e|e<v}
}
p a.size
puts a*' '

n,v = gets.chomp.split.map(&:to_i)
q=[]
n.times do |i|
	a=gets.chomp.split.map(&:to_i)
	k=a.shift
	for x in a
		if v>x
			q.push(i+1)
			break
		end
	end
end
puts q.count
if (!q.empty?)
	for i in q
		print i.to_s+' '
	end
end
puts

n, v = gets.chomp.split(/ /).map(&:to_i)
sellers = []
n.times do
    line = gets.chomp.split(/ /).map(&:to_i)
    prices = line[1...line.length]
    sellers << prices
end
deal = []
sellers.each_index do |seller|
    prices = sellers[seller]
    prices.each do |price|
        if price < v
            deal << seller + 1
            break
        end
    end
end
deal.sort!
puts deal.length
puts deal.join(" ")

n,v=gets.split.map{|e| e.to_i}
ans=[]
n.times{|i|
	x=gets.split.map{|e| e.to_i}
	x.shift
	if x.min<v then
		ans<<(i+1)
	end
}
puts ans.size
if ans.size>0 then
	puts ans*" "
end

input = gets.split(" ").map{|el| el.to_i }
sellers = input[0]
money = input[1]
output = []

for i in 1..sellers
  input = []
  input = gets.split(" ").map{|el| el.to_i}
  for j in 1...input.size
    if input[j] < money
      output << i
      break
    end
  end
end

puts output.size
puts output.join(" ")

# coding: utf-8

n, v = gets.split.map(&:to_i)
dealers = []
n.times { |dealer|
    _, *prices = gets.split.map(&:to_i)
    if v > prices.min
        dealers << dealer + 1
    end
}
puts dealers.length
puts dealers.join(' ')

nk = gets.chomp.split.map(&:to_i)
n = nk[0]
k = nk[1]
arr = []
count = 0
a = []
for i in (0..n-1)
	arr << gets.chomp.split.map(&:to_i)
	arr[i].delete_at(0)
	if arr[i].min < k
		count += 1
		a << i+1
	end
end

puts count
for num in a
	print num
	print " "
end

first_line=gets().split(" ")
ans=[]
n=first_line[0].to_i;money=first_line[1].to_i
for i in 0...n
  line=gets().split(" ")
  line.map!{|x| x.to_i}
  for j in 1...line.size
    if line[j]<money
      ans<< i+1
      break
    end
  end
  ans.sort!

end
if ans.size==0
  puts 0
else
  puts ans.size
  puts ans.join(" ")
end

n, v = gets.split.map &:to_i
arr = []
n.times do
  arr << gets.split.map { |x| x.to_i }.to_a
  arr.last.shift
end
count = 0
indices = []
arr.each do |x|
  if x.count { |y| y < v } > 0
    count += 1
    indices << arr.index(x) + 1
  end
end
puts count
indices.each { |x| print x, " " }

n,v = gets.split(" ").map(&:to_i)
sellers = []
(1..n).each do |s|
  sellers << s if gets.split(" ").map(&:to_i)[1..-1].any?{|x| v > x}
end
puts sellers.count
puts sellers.join(" ")

n,v = gets.split.map(&:to_i)
d = (1..n).select { |_|
  items = gets.split.map(&:to_i).drop 1
  items.select { |i| v > i }.size >= 1
}
puts d.size
puts d.join " "

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

n, v = read_next_line
a = []
(1..n).each { |i|
  a << i if read_next_line[1..-1].any? { |x| x < v }
}
puts a.size
puts a * ' '

n,v=gets.split.map{|i| i.to_i}
o=[]
n.times{|i| o<<(i+1) if gets.split.map{|i| i.to_i}[1..51].min<v}
p o.length
puts o.join' '

n, v = gets.split.map &:to_i

sellers_auctions = []
n.times do
  seller_auction = gets.split.map &:to_i
  seller_auction.shift
  sellers_auctions << seller_auction
end

bargainable_sellers = []

sellers_auctions.each_index do |i|
  buyable_items = sellers_auctions[i].select{ |item| item < v }
  bargainable_sellers << (i + 1) unless buyable_items.empty?
end

puts bargainable_sellers.length
puts bargainable_sellers.join(' ')

#!/usr/bin/ruby
n,v=gets.split.map(&:to_i)
a=1.step(n).select{gets.split.map(&:to_i)[1..-1].any?{|e|e<v}}
p a.size
puts a*' '

n,x=gets.split.map &:to_i
str=""
k=0
j=1
p=""
n.times do

  mas=gets.split.map &:to_i
  i=1
  while(i<mas.length)
    if x>mas[i]
      k+=1
      p+=j.to_s+" "
      break
    end
    i+=1
  end
j+=1
end
puts k
puts p

n,v=gets.chomp.split.map(&:to_i)
q=[]
n.times do |i|
	a=gets.chomp.split.map(&:to_i)
	k=a.shift
	for x in a
		if v>x
			q.push(i+1)
			break
		end
	end
end
puts q.count
if (!q.empty?)
	for i in q
		print i.to_s+' '
	end
end
puts

n, v = gets.chomp.split(/ /).map(&:to_i)
sellers = []
n.times do
    line = gets.chomp.split(/ /).map(&:to_i)
    prices = line[1...line.length]
    sellers << prices
end
deal = []
sellers.each_index do |seller|
    prices = sellers[seller]
    prices.each do |price|
        if price < v
            deal << seller + 1
        end
    end
end
deal.sort!
puts deal.length
puts deal.join(" ")

# coding: utf-8

n, v = gets.split.map(&:to_i)
dealers = []
n.times {
    dealer, *prices = gets.split.map(&:to_i)
    prices.each { |i|
        if i < v
            dealers << dealer
            break
        end
    }
}
puts dealers.length
puts dealers.join(' ')

first_line=gets().split(" ")
ans=[]
n=first_line[0].to_i;money=first_line[1].to_i
for i in 0...n
  line=gets().split(" ")
  line.map!{|x| x.to_i}
  for i in 1...line.size
    if line[i]<money
      ans<<line[0]
      break
    end
  end
  ans.sort!

end
if ans.size==0
  puts 0
else
  puts ans.size
  puts ans.join(" ")
end

first_line=gets().split(" ")
ans=[]
n=first_line[0].to_i;money=first_line[1].to_i
for i in 0...n
  line=gets().split(" ")
  line.map!{|x| x.to_i}
  for i in 1...line.size
    if line[i]<money
      ans<<line[0]
      break
    end
  end
  ans.sort!

end
if ans.size==0
  puts 0
else
  puts ans.join(" ")
end

n,v=gets.chomp.split.map(&:to_i)
q=[]
n.times do
	a=gets.chomp.split.map(&:to_i)
	k=a.shift
	for x in a
		if v>x
			q.push(k)
			break
		end
	end
end
puts q.count
if (!q.empty?)
	for i in q
		print i.to_s+' '
	end
end
puts


t = gets.to_i
t.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  l2 = a.max
  l1 = n - l2
  count = 0
  pair = []
  p1 = a.slice(0, l1)
  p2 = a.slice(l1, l2)
  if p1.min == 1 && p1.max == l1 && p2.min == 1 && p2.max == l2
    if p1.uniq.length == l1 && p2.uniq.length == l2
      count += 1
      pair.push([l1, l2])
    end
  end
  if l1 != l2
    p1 = a.slice(0, l2)
    p2 = a.slice(l2, l1)
    if p1.min == 1 && p1.max == l2 && p2.min == 1 && p2.max == l1
      if p1.uniq.length == l2 && p2.uniq.length == l1
        count += 1
        pair.push([l2, l1])
      end
    end
  end
  puts count
  pair.each do |pa|
    puts pa.join(" ")
  end
end

t = gets.to_i
t.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  l2 = a.max
  l1 = n - l2
  count = 0
  pair = []
  p1 = a.slice(0, l1)
  p2 = a.slice(l1, l2)
  if p1.uniq.length == l1 && p2.uniq.length == l2
    count += 1
    pair.push([l1, l2])
  end
  if l1 != l2
    p1 = a.slice(0, l2)
    p2 = a.slice(l2, l1)
    if p1.uniq.length == l2 && p2.uniq.length == l1
      count += 1
      pair.push([l2, l1])
    end
  end
  puts count
  pair.each do |pa|
    puts pa.join(" ")
  end
end

t = gets.to_i
t.times do
  n = gets.to_i
  a = gets.split.map(&:to_i)
  l2 = a.max
  l1 = n - l2
  count = 0
  pair = []
  p1 = a.slice(0, l1)
  p2 = a.slice(l1, l2)
  if p1.uniq.length == l1 && p2.uniq.length == l2
    count += 1
    pair.push([l1, l2])
  end
  p1 = a.slice(0, l2)
  p2 = a.slice(l2, l1)
  if p1.uniq.length == l2 && p2.uniq.length == l1
    count += 1
    pair.push([l2, l1])
  end
  puts count
  pair.each do |pa|
    puts pa.join(" ")
  end
end


#!/usr/bin/ruby

n = gets.chomp.to_i

s1 = "I hate "
s2 = "I love "
s3 = "that "
s4 = "it"

for i in 1..n
    if (i % 2 != 0)
        print s1
    else
        print s2
    end
    if i != n
        print s3
    else
        print s4
    end
end

n=gets.chomp().to_i
s3="I love"
s2=" that "
s1="I hate"
s4="I hate"
s5=" it"
i=2
while i<=n
  if i%2==0
    s1+=s2+s3
  else
    s1+=s2+s4
  end
  i=i+1
end
s1=s1+s5
puts(s1)

#!/usr/bin/ruby
N=gets.to_i
N.times{|i|
	print i%2==0?'I hate ':'I love '
	print i<N-1?'that ':'it'+$/
}

#!usr/bin/env ruby

# https://codeforces.com/problemset/problem/705/A

n = gets.to_i

answer = "I hate "

(n-1).times do |n|
  feeling = n % 2 == 0 ? "love" : "hate"
  answer << "that I #{feeling} "
end

answer << "it"

puts answer

n = gets.to_i - 1

print 'I hate'

k = 1
n.times do
  if k==1
    print ' that I love'
    k = 0
  else
    print ' that I hate'
    k = 1
  end
end
print ' it'

n = gets.chomp.to_i
base = (n.to_f / 2.0).ceil
ans = ["I hate", "I love"].cycle(base).to_a[0...n].join(" that ")
puts "#{ans} it"

n = gets.to_i
puts n.times.map{|i| i.even? ? 'I hate' : 'I love'}.join(' that ') + ' it'

n = gets.to_i()
print "I hate "
for i in (2..n)
  if i % 2 > 0
    print "that I hate "
  else
    print "that I love "
  end
end
puts "it"

hate = "I hate"
love = "I love"

lvl = Integer(STDIN.gets())

prev_emotion = false
emotion = ""

lvl.times { |x|

    if prev_emotion
        emotion += " that "
    else
        prev_emotion = true
    end

    if x.even?
        emotion += hate
    else
        emotion += love
    end
}

emotion += " it"

puts emotion

feel_number = gets.strip.to_i
feels = []

index = 1
feel_number.times do
  if index.odd?
    feels.push('I hate')
  else
    feels.push('I love')
  end
  index += 1
end

output = feels.join(' that ')
output += ' it'
puts output

n = gets.to_i
n.times{ |x|
  print x % 2 == 0 ? "I hate " : "I love "
  print x + 1 == n ? "it " : "that "
}

n = gets.to_i

ps = 'I hate '
p1 = 'that I love '
p2 = 'that I hate '
pe = 'it'
i = 1
while(i < n) do

    if (i % 2 ==1)
        ps += p1
    else
        ps += p2
    end

    i = i + 1
end
ps+=pe
puts ps

number = gets.chomp.to_i

hate = "I hate "
love = "I love "

if number == 1
	print hate
	print "it"
else
	for i in (1..number)
		if i % 2 != 0 # odd = hate
			print hate
			if i != number
				print "that "
			else
				print "it"
			end
		else	# even = love
			print love
			if i != number
				print "that "
			else
				print "it"
			end
		end
	end
end

n = gets.to_i
result = []
(1..n).each_with_index do |index|
	result << (index.even? ? 'I love' : 'I hate')
	result << (index == n ? 'it' : 'that')
end
print result.join(' ')

word = ["I hate", "I love"]
input = gets.chomp!.to_i
puts word.cycle.take(input).join(" that ").concat(' it')

layers = gets.to_i
reduced = 0;
result = ""
until layers == 0
    if reduced == 0
        result = result + "I hate"
    end

    if reduced == 1
        result = result + " that I love"
    end

    if reduced > 1
        if reduced % 2 == 0
            result = result + " that I hate"
        end
        if reduced % 2 > 0
            result = result + " that I love"
        end
    end

    layers = layers - 1
    reduced = reduced + 1
end
result = result + " it"
puts result

s = ""
n = gets.to_i

for i in (1..n-1)
  i%2 == 1 ? s += "I hate that " : s += "I love that "
end

puts s + (n%2 == 0 ? "I love it" : "I hate it")

$n = gets
$n = $n.to_i
print "I "
(1..$n).each do |i|
	if ((i%2 == 0)and(i == $n))
		print "love it"
		break
	end
	if ((i%2 == 1)and(i == $n))
		print "hate it"
		break
	end
	if i%2 == 0
		print "love that I "
	end
	if i%2 == 1
		print "hate that I "
	end
end

class Array
  def r
    self.map { |q| q.to_i }
  end
end

def read_line
  STDIN.gets.split(" ")
end

def read_to_array
  read_line.to_a
end

def read_numbers_to_array
  read_to_array.r
end

n = STDIN.gets.to_i
res = ""
hate = true
for i in 1..n - 1 do
  if hate
    res += "I hate that "
    hate = false
  else
    hate = true
    res += "I love that "
  end
end

if hate
  res += "I hate it"
else
  res += "I love it"
end

puts res

LEVELS = ['I hate', 'I love']

level = gets.to_i

puts LEVELS.cycle.take(level).join(' that ').concat(' it')

n = gets.to_i
ans = 'I hate'
(2..n).each do |i|
  if i.odd?
    ans += ' that I hate'
  else
    ans += ' that I love'
  end
end
puts ans + ' it'

n = gets.chomp.to_i

n.times do |i|
	if (i + 1).even? then
		print "I love"
	else
		print "I hate"
	end
	print i == n - 1 ? " it " : " that "
end
puts

n = gets.strip.to_i
odd_s = "I hate"
even_s = "I love"
s = Array.new(n) { |i| (i + 1).odd? ? odd_s : even_s }
ans = s.join(" that ") + " it"
puts ans

n=gets.to_i
a=["I hate","I love"]
str=""
p1=0
n.times{|i|

	if i==0 then
		str=a[0]
	else
		str=str+" that "+a[p1]
	end
	p1=((p1==1)?0:1)
}
puts str+" it"

t = gets.to_i
for i in 0..t-1
	if i%2 == 0
		print "I hate "
		if i == t-1
			print "it"
		else
			print "that "
		end
	else
		print "I love "
		if i == t-1
			print "it"
		else
			print "that "
		end
	end
end
print "\n"

input = gets.to_i

ans = ["I hate " , "I love "].cycle(input).to_a[0..input-1].join("that ")
puts ans + "it"

input = gets.chomp.to_i
1.upto(input-1){ |i|
	 if i.even?
		print "I love "
	else
		print "I hate "
	end
	print "that "
}
if input.even?
		print "I love it"
else
		print "I hate it"
	end

n = gets.chomp.to_i
s = ""

co = 0
n.times.each do
  if co == 0
    s += 'I hate it'
    co +=1
  elsif co %2 == 0
    s.gsub!('it', 'that I love it')
  else
    s.gsub!('it', 'that I hate it')
  end
  co +=1
end

puts s

input = gets.to_i
input.times {|i|
print i % 2 == 0 ?"I hate" : "I love"
print i == input - 1 ? " it" : " that "
}

n = gets.chomp.to_i
sentence = ""

for i in (1...n+1)
  if i % 2 != 0
    sentence += "I hate"
  else
    sentence += "I love"
  end
  if i != n
    sentence += " that "
  end
end

sentence += " it"
puts sentence

n = gets.to_i
0.upto(n-1) do |i|
	if i != 0
		print 'that '
	end
	if i % 2 == 0
		print 'I hate '
	else
		print 'I love '
	end
end
puts 'it'

# https://codeforces.com/problemset/problem/705/A

n = gets.to_i

feeling = "I hate it"

2.upto(n) do |i|
    if i % 2 == 0
        feeling.gsub!("it", "that I love it")
    else
        feeling.gsub!("it", "that I hate it")
    end
end

puts feeling

n = gets.chomp.to_i

w = ["I hate that", "I love that"]

result = "I hate it"
pos    = 1
if n%2 == 0 then
	result = "I love it"
	pos    = 0
end

1.upto(n-1) do
	result = w[pos] + " " + result
	pos = (pos+1)%2
end

puts result

n = STDIN.gets.to_i
s = ''
n.times do |i|
	s += 'I '+((i%2)==0 ? 'hate' : 'love')+' '+(i==n-1 ? 'it' : 'that ')
end
puts s

input = gets.to_i
feeling1 = "I hate"
feeling2 = "I love"
feeling = ""
if(input == 1)
  feeling = "I hate it"
else
  c = 1
  while(c <= input)
    if(c%2 == 1)
      feeling += feeling1
      if(c!=input)
        feeling += " that "
      end
    else
      feeling += feeling2
      if(c!=input)
        feeling += " that "
      end
    end
    c += 1
  end
  feeling += " it"
end
puts feeling

n=gets.to_i
s=""
n.times do |x|
	s+="I love " if x%2==1
	s+="I hate " if x%2==0
	s+="that " if x!=n-1
	s+="it" if x==n-1
end
puts s

n = gets.chomp.to_i
ans = ''

n.times do |i|
	i += 1

	ans += 'I hate ' if i % 2 == 1
	ans += 'I love ' if i % 2 == 0

	ans += 'that ' if i != n
end

ans += 'it'

puts ans

def love(n)
	phrase = ""
	while n > 0
		phrase << "I hate "
		n = n - 1
		phrase << "that " if n > 0
		phrase << "I love " if n > 0
		n = n - 1
		phrase << "that " if n > 0
	end
	phrase << "it"
	return phrase
end

n = gets.chomp.to_i
puts(love(n))

n=gets.to_i
res=""
n.times {|i|
    res+="that " if res.size>0
    if i.even?
        res+="I hate "
    else
        res+="I love "
    end
}
res+="it"
puts res

n = gets.to_i

pc = 'I hate it'
p1 = 'I love that '
p2 = 'I hate that '
i = 1
while(i < n) do
    i = i + 1;
    if (i % 2 ==1)
        pc = p1 + pc
    else
        pc = p2 + pc
    end
end

puts pc

s = ""
n = gets.to_i

for i in (1..n-1)
  (n-i)%2 == 0 ? s += "I hate that " : s += "I love that "
end

puts s + "I hate it"

s = ""
n = gets.to_i

for i in (1..n-1)
  (n-i)%2 == 1 ? s += "I hate that " : s += "I love that "
end

puts s + (n%2 == 0 ? "I love it" : "I hate it")

LEVELS = ['I hate that I love that I hate it', 'I hate it', 'I hate that I love it']

level = gets.to_i

puts LEVELS[level % 3]

n = gets.chomp.to_i

n.times do |i|
	if (i + 1).even? then
		print "I love it "
	else
		print "I hate that"
	end
end
puts

n = gets.to_i
puts n.times.map{|i| i.even? ? 'I hate it' : 'I love it'}.join(' that ')

input = gets.chomp.to_i
1.upto(input-1){ |i|
	 if i.even?
		print "I Love "
	else
		print "I Hate "
	end
	print "that "
}
if input.even?
		print "I Love it"
else
		print "I Hate it"
	end

n = gets.chomp.to_i
sentence = ""

for i in (1...n+1)
  if i % 2 != 0
    sentence += "I hate"
  else
    sentence += "I love"
  end
  if i != n
    sentence += " that "
  end
end

sentence += " It"
puts sentence

word = ["I hate", "I love"]
input = gets.chomp!.to_i
p word.cycle.take(input).join(" that ").concat(' it')

word = ["I hate", "I love"]
input = gets.chomp!.to_i
p word.cycle.take(input).join(" that ").concat(' it ')

layers = gets.to_i
reduced = 0;
result = ""
until layers == 0
    if reduced == 0
        result = result + "I hate"
    end

    if reduced == 1
        result = result + " that I love"
    end

    if reduced > 1
        if reduced % 2 == 0
            result = result + " that I hate"
        end
        if reduced % 3 == 0
            result = result + " that I love"
        end
    end

    layers = layers - 1
    reduced = reduced + 1
end
result = result + " it"
puts result

layers = gets.to_i
reduced = 0;
result = ""
until layers == 0
    if reduced == 0
        result = result + "I hate it"
    end

    if reduced == 1
        result = result + " that I love it"
    end

    if reduced > 1
        if reduced % 2 == 0
            result = result + " that I hate it"
        end
        if reduced % 3 == 0
            result = result + " that I love it"
        end
    end

    layers = layers - 1
    reduced = reduced + 1
end
puts result

numbers = gets.chomp
start = 1
result = ""
while start <= numbers.to_i
    if start > 1
        result = result + " that "
    end
    if start % 2 == 0
        result = result + "I hate it"
    else
        result = result + "I love it"
    end
    start = start + 1
end
puts result

numbers = gets.chomp
start = 1
result = ""
while start <= numbers.to_i
    if start > 1
        result = result + " that "
        if start % 2 == 0
            result = result + "I hate it"
        else
            result = result + "I love it"
        end
    else
        result = result + "I hate it"
    end
    # if start % 2 == 0 && start > 1
    #     result = result + "I hate it"
    # elsif
    #     result = result + "I love it"
    # end
    start = start + 1
end
puts result

n=gets.to_i
a=["I hate","I love","I hate"]
str=""
n.times{|i|
	if i==0 then
		str=a[0]
	else
		str=str+" that "+a[i%3]
	end
}
puts str+" it"

n=gets.chomp().to_i
s3="i love it"
s2=" that "
s1="i hate it"
s4="i hate it"
i=2
while i<=n
  if i%2==0
    s1+=s2+s3
  else
    s1+=s2+s4
  end
  i=i+1
end
puts(s1)

n=gets.chomp().to_i
s3=" ilove it "
s2=" that "
s1="i hate it "
s4="i hate it "
i=2
while i<=n
  if i%2==0
    s1+=s2+s3
  else
    s1+=s2+s4
  end
  i=i+1
end
puts(s1)

n=gets.chomp().to_i
s3="I love it"
s2=" that "
s1="I hate it"
s4="I hate it"
i=2
while i<=n
  if i%2==0
    s1+=s2+s3
  else
    s1+=s2+s4
  end
  i=i+1
end
puts(s1)


n = gets.to_i
arr = gets.split(" ").map(&:to_i)
l = r = 0
arr.each_with_index do |a,i|
	s = i + 1
	if a != s
		l = s
		r = a
		break
	end
end
# puts "#{l} #{r}"
if l != 0 && r != 0
	(l..r).each do |z|
		i = z-1
		arr[i] = z
	end
	val = (1..n).to_a
	# puts "#{arr} #{val}"
	if arr != val
		l = 0
		r = 0
	end
end
puts "#{l} #{r}"

n = gets.to_i
s = gets.chomp!.split(" ")
mas = Array.new()

for i in 0..n-1
  mas[i] = s[i].to_i
end

start,finish = 0, 0
wrong = false
for i in 1..n-1
  if mas[i] == mas[i-1] - 1
    start = i if start == 0
  else
    finish = i if start != 0 && finish == 0
  end
end

finish = n if finish == 0 && start != 0

for i in 0..start-3
  wrong = true if mas[i] + 1 != mas[i+1]
end
for i in finish..n-2
  wrong = true if mas[i] + 1 != mas[i+1]
end

puts wrong ? "0 0" : start.to_s + " "+finish.to_s

def check a,n
  i = 0
  z = []
  while i < n do
    z[i]= i+1
    if a[i]!=z[i] then
      return false
    end
    i += 1
  end
  return true
end

def get_sub_array a,i
  j = i
  res = []
  while j < a.length-1 do
    if a[j]-a[j+1]==1 then
      if !res.include?(a[j]) then
       res << a[j]
      end
      if !res.include?(a[j+1]) then
        res << a[j+1]
      end
    else
      if !res.include?(a[j]) then
       res << a[j]
      end
      break
    end
    j+=1
  end
  return res.reverse
end

def conc a,b,i,n
  j,count = 0,0
        while j < a.length do
            if i == j - 1 then
                count = i;
        j2 = 0
                while j2 < b.length do
                    a[count] = b[j2];
          count += 1
          j2 += 1
        end
                break
      end
      j += 1
    end
        if check(a, n) then
            return true
    end
    return false
end

def solve!
  m = gets.to_i
  s = gets.chomp
  a = s.split(" ")
  q = a.map { |x| x.to_i }
  if check(q,m) then
    print "0 0"
  else
    i = 0
    for c in q
      if c != i+1 then
        z = get_sub_array(q , i)
        if conc(q, z, i, m)then
          print "#{z[0]} #{z[z.length - 1]}"
          break
        else
          print "0 0"
          break
        end
      end
      i += 1
    end
  end
end

solve!

n = gets.to_i
arr = gets.split(" ").map(&:to_i)
l = r = 0
arr.each_with_index do |a,i|
	s = i + 1
	if a != s
		l = s
		r = a
		break
	end
end
# puts "#{l} #{r}"
if l != 0 && r != 0
	x = r
	arr[(l-1)..(r-1)].each do |a|
		if a != x
			l = 0
			r = 0
			break
		end
		x -= 1
	end
end
puts "#{l} #{r}"

n = gets.to_i
arr = gets.split(" ").map(&:to_i)
l = r = 0
arr.each_with_index do |a,i|
	s = i + 1
	if a != s
		l = s
		r = a
		break
	end
end
# puts "#{l} #{r}"
if l != 0 && r != 0
	(l..r).each do |z|
		i = z-1
		arr[i] = z
	end
	val = (1..n).to_a
	puts "#{arr} #{val}"
	if arr != val
		l = 0
		r = 0
	end
end
puts "#{l} #{r}"

n = gets.to_i
s = gets.chomp!.split(" ")
mas = Array.new()

for i in 0..n-1
  mas[i] = s[i].to_i
end

start,finish = 0, 0
wrong, first_wrong = false, true
for i in 1..n-1
  if mas[i] == mas[i-1] - 1
    start = i if start == 0

    wrong = true if finish != 0
  else
    finish = i if start != 0 && finish == 0

    first_wrong ? first_wrong = false : wrong = true if mas[i-1] + 1 != mas[i]
  end
end

finish = n if finish == 0 && start != 0

puts wrong ? "0 0" : start.to_s + " "+finish.to_s

n = gets.to_i
s = gets.chomp!.split(" ")
mas = Array.new()

for i in 0..n-1
  mas[i] = s[i].to_i
end

start,finish = 0, 0
for i in 1..n-1
  if mas[i] == mas[i-1] - 1
    if start == 0
      start = i
    end
    if finish != 0
      puts "0 0"
      exit
    end
  else
    if start != 0 && finish == 0
      finish = i
    end
  end
end

if finish == 0 && start != 0
  finish = n
end

puts start.to_s + " "+finish.to_s

n = gets.to_i
s = gets.chomp!.split(" ")
mas = Array.new()

for i in 0..n-1
  mas[i] = s[i].to_i
end

start,finish = 0, 0
wrong, first_wrong = false, true
for i in 1..n-1
  if mas[i] == mas[i-1] - 1
    start = i if start == 0

    wrong = true if finish != 0
  else
    finish = i if start != 0 && finish == 0

    first_wrong ? firstwrong = false : wrong = true if mas[i-1] + 1 != mas[i]
  end
end

finish = n if finish == 0 && start != 0

puts wrong ? "0 0" : start.to_s + " "+finish.to_s


gets
puts gets.chomp.squeeze("aiuy").gsub(/e{3,}/, 'e').gsub(/o{3,}/, 'o')

while l = gets
	a = gets
	b = a.squeeze("aiuy")
	c = b.gsub(/e{3,}/, 'e').gsub(/o{3,}/, 'o')
	print c
end

n = gets
s = gets
i = 0
last = '$'
vowels = 'aiuy'
ecount = 0
ocount = 0
s.split("").each do |c|
    if c == 'e'
        ecount += 1
    elsif ecount > 0
        if ecount == 2
            print 'ee'
        else
            print 'e'
        end
        ecount = 0
    end

    if c == 'o'
        ocount += 1
    elsif ocount > 0
        if ocount == 2
            print 'oo'
        else
            print 'o'
        end
        ocount = 0
    end

    if vowels.include? c
        unless c === last
            print c
        end
    elsif c != 'e' and c != 'o'
        print c
    end

    last = c
end
# puts "#{s}"

# require 'rubygems'
# gem 'capataz'
# require 'capataz'
#
# class A
#   def m1
#     1
#   # end
#
#   def m2
#     2
#   end
#
#   def self.m3
#     3
#   end
#
#   def self.m4
#     4
#   end
# end
#
# Capataz.config do
#
#   set_max_allowed_iterations 6
#
#   set_max_allowed_invocations :new, 6, :casecmp, 5
#
#   deny_declarations_of :module
#
#   deny_invoke_of :constantize
#
#   allowed_constants A, Set
#
#   #deny_for A, :m2
#
#   deny_on A, :m4
#
# end
#
# puts Capataz.eval <<-RUBY
#
# x = A.new
# x.m1
# x.m2
#
# A.m4
#
# RUBY

def cons(x)
  if ['a','e','i','o','u','y'].include?(x)
    return false
  else
    return true
  end
end

def a(x)
  if ['a','i','u','y'].include?(x)
    return true
  else
    return false
  end
end

def last(i,n,s)
  while true
    if i == n - 1 or s[i + 1] != s[i]
      return i
    end
    i += 1
  end
end

n = readline().to_i
s = readline()

i = 0
while i < n
  if cons(s[i])
    print s[i]
  elsif a(s[i])
    unless i < n - 1 and s[i] == s[i + 1]
      print s[i]
    else
    end
  else
    print s[i]
    pos = last(i,n,s)
    if pos > i + 1
      i = pos
    end
  end
  i += 1
end

def is_vowel( ch )
  vowel = "aeiouy"
  for i in 0..( vowel.length - 1 ) do
    if vowel[ i ] == ch then
      return true
    end
  end
  return false
end

N = gets.chomp.to_i
S = gets.chomp
ans = ""
prev = '$'
ptr = 0
while ptr < N do
  if not is_vowel( S[ ptr ] ) then
    ans.concat( S[ ptr ] )
    ptr += 1
    next # continue の身代わりらしい
  end
  nxt = ptr
  while nxt < N do
    if S[ nxt ] != S[ ptr ] then
      break
    end
    nxt += 1
  end
  if nxt - ptr == 2 and ( S[ ptr ] == 'e' or S[ ptr ] == 'o' ) then
    ans.concat( S[ ptr ] )
    ans.concat( S[ ptr ] )
  else
    ans.concat( S[ ptr ] )
  end
  ptr = nxt
end
print ans

n = gets.to_i
n = n-1
s = gets.chomp
last = '#'
cnt = 0
for i in (0..n)
    if s[i] != last then
        if "oe".count(last) > 0 and cnt == 2 then
            print last
        end
    end
    if "aeiouy".count(s[i]) > 0 then
        if s[i] == last then
            cnt = cnt + 1
        else
            print s[i]
            cnt = 1
        end
    else
        print s[i]
        cnt = 1
    end
    last = s[i]
end
if "oe".count(last) > 0 and cnt == 2 then
    print last
end
print "\n"

gets
puts gets.chomp.squeeze("aiuy").sub(/e{3,}/, 'e').sub(/o{3,}/, 'o')

while l = gets
	a = gets
	b = a.squeeze("aiuy")
	c = b.gsub(/e{3,}/, 'e').gsub(/o{3,}/, 'o')
	p c
end

while l = gets
	a = gets
	b = a.squeeze("aiuy")
	c = b.gsub(/e{3,}/, 'e').gsub(/o{3,}/, 'o')
	p "#{c}\n"
end


gets; input = gets.strip.split.map &:to_i
odd, even = [], []
input.each {|i| i % 2 == 0 ? even.push(i) : odd.push(i)  }
print even.length == 1 ? input.index(even.first) + 1 : input.index(odd.first) + 1

n=gets.chomp.to_i
memo=gets.chomp.split.map{|i| i.to_i}
even=0
odd=0
evenIndex=-1
oddIndex=-1
n.times do |i|
  if memo[i]%2 == 0
    even=even+1
    evenIndex=i
  elsif
    odd=odd+1
    oddIndex=i
  end
end
if even > odd
  puts oddIndex+1
else
  puts evenIndex+1
end

gets
arr = gets.split.map &:to_i
puts arr.count { |x| x % 2 == 0 } > arr.count { |x| x % 2 != 0 } ?
  arr.index { |x| x % 2 != 0 } + 1 : arr.index { |x| x % 2 == 0 } + 1

n = gets.to_i
a = gets.split.map!{|t| t.to_i}
b = a.sort{|x,y| x%2 <=> y%2}
if b[0]%2 != b[1]%2
    puts a.index(b[0])+1
else
    puts a.index(b[-1])+1
end

gets.chomp
nums = gets.chomp.split(/ /).map(&:to_i)
odds = []
evens = []
(0...nums.length).each do |num|
    evens << num + 1 if nums[num].even?
    odds << num + 1 if nums[num].odd?
end
ans = 0
if odds.length == 1
    ans = odds[0]
else
    ans = evens[0]
end
puts ans

gets
a = gets.split.map(&:to_i)
b = { 0 => [], 1 => [] }
a.each_with_index do |x, i|
  b[x % 2] << i + 1
end
b.each_value do |ns|
  puts ns.first if ns.size == 1
end

n = gets.chomp.to_i
arr = gets.chomp.split.map(&:to_i)
co = 0
aco = {'odd'=>0,'even'=>0}
arr.each_with_index do |el,i|
  aco['even'] += 1 if el %2 == 0
  aco['odd'] += 1 if el %2 != 0
end

arr.each_with_index do |el,i|
  if aco['odd'] == 1
    if el % 2 != 0
      co = i
      break
    end
  else
    if el % 2 == 0
      co = i
      break
    end
  end
end

puts co+1

n = gets.to_i
arr = gets.split.map { |e| e.to_i  }
c = 0
3.times do |i|
	arr[i].even? ? c += 1 : c = c
	i += 1
end
x = 1
if c >= 2
	for i in arr
		if i.even?
			x += 1
		else
			p x
		end
	end
else
	for i in arr
		if i.even?
			p x
		else
			x += 1
		end
	end
end

gets
q = gets.split.map { |e| e.to_i }

s = q.find_all { |x| x.even? }
if s.size == 1
  puts q.index(s[0]) + 1
  exit
end

s = q.find_all { |x| x.odd? }
puts q.index(s[0]) + 1

def fn()
n=gets.to_i
arr=gets.split.collect{|a| a.to_i%2}
even=arr.count 0
odd= arr.count 1
wild=0
if odd == 1
  wild=1
end

return (arr.index wild)+1

end

p fn()

amount = gets.chomp
n = gets.chomp

numbers = n.split
even = 0
odd = 0

if amount.to_i == numbers.count
	for i in (1..amount.to_i)
		if numbers[i-1].to_i%2 != numbers[i].to_i%2
			a = numbers[i-1].to_i
			b = numbers[i].to_i
			pos_a = i
			pos_b = i+1
			break
		end
	end
end

numbers.each do |number|
	if number.to_i%2 == 0
		even += 1
	else
		odd += 1
	end
end

if even == 1 && a%2 == 0
	print pos_a
elsif even == 1 && b%2 == 0
	print pos_b
elsif odd == 1 && a%2 != 0
	print pos_a
else
	print pos_b
end

#!/bin/ruby

n = gets.chomp.to_i

a = gets.chomp.split(" ").map {|e| e.to_i}

j = 1
vitri = 0
odd = 0
even = 0
wE = 0
wO = 0
a.each do |i|
    if i % 2 == 0
        even += 1
        wE = j
    else
        odd += 1
        wO = j
    end
    j += 1
end

if even > odd
    puts wO.to_i
else
    puts wE.to_i
end

#puts "Enter total number of integers\n"
n = gets.to_i
#puts "Enter the numbers in a line\n"
s = gets.chomp.to_s.split(" ")
l = s.length
a = [l]
for i in 0...l do
    a[i] = s[i].to_i
end
e = []
o = []
j = 0
k = 0
for c in 0...l do
    if a[c] % 2 == 0
         e[j] = c
         j += 1
    else
        o[k] = c
        k += 1
    end
end
#puts o.length
#puts e.length
if o.length < e.length
    puts o[0] + 1
else
    puts e[0] + 1
end

gets.to_i
numbers = gets.split(" ").map(&:to_i)
odd_count = 0
even_count = 0
numbers[0..2].each do |n|
  if n % 2 == 0
    even_count += 1
  else
    odd_count += 1
  end
end

remainder = 1
remainder = 0 if even_count > odd_count
numbers.each_with_index do |n,i|
  puts i + 1 and break if n % 2 != remainder
end

gets
a = gets.split.map &:to_i
a.partition{|x| x.even? }[0].size == 1 ? a.map{|x| puts a.index(x) + 1 if x.even? } : a.map{|x| puts a.index(x) + 1 if x.odd? }

n = gets
l = gets.split
i = l.index{ |x| (l[0].to_i.even? and x.to_i.odd?) or (not l[0].to_i.even? and x.to_i.even?) } + 1
if l[i..-1].find{ |x| (l[0].to_i.even? and x.to_i.odd?) or (not l[0].to_i.even? and x.to_i.even?) }
	puts 1
else
	puts i
end

n, nums, odd, even, cur = gets, gets.chomp.split(' ').map { |item| item.to_i }, [], [], 1
nums.each{|i|
  even << cur if i.even?
  odd << cur if i.odd?
  cur=cur+1
}
puts even[0] if even.size==1
puts odd[0] if odd.size==1

n = gets.to_i
a = gets.split.map(&:to_i)
m = a.take(3).map{|x| x % 2}.sort[1]
puts a.find_index{|x| x % 2 != m} + 1

n = gets.to_i
a = [nil] + gets.split.map(&:to_i)
e = 0
o = 0
a[1..3].map{|x| x % 2 == 0 ? e += 1 : o += 1}
m = 1
m = 0 if e > o
for i in 1..a.size
  if a[i] % 2 != m
    puts i
    break
  end
end

gets
nums = gets.chomp.split.map(&:to_i)

res = nums.partition{ |e| e.even? }
elem = res.min_by{ |e| e.size }
puts nums.find_index(elem[0]) + 1

class Euler
  n=gets.to_i;
  a=gets;
  a=a.split(" ");
  a.each_index do |i|
    a[i]=(a[i].to_i)%2;
  end
  b=a.sort;
  if (b[0]==b[1])
    a.each_index do |i|
    if (a[i].to_i%2==1)
      puts (i+1);
      exit;
    end
    end
  else
     a.each_index do |i|
    if (a[i].to_i%2==0)
      puts (i+1);
      exit;
    end
  end
  end
end

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

puts (a.one?(&:odd?) ? a.index(&:odd?) : a.index(&:even?)) + 1

gets
nums = gets.split
even = 0
odd = 0
first_odd = nil
first_even = nil
nums.each_with_index do |num,index|
  num_even = num.to_i % 2 == 0
  if(!num_even)
    first_odd = index + 1 if odd == 0
    odd += 1
  else
    first_even = index + 1 if even == 0
    even +=1
  end
  if(odd >= 2 && even == 1)
    puts first_even
    break
  end
  if(even >= 2 && odd == 1)
    puts first_odd
    break
  end
end

gets
nums = gets.split(" ")

even = odd = even_pos = odd_pos = 0

nums.each_with_index do |num, i|
    buff = num.to_i
    if buff.even?
	even += 1
	even_pos = i + 1
    elsif buff.odd?
	odd += 1
	odd_pos = i + 1
    end

    if even >= 2 && odd == 1
	puts odd_pos
	exit
    elsif odd >= 2 && even == 1
	puts even_pos
	exit
    end
end

n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
e = a.select {|x| x % 2 == 0 }
puts a.each_with_index.select {|x| x[0] % 2 == (e.length == 1 ? 0 : 1)}.first.last + 1

n = gets.to_i
hs = gets.split(' ').map(&:to_i).map.with_index{|x,id| [x,id]}.group_by{|x,id| x%2}
puts hs.min_by{|x,y| y.length}.last.last.last + 1

def func(n)
    if n % 2 == 0 then
        return true
    else
        return false
    end
end

n = gets.to_i
ch = []
nech = []

nums = gets.split.map{|i| i.to_i}

i = 0
while ch.size < 2 && nech.size < 2 do
    if func(nums[i]) then
        ch << nums[i]
    else
        nech << nums[i]
    end
    i += 1
end

if ch.size == 2 then
    i = 0
    while func(nums[i]) do
        i += 1
    end
else
    i = 0
    while !func(nums[i]) do
        i += 1
    end
end

puts i+1

n = gets.chomp.to_i
a = gets.chomp.split(/ /)
idx = 1
firste = 0
laste  = 0
firsto = 0
lasto  = 0
a.each {|aa|
	if aa.to_i % 2 == 0
		laste = idx
		firste = idx if firste == 0
	else
		lasto = idx
		firsto = idx if firsto == 0
	end
	idx += 1
}
if laste == firste
	puts laste
else
	puts lasto
end

n = gets.to_i
task = gets.strip.split.map &:to_i

odd_even_indexes = {odd: [], even:[]}

task.each_index do |i|
  if task[i].odd?
    odd_even_indexes[:odd] << (i + 1)
  else
    odd_even_indexes[:even] << (i + 1)
  end
end

if odd_even_indexes[:odd].length == 1
  puts odd_even_indexes[:odd].first
else
  puts odd_even_indexes[:even].first
end

gets
cnt = 0
a = gets().chomp.split(/[ \n]/)
a.map{|x| cnt += 1 if x.to_i.odd?}
puts a.index{|x| cnt == 1 ? x.to_i.odd? : x.to_i.even?} + 1

def string_to_int(string, delim = " ")
  result = []
  string = string.split(delim)
  for i in 0...string.length
    result[i] = string[i].to_i % 2
  end
  return result
end

n = gets.chomp.to_i
test = string_to_int(gets.chomp)
if test.count(0) > test.count(1)
	puts test.index(1) + 1
else
	puts test.index(0) + 1
end

n = gets.to_i
a = gets.split.map(&:to_i)
c = [a[0], a[1], a[2]].map {|x| x%2}
c.count(0) > c.count(1) ? ch = 0 : ch = 1
puts a.index { |x| x%2 != ch } + 1

n = gets.to_i
arr = gets.split(" ").map{|i| i.to_i}
odd, even = [], []
n.times{|i| odd << i if arr[i].odd?; even << i if arr[i].even?}
puts (odd.count == 1 ? odd : even)[0]+1

n = gets.to_i
f = gets.split.map{|r| r.to_i}

counters = 0
for i in 0..n-1
 if f[i]%2 == 0
     par = i+1
     counters+=1
 else
     nep = i+1
 end
end

if counters > 1
    puts nep
else
    puts par
end

def find(n,even: false, odd: false )
  if even
    n.each_with_index do |val,ind|
      if val.even?
        puts ind +1
        break
      end
    end
  elsif odd
    n.each_with_index do |val,ind|
      if val.odd?
        puts ind+1
        break
      end
    end
  end
end

total = gets.chop!
n = gets.chop.split(" ").map(&:to_i)
count = 0
even=0
odd =0
n.each do |i|
  if count <3
    if i.even?
      even+=1
      count+=1
    else
      odd+=1
      count+=1
    end
  end
end
if even>odd
  find(n,odd: true)
else
  find(n,even: true)
end

gets
cnt = 0
a = gets().chomp.split(/[ \n]/)
a.map{|x| cnt += 1 if x.to_i.odd?}
puts a.select{|x| cnt == 1 ? x.to_i.odd? : x.to_i.even?}

n = gets.to_i
f = gets.split.map{|r| r.to_i}
a = Array.new(n)
b = Array.new(n)

for i in 0..n-1
 if f[i]%2 == 0
     a[i] = f[i]
 else
     b[i] = f[i]
 end
end

if a.compact.size < b.compact.size
   puts  a.compact
else
   puts b.compact
end

gets
p gets.split.collect{|i| i.to_i}.index{|x| x%2!=0}+1

gets
a = gets.split.map{|i| i.to_i%2}
p (a.count(0)>1?a.index{|x| x!=0}+1 : a.index{|x|x=0}+1)

gets
a = gets.split.map{|i| i.to_i%2}
p (a.count(0)>1?a.index{|x| x!=0} : a.index{|x|x=0})+1

gets
a = gets.split.map{|i| i.to_i%2}
p (a.count(?0)>1?a.index{|x| x!=0} : a.index{|x|x=0})+1

def find(n,even: false, odd: false )
  if even
    n.each_with_index do |val,ind|
      if val.even?
        return ind +1
      end
    end
  elsif odd
    n.each_with_index do |val,ind|
      if val.odd?
        return ind+1
      end
    end
  end
end

n = gets.chop.split(" ").map(&:to_i)
count = 0
even=0
odd =0
n.each do |i|
  if count <3
    if i.even?
      even+=1
      count+=1
    else
      odd+=1
      count+=1
    end
  else
    if even>odd
      puts find(n,odd: true).to_i
      break
    else
      puts find(n,even: true).to_i
      break
    end
  end
end

def find(n,even: false, odd: false )
  if even
    n.each_with_index do |val,ind|
      if val.even?
        puts ind +1
        break
      end
    end
  elsif odd
    n.each_with_index do |val,ind|
      if val.odd?
        puts ind+1
        break
      end
    end
  end
end

n = gets.chop.split(" ").map(&:to_i)
count = 0
even=0
odd =0
n.each do |i|
  if count <3
    if i.even?
      even+=1
      count+=1
    else
      odd+=1
      count+=1
    end
  else
    if even>odd
      find(n,odd: true)
      break
    else
      find(n,even: true)
      break
    end
  end
end

# cook your code here
def find(n,even: false, odd: false )
  if even
    n.each_with_index do |val,ind|
      if val.even?
        return ind +1
      end
    end
  elsif odd
    n.each_with_index do |val,ind|
      if val.odd?
        return ind+1
      end
    end
  end
end

n = gets.chop.split(" ").map(&:to_i)
count = 0
even=0
odd =0
n.each do |i|
  if count <3
    if i.even?
      even+=1
      count+=1
    else
      odd+=1
      count+=1
    end
  else
    if even>odd
      puts find(n,odd: true)
      break
    else
      puts find(n,even: true)
      break
    end
  end
end

def find(n,even: false, odd: false )
  if even
    n.each_with_index do |val,ind|
      if val.even?
        puts ind +1
        break
      end
    end
  elsif odd
    n.each_with_index do |val,ind|
      if val.odd?
        puts ind+1
        break
      end
    end
  end
end

total = gets.chop!
n = gets.chop.split(" ").map(&:to_i)
count = 0
even=0
odd =0
n.each do |i|
  if count <3
    if i.even?
      even+=1
      count+=1
    else
      odd+=1
      count+=1
    end
  else
    if even>odd
      find(n,odd: true)
      break
    else
      find(n,even: true)
      break
    end
  end
end

n=gets.chomp.to_i
number=gets.chomp.split.map{|i| i.to_i}
memo=Array.new(4)
if n==3
  puts 2
  exit(0)
end
mhash=Hash.new
num=0
(n-1).times do |i|
  memo[i]= number[i+1]-number[i]
  if mhash.include?(memo[i])==false
    mhash[memo[i]]=true
  elsif
    num=memo[i]
  end
end
(n-1).times do |i|
  if memo[i]!=num
    puts i+2
    break
  end
end

gets.chomp
nums = gets.chomp.split(/ /).map(&:to_i)
odds = []
evens = []
ans = 0
puts ans

n = gets.to_i
arr = gets.split.map { |e| e.to_i  }
c = 0
3.times do |i|
	arr[i].even? ? c += 1 : c = c
	i += 1
end
x = 1
if c == 2
	for i in arr
		if i.even?
			x += 1
		else
			p x
		end
	end
else
	for i in arr
		if i.even?
			p x
		else
			x += 1
		end
	end
end

def fn()
n=gets.to_i
arr=gets.split.collect{|a| a.to_i }
x=arr.pop
y=arr.pop
z=arr.pop
if x%2==y%2 && x%2!= z%2
 return z
elsif x%2==z%2  &&x%2 !=y%2
return y
elsif z%2==y%2 && z%2 !=x%2
return x
end

return arr.select{|a| a%3 != x%2}.first

end

p fn()

n = gets
l = gets.split
puts l.index{ |x| (l[0].to_i.even? and x.to_i.odd?) or (not l[0].to_i.even? and x.to_i.even?) } + 1

gets; input = gets.strip.split.map &:to_i
k = input[0] % 2

input.length.times {|i| print i + 1 if k != input[i] % 2 }


DBG = true
n = gets.to_i
a = gets.split.map{|z| z.to_i}
m = gets.to_i
q = gets.split.map{|z| z.to_i}
sum = a.inject(:+)
a.sort_by!{|z| -z}
for i in 0...m
  x = q[i]
  puts "#{sum - a[x-1]}"
end

if File.exists?("input")
  $stdin = File.open("input")
  $stdout = File.open("output","w")
end

n = gets.to_i
arr = gets.chomp.split(" ").map(&:to_i).sort
sum = arr.inject(:+)
m = gets.to_i
qarr = gets.chomp.split(" ").map(&:to_i)

qarr.each do |q|
	puts sum-arr[-q]
end


while !STDIN.eof? && (string1 = STDIN.readline.strip) && (string2 = STDIN.readline.strip)
  n = string1.split(" ").first.to_i
  k = string1.split(" ").last.to_i
  successes = string2.split(" ").map { |s| s.strip == "YES" }
  name = "a"
  names = []
  successes.each_with_index do |success, index|
    if(index > 0)
      if(success)
        names.push(name.capitalize)
        name = name.next
      else
        names.push(names[index].capitalize)
      end
    else
      if(success)
        k.times do
          names.push(name.capitalize)
          name = name.next
        end
      else
        (k-1).times do
          names.push(name.capitalize)
          name = name.next
        end
        names.push(names[index].capitalize)
      end
    end
  end
  string = ""
  names.each { |name| string << name << " " }
  STDOUT << string.strip << "\n"
end

#1. Collect Input
n = gets(" ").to_i
k = gets.chomp.to_i

arr = gets.chomp.split(" ")
arr.map! { |s| s == "YES" ? true : false }

names = Array.new()
c_name = 0
stop_i = 0
out = Array.new(n, "")

names =
"Joyce
Abbey
Jenine
Arleen
Cammie
Lizbeth
Mario
Cortney
Shauna
Jenae
Erich
Faviola
Lexie
Erlinda
Alethia
Jacklyn
Yvone
Judy
Cassy
Hilda
Nettie
Florencia
Pattie
Zula
Debrah
Celeste
Leia
Lisette
Margarito
Josephina
Lanie
Justin
Kacie
Delores
Sherita
Carolynn
Edra
Hiedi
Neville
Rhona
Zane
Devona
Sigrid
Phillis
Delana
Nathanial
Roni
Melvina
Terri
Kandra".split("\n").each{ |s| s.strip! }

#2. First Advance
(0...arr.length).each do |i|
  if arr[i]
    (i...i+k).each do |j|
      out[j] = names[c_name]
      c_name += 1
    end
    stop_i = i
    break
  else
    out[i] = names[0]
  end
end

#3. Rest
if c_name == 0
  (arr.length...n).each { |i| out[i] = names[0] }
else
  (stop_i+1...arr.length).each do |i|
    if arr[i]
      out[i+k-1] = names[c_name]
      c_name += 1
    else
      out[i+k-1] = out[i]
    end
  end
end

out.each do |e|
  print e
  print " "
end

n, k=gets.split.map &:to_i
s=gets.split
c=?A
res=(1..n).map{c.next!.capitalize}
s.each_with_index{|e, i|
    res[i+k-1]=res[i] if e=="NO"
}
puts res*' '

names = ('A'..'Z').to_a + ('Aa'..'Az').to_a
n, k = gets.split.map(&:to_i)
bools = gets.split(' ').map{|x| x == 'YES'}
ans = Array.new(n)
ans[0, k - 1] = names[0, k - 1]
nn = k - 1
(n - k + 1).times do |i|
  if bools[i]
    ans[i + k - 1] = names[nn]
    nn += 1
  else
    ans[i + k - 1] = ans[i]
  end
end
puts ans.join(' ')

names = ('A'..'Z').to_a + ('AA'..'AZ').to_a
nn = 0
n, k = gets.split.map(&:to_i)
bools = gets.split(' ').map{|x| x == 'YES'}
ans = Array.new(n)
if bools[0]
  ans[0, k] = names[nn, k]
  nn += k
else
  ans[0, k - 1] = names[nn, k - 1]
  ans[0 + k - 1] = ans[0]
  nn += k - 1
end
(n - k).times do |i|
  if bools[i + 1]
    ans[i + k] = names[nn]
    nn += 1
  else
    ans[i + k] = ans[i + 1]
  end
end
puts ans.join(' ')

n, k=gets.split.map &:to_i
s=gets.split
if !s.include?("YES")
    puts "A "*n
else
    c=?A
    res=(1..n).map{c.next!.capitalize}
    s.reverse.each_with_index{|e, i|
        res[i]=res[i+k-1] if e=="NO"
    }
    puts res.reverse*' '
end

while !STDIN.eof? && (string1 = STDIN.readline.strip) && (string2 = STDIN.readline.strip)
  n = string1.split(" ").first.to_i
  k = string1.split(" ").last.to_i
  successes = string2.split(" ").map { |s| s.strip == "YES" }
  name = "a"
  names = []
  successes.each_with_index do |success, index|
    if(index > 0)
      if(success)
        names.push(name)
        name = name.next
      else
        names.push(names[index])
      end
    else
      if(success)
        k.times do
          names.push(name)
          name = name.next
        end
      else
        (k-1).times do
          names.push(name)
          name = name.next
        end
        names.push(names[index])
      end
    end
  end

  p names
end

while !STDIN.eof? && (string1 = STDIN.readline.strip) && (string2 = STDIN.readline.strip)
  n = string1.split(" ").first.to_i
  k = string1.split(" ").last.to_i
  successes = string2.split(" ").map { |s| s.strip == "YES" }
  name = "a"
  names = []
  successes.each_with_index do |success, index|
    if(index > 0)
      if(success)
        names.push(name)
        name = name.next
      else
        names.push(names[index])
      end
    else
      if(success)
        k.times do
          names.push(name)
          name = name.next
        end
      else
        (k-1).times do
          names.push(name)
          name = name.next
        end
        names.push(names[index])
      end
    end
  end
  string = ""
  names.each { |name| string << name << " " }
  STDOUT << string.strip << "\n"
end


main = -> {
  m, s = ints
  b = ints

  return "NO" if b.uniq.size != m

  b_max = b.max

  exist = [false] * (b_max + 1)
  b.each do |bi|
    exist[bi] = true
  end

  acc = 0
  (1..b_max).each do |i|
    acc += i unless exist[i]
  end

  (b_max+1..30000).each do |i|
    return "YES" if acc + (b_max + 1...i).sum == s
  end

  return "NO"
}

def int; gets.to_i end
def ints; gets.split.map(&:to_i) end

t = gets.to_i
puts t.times.map{ main.call }.join("\n")

gets.to_i.times do
    m, s=gets.chomp.split(' ').map(&:to_i)
    arr=gets.chomp.split(' ').map(&:to_i)
    n= Math.sqrt((arr.sum+s)*2).floor
    mx=arr.max
    if arr.uniq.length==m && n*(n+1)==(arr.sum+s)*2 && n>=mx
        puts "YES"
    else
        puts "NO"
    end
end

gets.to_i.times do
    m, s=gets.chomp.split(' ').map(&:to_i)
    arr=gets.chomp.split(' ').map(&:to_i)
    n= Math.sqrt((arr.sum+s)*2).floor
    if arr.uniq.length==m and n*(n+1)==(arr.sum+s)*2
        puts "YES"
    else
        puts "NO"
    end
end


gets.to_i.times do
    n=gets.to_i
    h=Hash.new (0)
    (n*2+1).times do
        gets.each_char do |c|
            h[c]=h[c]+1
        end
    end
    h.each do |x,y|
        if y%2!=0 && x>='a' and x<='z'
            puts x
        end
    end
end

t = gets.chomp.to_i
t.times do
    n = gets.chomp.to_i
    list = {}
    ('a'..'z').each do |i|
        list.store(i, 0)
    end
    possible_answers = []

    ((2*n)+1).times do
        x = gets.chomp
        x.each_char do |i|
            list[i] += 1;
        end
    end

    list.keys.each do |key|
        if list[key]%2 == 1
            puts key
            break
        end
    end
end

gets.to_i.times do
  n = gets.to_i
  freq = [0] * 26
  (2 * n + 1).times do |i|
    gets.chomp.bytes.each do |c|
      freq[c - 97] += 1
    end
  end
  freq.each.with_index do |f, i|
    puts (97 + i).chr if f % 2 == 1
  end
end

gets.to_i.times do
  n = gets.to_i
  freq = Array.new(26) { [0] * (2 * n + 1) }
  (2 * n + 1).times do |i|
    gets.chomp.bytes.each do |c|
      freq[c - 97][i] += 1
    end
  end
  freq.each.with_index do |f, i|
    left, right = 0, 0
    f.sort.reverse.each do |x|
      if left < right
        left += x
      else
        right += x
      end
    end
    if left != right
      puts (97 + i).chr
      break
    end
  end
end

gets.to_i.times do
  n = gets.to_i
  freq = Array.new(26) { [0] * (2 * n + 1) }
  (2 * n + 1).times do |i|
    gets.chomp.bytes.each do |c|
      freq[c - 97][i] += 1
    end
  end
  freq.each.with_index do |f, i|
    left, right = 0, 0
    f.sort.each do |x|
      if left < right
        left += x
      else
        right += x
      end
    end
    if left != right
      puts (97 + i).chr
      break
    end
  end
end

gets.to_i.times do
  n = gets.to_i
  freq = Array.new(26) { [0] * (2 * n + 1) }
  (2 * n + 1).times do |i|
    gets.chomp.bytes.each do |c|
      freq[c - 97][i] += 1
    end
  end
  freq.each.with_index do |f, i|
    sum = 0
    f.sort.each do |x|
      if (sum + x).abs < (sum - x).abs
        sum += x
      else
        sum -= x
      end
    end
    if sum != 0
      puts (97 + i).chr
      break
    end
  end
end

gets.to_i.times do
  n = gets.to_i
  freq = Array.new(26) { [0] * (2 * n + 1) }
  (2 * n + 1).times do |i|
    gets.chomp.bytes.each do |c|
      freq[c - 97][i] += 1
    end
  end
  freq.each.with_index do |f, i|
    sum = 0
    f.sort.reverse.each do |x|
      if (sum + x).abs < (sum - x).abs
        sum += x
      else
        sum -= x
      end
    end
    if sum != 0
      puts (97 + i).chr
      break
    end
  end
end

t = gets.chomp.to_i
t.times do
    n = gets.chomp.to_i
    list = {}
    ('a'..'z').each do |i|
        list.store(i, 0)
    end
    possible_answers = []
    cnt = 0
    ((2*n)+1).times do
        x = gets.chomp
        cnt+=1
        if cnt != 2*n+1
            if x.length == 1
                possible_answers << x
            end
        end
        temp_list = {}
        x.each_char do |i|
            temp_list[i] = 1;
        end
        temp_list.keys.each do |key|
            list[key]+=1
        end

    end

    possible_answers.each do |x|
        if list[x]%2 == 1
            puts x
            break
        end
    end
end

t = gets.chomp.to_i
t.times do
    n = gets.chomp.to_i
    list = {}
    ('a'..'z').each do |i|
        list.store(i, 0)
    end
    possible_answers = []
    ((2*n)+1).times do
        x = gets.chomp
        if x.length == 1
            possible_answers << x
        end
        temp_list = {}
        x.each_char do |i|
            temp_list[i] = 1;
        end
        temp_list.keys.each do |key|
            list[key]+=1
        end

    end

    possible_answers.each do |x|
        if list[x]%2 == 1
            puts x
            break
        end
    end
end

t = gets.chomp.to_i
t.times do
    n = gets.chomp.to_i
    list = {}
    ('a'..'z').each do |i|
        list.store(i, 0)
    end
    possible_answers = []
    ((2*n)+1).times do
        x = gets.chomp
        if x.length == 1
            possible_answers << x
        end
        temp_list = {}
        x.each_char do |i|
            temp_list[i] = 1;
        end
        temp_list.keys.each do |key|
            list[key]+=1
        end

    end

    possible_answers.each do |x|
        if list[x]%2 == 1
            p x
            break
        end
    end
end

gets.to_i.times do
    n=gets.to_i
    h=Hash.new (0)
    (n*2+1).times do
        gets.each_char do |c|
            h[c]=h[c]+1
        end
    end
    h.each do |x,y|
        if y%2!=0
            print x
        end
    end
end

gets.to_i.times do
    n=gets.to_i
    h=Hash.new (0)
    (n*2+1).times do
        gets.each_char do |c|
            h[c]=h[c]+1
        end
    end
    h.each do |x,y|
        if y%2!=0
            puts x
        end
    end
end


def compress(s)
  a = Array.new(s.size)
  last = nil
  cnt = 0
  s.split('').each do |c|
    if c == last
      cnt += 1
    else
      a.push [last, cnt] if last
      last = c
      cnt = 1
    end
  end
  a.push([last, cnt]).compact
end

def good(a, b)
  if a.size != b.size
    false
  else
    !(a.map.with_index do |e, i|
      e[0] == b[i][0] && e[1] <= b[i][1]
    end.include? false)
  end
end

n = gets.strip.to_i
n.times do
  a = gets.strip
  b = gets.strip
  puts good(compress(a), compress(b)) ? 'YES' : 'NO'
end

n = gets.to_i
n.times do
  s = gets.chomp
  t = gets.chomp
  flg = true
  i,j=0,0
  sl,tl = s.length,t.length
  while i < sl && j < tl
    ci,cj = 0,0
    #p [i,j]
    while i < sl-1 && s[i] == s[i+1]
      i += 1
      ci += 1
    end
    while j < tl-1 && t[j] == t[j+1]
      j += 1
      cj += 1
    end
    if s[i] != t[j] || ci > cj
      flg = false
      break
    end
    i+=1
    j+=1
  end
  flg = false if i != sl || j != tl
  puts flg ? "YES" : "NO"
end

def compress(s)
  a = []
  last = nil
  cnt = 0
  s.split('').each do |c|
    if c == last
      cnt += 1
    else
      a.push [last, cnt] if last
      last = c
      cnt = 1
    end
  end
  a.push [last, cnt]
end

def good(a, b)
  if a.size != b.size
    false
  else
    !(a.map.with_index do |e, i|
      e[0] == b[i][0] && e[1] <= b[i][1]
    end.include? false)
  end
end

n = gets.strip.to_i
n.times do
  a = gets.strip
  b = gets.strip
  puts good(compress(a), compress(b)) ? 'YES' : 'NO'
end

def compress(s)
  a = []
  last = nil
  cnt = 0
  s.split('').each do |c|
    if c == last
      cnt += 1
    else
      a << [last, cnt] if last
      last = c
      cnt = 1
    end
  end
  a << [last, cnt]
end

def good(a, b)
  if a.size != b.size
    false
  else
    !(a.map.with_index do |e, i|
      e[0] == b[i][0] && e[1] <= b[i][1]
    end.include? false)
  end
end

n = gets.strip.to_i
n.times do
  a = gets.strip
  b = gets.strip
  puts good(compress(a), compress(b)) ? 'YES' : 'NO'
end

def compress(s)
  a = []
  last = nil
  cnt = 0
  index = 0
  s.split('').each do |c|
    if c == last
      cnt += 1
    else
      a << [last, cnt] if last
      last = c
      cnt = 1
    end
  end
  a << [last, cnt]
  a.compact
end

def good(a, b)
  if a.size != b.size
    false
  else
    !(a.map.with_index do |e, i|
      e[0] == b[i][0] && e[1] <= b[i][1]
    end.include? false)
  end
end

n = gets.strip.to_i
n.times do
  a = gets.strip
  b = gets.strip
  puts good(compress(a), compress(b)) ? 'YES' : 'NO'
end

def compress(s)
  a = []
  last = nil
  cnt = 0
  index = 0
  s.split('').each do |c|
    if c == last
      cnt += 1
    else
      a << [last, cnt] if last
      last = c
      cnt = 1
    end
  end
  a << [last, cnt]
  a.compact
end

def good(a, b)
  if a.size != b.size
    false
  else
    (0...(a.size)).each do |i|
      if !(a[i][0] == b[i][0] && a[i][1] <= b[i][1])
        return false
      end
    end
    true
  end
end

n = gets.chomp.to_i
n.times do
  a = gets.chomp
  b = gets.chomp
  puts good(compress(a), compress(b)) ? 'YES' : 'NO'
end

def compress(s)
  a = []
  last = nil
  cnt = 0
  index = 0
  s.split('').each do |c|
    if c == last
      cnt += 1
    else
      a << [last, cnt] if last
      last = c
      cnt = 1
    end
  end
  a << [last, cnt]
  a.compact
end

def good(a, b)
  if a.size != b.size
    false
  else
    (0...(a.size)).each do |i|
      if !(a[i][0] == b[i][0] && a[i][1] <= b[i][1])
        return false
      end
    end
    true
  end
end

n = gets.strip.to_i
n.times do
  a = gets.strip
  b = gets.strip
  puts good(compress(a), compress(b)) ? 'YES' : 'NO'
end

def compress(s)
  a = []
  last = nil
  cnt = 0
  index = 0
  s.split('').each do |c|
    if c == last
      cnt += 1
    else
      a << [last, cnt] if last
      last = c
      cnt = 1
    end
  end
  a << [last, cnt]
  a.compact
end

def good(a, b)
  if a.size != b.size
    false
  else
    a.each.with_index do |e, i|
      if !(e[0] == b[i][0] && e[1] <= b[i][1])
        return false
      end
    end
    true
  end
end

n = gets.strip.to_i
n.times do
  a = gets.strip
  b = gets.strip
  puts good(compress(a), compress(b)) ? 'YES' : 'NO'
end

def compress s
  a = []
  last = nil
  cnt = 0
  s.split('').each do |c|
    if c == last
      cnt += 1
    else
      if last
        a << [c, cnt]
      end
      last = c
      cnt = 1
    end
  end
  a << [last, cnt]
end

def good a, b
  if a.size != b.size
    false
  else
    !(a.map.with_index do |e, i|
      e[0] == b[i][0] && e[1] <= b[i][1]
    end.include? false)
  end
end

n = gets.strip.to_i
n.times do
  a, b = gets.strip, gets.strip
  puts good(compress(a), compress(b)) ? "YES" : "NO"
end

def compress(s)
  a = []
  last = nil
  cnt = 0
  s.split('').each do |c|
    if c == last
      cnt += 1
    else
      a << [c, cnt] if last
      last = c
      cnt = 1
    end
  end
  a << [last, cnt]
end

def good(a, b)
  if a.size != b.size
    false
  else
    (0...(a.size)).each do |i|
      if !((a[i][0] == b[i][0]) && (a[i][1] <= b[i][1]))
        return false
      end
    end
    true
  end
end

n = gets.strip.to_i
n.times do
  a = gets.strip
  b = gets.strip
  puts good(compress(a), compress(b)) ? 'YES' : 'NO'
end

def compress(s)
  a = []
  last = nil
  cnt = 0
  s.split('').each do |c|
    if c == last
      cnt += 1
    else
      a << [c, cnt] if last
      last = c
      cnt = 1
    end
  end
  a << [last, cnt]
end

def good(a, b)
  if a.size != b.size
    false
  else
    a.each.with_index do |e, i|
      if !((e[0] == b[i][0]) && (e[1] <= b[i][1]))
        return false
      end
    end
    true
  end
end

n = gets.strip.to_i
n.times do
  a = gets.strip
  b = gets.strip
  puts good(compress(a), compress(b)) ? 'YES' : 'NO'
end


n = gets.to_i
ans = 0
p = 0
n.times do
  a, b = gets.split.map(&:to_i)
  p += - a + b
  ans = [ans, p].max
end
puts ans

n = gets.to_i
m, sv = 0, 0
n.times do
  a, b = gets.split(' ').map{|_|_.to_i}
  sv += b-a
  m = sv if sv>m
end
puts m

n = max_n = 0
gets.to_i.times do
  x,y = gets.split.map &:to_i
  n = n-x+y
  max_n = n if n > max_n
end
p max_n

stations = Array.new
tram = 0
gets.to_i.times do
  station = gets.split.map(&:to_i)
  tram += station[1] - station[0]
  stations.push(tram)
end
puts stations.max

@stopCount = STDIN.gets.to_i
@minSlot = 0;
@currentSlot = 0;
while (@stopCount > 0)
    stopInfo = STDIN.gets
    passengers_info = stopInfo.split(" ")
    @currentSlot = @currentSlot - passengers_info[0].to_i + passengers_info[1].to_i
    if(@minSlot < @currentSlot)
        @minSlot = @currentSlot
    end
    @stopCount -= 1
end
puts @minSlot

n = gets.to_i

max = 0
tram = 0
n.times do |i|
    s = gets.split.map{|i| i.to_i}
    tram -= s[0]
    tram += s[1]
    if tram > max then
        max = tram
    end
end

puts max

total=0
max=0
k=gets.to_i
k.times{|x|a,b=gets.split.map(&:to_i)
total=total+b-a
max=total if total>max}
print max

#!/usr/bin/ruby

stops = gets.to_i
capacity = 0
passengers = 0
stops.times do
    a, b = gets.split.map(&:to_i)
    passengers = [passengers - a , 0].max
    passengers += b
    capacity = [capacity, passengers].max
end

p capacity

n = gets.to_i

passengers_count = 0
max_passengers_count = 0

n.times do
  outcoming, incoming = gets.split.map(&:to_i)
  passengers_count += incoming - outcoming
  max_passengers_count = max_passengers_count > passengers_count ? max_passengers_count : passengers_count
end

puts max_passengers_count

n = gets.to_i

max = 0
col = 0
while n > 0 do
  a, b = gets.split.map &:to_i
  col += b - a
  max = col if col > max
  n -= 1
end

puts max

def main
  number_of_stops = gets.to_i

  max_people_on_tram = 0
  current_people_on_tram = 0

  until number_of_stops.zero?
    leaving, entering = gets.split.map(&:to_i)

    current_people_on_tram = current_people_on_tram - leaving + entering

    if current_people_on_tram > max_people_on_tram
      max_people_on_tram = current_people_on_tram
    end

    number_of_stops -= 1
  end

  puts max_people_on_tram

end

main if __FILE__ == $PROGRAM_NAME

def get_min_capacity(passangers)
  temp_p = passangers.shift.sum
  # removing the last stop which is not important because all passangers exit the tram
  passangers.pop
  min = temp_p
  passangers.each do |a,b|
    temp_p = (temp_p-a) + b
    min = temp_p if temp_p > min
  end
  min
end

s = gets.to_i
a_p = []
(1..s).each do
  a = gets.split(/\s/).map(&:to_i)
  a_p << a
end
puts get_min_capacity(a_p)

ret = 0
running = 0
gets.to_i.times do
    chu, jin = gets.split.map &:to_i
    running += jin - chu;
    ret = [ret, running].max
end
puts ret

def tram ()
  n = gets.chomp
  capacity = 0
  count = 0
  for i in 0...n.to_i
    stops = gets.chomp
    stop = stops.split(" ")
    count = count + stop[1].to_i - (stop[0].to_i)
    if count > capacity
      capacity = count
    end
  end
  puts capacity
end

tram

def func()
 a=STDIN.readchar;
  b=0;
  while (a!=" "&& a!="\n")
  b=b*10+a.to_i;
  a=STDIN.readchar;
end
return b;
end
class Euler
  n=func;
  kol=0;
  max=0;
  (1..n).each do |i|
    a=func;
    b=func;
    kol-=a;
    kol+=b;
    if (kol>max)
      max=kol;
      end;
  end
  puts max;
 end

res=0; puts gets.to_i.times.map{res+=-gets(' ').to_i+gets.to_i}.max

s = gets.split(" ")
n = s[0].to_i
rez = 0
cur = 0
for i in 1..n
  s = gets.split(" ").to_a
  a = s[0].to_i
  b = s[1].to_i
  cur -= a;
  cur += b;
  rez = [rez, cur].max
end
puts(rez)

n = gets.to_i
rmax = 0
tmax = 0
for i in 0..n-1 do
    a = gets.split(" ").map(&:to_i)
    tmax = tmax - a[0]
    tmax = tmax + a[1]
    if tmax > rmax then
        rmax = tmax
    end
end

puts rmax

n = gets.to_i
answer = 0
max = 0

while(n>0)
    a, b = gets.split.map(&:to_i)
    answer -= a
    answer += b
    if answer > max
        max = answer
    end

    n-=1
end
puts max

def max(a, b)
    return a>b ? a : b
end
n = gets.to_i
ans = 0
tk = 0
while (n > 0)
    a,b = gets.split(' ').map{|s| s.to_i}
    tk = tk - a + b
    ans = max(ans, tk)
    n -= 1
end
puts ans

n, k, s = gets.to_i, 0, 0
n.times do
  a, b = gets.split.map(&:to_i)
  s += -a + b
  k = [s, k].max
end
puts k

max = 0
count = 0
n = gets.chomp.to_i
a = []
b = []
n.times.each do |_|
  a_n, b_n = gets.chomp.split(/ /).map(&:to_i)
  a << a_n
  b << b_n
  count += b_n - a_n
  max = count if count > max
end
puts max

a=[0]
gets.to_i.times{
  i,j=gets.split.map &:to_i
  a<<a[-1]-i+j
}
p a.sort![-1]

n=gets.to_i
a=[0]
n.times do
  i,j=gets.split.map &:to_i
  a<<a[-1]-i+j
end
puts a.sort![-1]

n = gets.to_i

inn = []
outt = []
counter,xounter = 0,0
for i in 0..n-1
  inn[i], outt[i] = gets.split.map(&:to_i)
  counter+=(outt[i]-inn[i])
  xounter = counter if counter > xounter
end

puts xounter

n = gets.strip.to_i
capacity = 0
current_passenger = 0
n.times do
  a, b = gets.strip.split(" ").map(&:to_i)
  current_passenger = current_passenger - a + b
  capacity = [capacity, current_passenger].max
end
puts capacity

gets; input = STDIN.read.split("\n").map {|i| i.split.map! &:to_i }

max, up = 0, 0

input.each do |i|
  up -= i[0]
  up += i[1]
  max = up if max < up
end

print max

capacity, max = 0, 0
gets.to_i.times do
  inp = gets.split.map &:to_i
  capacity += inp[1] - inp[0]
  max = capacity if capacity > max
end
puts max

n = gets.chomp.to_i
maxCap = 0
currentCap = 0

for i in 0...n
	input = gets.chomp.split(' ').map {|item| item.to_i}

	currentCap = currentCap - input[0] + input[1]
	maxCap = currentCap if maxCap < currentCap
end

puts maxCap

ret = 0
cur = 0
for i in 1..gets.to_i do
    a,b = gets.split.map(&:to_i)
    cur += b-a
    if (cur > ret) then ret = cur end
end
puts ret

n = gets.strip.to_i
in_count = max_capacity = 0
n.times do
    a, b = gets.strip.split.map(&:to_i)
    in_count += (b - a)
    max_capacity = [max_capacity, in_count].max
end
puts max_capacity

t = $stdin.readline.split
n = t[0].to_i

m = 0
s = 0
n.times do
    t = $stdin.readline.split
    a, b = t.map(&:to_i)
    s += (b-a)
    m = s if s>m
end

puts m

a=gets.chomp.to_i
ans=0
temp=0
a.times do
k=gets.chomp.split(" ")
temp=temp+k[1].to_i-k[0].to_i
if temp> ans
ans = temp
end
end

puts "#{ans}"

n=0
ans=0
gets.to_i.times{
	a,b=gets.split.map{|e| e.to_i}
	n=n-a+b
	ans=[ans,n].max
}
puts ans

n=gets.to_i

ans=bus=0
n.times{
	a,b=gets.split.map(&:to_i)

	bus=bus-a+b
	ans=[bus, ans].max
}

p ans

class C116A
  q = 0
  m = 0
  gets.to_i.times{
    a, b = gets.split.map &:to_i
    q -= a
    q += b
    q > m && m = q
  }
  puts m
end

n = gets.to_i

s = max = 0
(0..n-1).each{|i|
    a,b=gets.split.map(&:to_i)
    s = s - a + b
    max < s ? max = s : max = max
}
p max

n=gets.to_i
ans = 0
t = 0
n.times do
    a,b = gets.split.map(&:to_i)
    t += b - a
    ans = t if t > ans
end

puts ans

stop_count = gets.chomp.to_i
accum = 0
max = 0
for i in 1..stop_count
  stop = gets.chomp.split ' '

  accum += stop[1].to_i - stop[0].to_i

  if accum > max
    max = accum
  end
end

puts max

stops = gets.chomp.to_i
passengers = []
i = 0
while i < stops
	n = gets.chomp
	passengers << n.split(" ")
	i += 1
end

arr = []
count = 0
passengers.each do |pair|
	if passengers[0] == pair
		count += pair[1].to_i
		arr << count
	else
		count -= pair[0].to_i
		count += pair[1].to_i
		arr << count
	end
end

print arr.max

s=0
res=[]
gets.to_i.times{
  a,b=gets.split.map(&:to_i)
  res<<s=s+(-a+b)
}
puts res.max

n = gets.to_i

max_cnt = 0
cur_cnt = 0
n.times {
  a, b = gets.split(" ").map(&:to_i)
  cur_cnt = cur_cnt - a + b
  max_cnt = cur_cnt if cur_cnt > max_cnt
}

puts max_cnt

n = gets.chomp.to_i
ans = 0
people = 0

n.times do |i|
    a, b = gets.chomp.split(" ").map(&:to_i)
    people = people + b - a
    ans = [ans,people].max
end

puts ans

caps = 0
pass = 0
gets.to_i.times {
  a, b = gets.split.map(&:to_i)
  pass = pass - a + b
  caps = [caps, pass].max
}
puts caps

s = t = 0
gets.to_i.times do
  x, y = gets.split.map &:to_i
  s += y - x
  t = s if s > t
end
puts t

n = gets.chomp.to_i
array = []
passenger = 0
ans = 0
n.times do
	input = gets.chomp.split.map{|x| array.push x.to_i}
end
i = 0
while i < array.length
	passenger = passenger - array[i] + array[i+1]
	if passenger >= ans
		ans = passenger
	end
	i += 2
end
puts ans

num = gets.chomp.to_i
entra  = []
sale = []
a1 = 0
a2 = 0
i = 0
while (i < num)
	line = gets.chomp.split
	sale.push line[0].to_i
	entra.push line[1].to_i
	i = i + 1
end
j = 0
while (j < num)
	a1 = a1 + (entra[j] - sale[j])
	if (a1 > a2)
		a2 = a1
	end
	j = j + 1
end
puts a2.to_s

max, passengers = 0, 0
gets.to_i.times do
  tramio = gets.split.map(&:to_i)
  passengers += tramio[1] - tramio[0]
  max = passengers > max ? passengers : max
end
puts max

n = gets.chomp.to_i

res = 0
act = 0

for i in 1..n
	input = gets.chomp.split(" ")
	a = input[0].to_i
	b = input[1].to_i

	act -= a
	act += b

	if act>res
		res = act
	end
end

puts res

n = gets.to_i
c = 0
max = 0
for i in 1..n do
	a,b = gets.split.map(&:to_i)
	c = c - a + b
	if c > max
		max = c
	end
end

puts max

n = gets.to_i
a = []
b = []
for i in 1..n do
	b = gets.split.map(&:to_i)
	a.push(b)
end

j = 1
c = a[0][1]
max = 0
while j < (n-1) do
	c = c - a[j][0] + a[j][1]
	j = j+1
	if c > max
		max = c
	end
end

puts max

stops = gets.to_i
max = 0
passengers = 0
0.upto(stops - 1) do
  stop = gets.split
  passengers = passengers - stop[0].to_i
  passengers = passengers + stop[1].to_i
  max = passengers if passengers > max
end

puts passengers

def get_min_capacity(passangers)
  temp_p = passangers.shift.sum
  # removing the last stop which is not important because all passangers exit the tram
  passangers.pop
  min = 0
  passangers.each do |a,b|
    temp_p = (temp_p-a) + b
    min = temp_p if temp_p > min
  end
  min
end

s = gets.to_i
a_p = []
(1..s).each do
  a = gets.split(/\s/).map(&:to_i)
  a_p << a
end
puts get_min_capacity(a_p)

def get_min_capacity(passangers)
  min = passangers.shift.sum
  # removing the last stop which is not important because all passangers exit the tram
  passangers.pop

  passangers.each do |a,b|
    temp_p = (min-a) + b
    min = temp_p if temp_p > min
  end
  min
end

s = gets.to_i
a_p = []
(1..s).each do
  a = gets.split(/\s/).map(&:to_i)
  a_p << a
end
puts get_min_capacity(a_p)

def get_min_capacity(passangers)
  temp_p = passangers.shift.sum
  # removing the last stop which is not important because all passangers exit the tram
  passangers.pop
  min = 1
  passangers.each do |a,b|
    temp_p = (temp_p-a) + b
    min = temp_p if temp_p > min
  end
  min
end

s = gets.to_i
a_p = []
(1..s).each do
  a = gets.split(/\s/).map(&:to_i)
  a_p << a
end
puts get_min_capacity(a_p)

def tram ()
  n = gets.chomp
  capacity = 0
  count = 0
  for i in 0...n.to_i
    stops = gets.chomp
    count = count + stops[2].to_i - stops[0].to_i
    if count > capacity
      capacity = count
    end
  end
  puts capacity
end

tram

ret = 0
for i in 1..gets.to_i do
    a,b = gets.split.map(&:to_i)
    if (b-a>0) then ret += b-a end
end
puts ret

a=gets.chomp
res=0
if a.length==1
if a==a.upcase
puts "#{a.downcase}"
else
puts "#{a.upcase}"
end
else
1.upto(a.length-1) do|i|
if a[i]!=a[i].upcase
res=1
end
break if res==1
end
if res==1
puts "#{a}"
elsif (a[0]==a[0].upcase)
puts "#{a.downcase}"
else
a=a.downcase
b=a[0].upcase+a[1..a.length-1]
puts "#{b}"
end
end

n=gets.to_i

ans=bus=0
n.times{
	a,b=gets.split.map(&:to_i)

	bus-=(-a+b)
	ans=[bus, ans].max
}

p ans

n = gets.to_i
 a,b=gets.split.map(&:to_i)
s = max = 0
(0..n-1).each{|i|
    s = s - a[i] + b[i]
    max < s ? max = s : max = max
}
p max

stops = gets.chomp.to_i
passengers = []
i = 0
while i < stops
	n = gets.chomp
	passengers << n.split(" ")
	i += 1
end

arr = []
count = 0
passengers.each do |pair|
	if passengers[0] == pair
		count += pair[1].to_i
	else
		count -= pair[0].to_i
		count += pair[1].to_i
		arr << count
	end
end

print arr.max

caps = 0
gets.to_i.times {
  a, b = gets.split.map(&:to_i)
  caps = [caps, caps - a + b].max
}
puts caps

tramio, results = [], []
gets.to_i.times { tramio << gets.split.map(&:to_i) }
(tramio.size-1).times {|index| results << (tramio[index][1] - tramio[index+1][0] + tramio[index+1][1]) }
puts results.max

n = gets.to_i
a = []
b = []
for i in 1..n do
	b = gets.split.map(&:to_i)
	a.push(b)
end
print a
j = 1
c = a[0][1]
max = 0
while j < (n-1) do
	c = c - a[j][0] + a[j][1]
	j = j+1
	if c > max
		max = c
	end
end

puts max


n = gets.chomp.to_i
a = gets.split(" ").map{|e| e.to_i}
b = a.each_cons(2).map.with_index{|e, i| (e[0] - e[1]).abs * (i & 1 == 0 ? 1 : -1)}
c = b.map{|e| -e}
def get_max_sum(a)
    l = 0
    r = 0
    sum = a[0]
    max = sum
    while r < a.length - 1
        while r < a.length - 1 && sum >= 0
            r += 1
            sum += a[r]
            max = [max, sum].max
        end
        while sum < 0
            sum -= a[l]
            l += 1
            max = [max, sum].max
        end
    end
    while l < a.length
        sum -= a[l]
        l += 1
        max = [max, sum].max
    end
    return max
end
puts [get_max_sum(b), get_max_sum(c)].max

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

s = (0...n-1).map { |i| (a[i] - a[i+1]).abs }

s1 = s.map.with_index { |v, i| i % 2 == 0 ? v : -v }
s2 = s.drop(1).map.with_index { |v, i| i % 2 == 0 ? v : -v }

def solve(arr)
    arr.push(0)
    mn = 0
    (1...arr.length).each { |i| arr[i] += arr[i-1] }
    (0...arr.length).map { |i|
        mn = [mn, arr[i]].min if i % 2 == 1
        arr[i] - mn
    }.max
end

puts [solve(s1), solve(s2)].max

n = gets.to_i
a = gets.split.map(&:to_i)
b = (n - 1).times.map{|i| (a[i + 1] - a[i]).abs * (-1) ** i}
bs = [0]
(n - 1).times{|i| bs[i + 1] = bs[i] + b[i]}
cmi = bs[0]
cmx = bs.max
mx = 0
mi = 0
n.times do |i|
  t = bs[i] - cmi
  mx = [t, mx].max
  cmi = [bs[i], cmi].min

  t = bs[i] - cmx
  mi = [t, mi].min
  cmx = [bs[i], cmx].max
end
p [mx, mi.abs].max

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

s = (0...n-1).map { |i| (a[i] - a[i+1]).abs }

s1 = s.map.with_index { |v, i| i % 2 == 0 ? v : -v }
s2 = s.drop(1).map.with_index { |v, i| i % 2 == 0 ? v : -v }

def solve(arr)
    arr.push(0)
    (1...arr.length).each { |i| arr[i] += arr[i-1] }
    mn = 0
    (0...arr.length).step(2).map { |i|
        mn = [mn, arr[i]] if i % 2 == 1
        arr[i] - mn
    }.max
end

puts [solve(s1), solve(s2)].max


st0 = Time.now
n = gets().to_i
arr = [0] * n
n.times do |i|
  arr[i] = gets().chomp
end
# puts "0- #{Time.now - st0}"
st1 = Time.now
b = Array.new(arr.size) {[0, '']}
# b = Hash.new([0, ''])
# puts "1- #{Time.now - st1}"
t = 0

st2 = Time.now
arr.each_with_index do |e, ind|
  l = true
  r = e[-1] == ')'
  min_i = 0
  min = 1e9
  lst = 0
  # b[ind] = [0, '']
  e.each_char.with_index do |s, indd|
    lst = indd
    b[ind][0] += (s == '(') ? 1 : -1
    l = l && (b[ind][0] >= 0)
    if (b[ind][0] <= min)
      min = b[ind][0]
      min_i = indd
    end
  end
  r = r && min_i == lst && b[ind][0] <= 0
  b[ind][1] += 'l' if l
  b[ind][1] += 'r' if r
  if l && r
    t += 1
  end
end
# puts "2- #{Time.now - st2}"
# puts arr.to_s
# puts b.to_s
p = Hash.new(0)
m = Hash.new(0)
st3 = Time.now
b.each do |e|
  if e[0] < 0 && e[1] != ''
    m[-e[0]] += 1
  end
  if e[0] > 0 && e[1] != ''
    p[e[0]] += 1
  end
end
# puts "3- #{Time.now - st3}"
# puts p
# puts m
res = 0
st4 = Time.now
(p.keys & m.keys).each do |e|
  lp = p[e]
  rm = m[e]
  res += [lp, rm].min
end

# puts "4- #{Time.now - st4}"
# puts "sum- #{Time.now - st0}"
# puts t
puts res + t/2

# Utility
class BracketsSequence
  attr_reader :str, :correct, :clear_open, :clear_close

  def initialize(str)
    @str = str.strip

    @clear_open = 0
    @clear_close = 0

    @str.each_char do |c|
      if c == "("
        @clear_open += 1
      else
        @clear_open == 0 ? (@clear_close += 1) : (@clear_open -= 1)
      end
    end

    @correct = (@clear_open == 0) && (@clear_close == 0)
  end

  def to_s
    @str
  end
end

# Input and processing
n = gets.to_i
seq = Array.new

correct_count = 0
n.times do |i|
  s = BracketsSequence.new(gets)
  if s.correct
    correct_count += 1
  else
    seq << s
  end
end

count = 0
left  = Hash.new(0) # Amount of sequences with only N of opening brackets
right = Hash.new(0) # Amount of sequences with only N of closing brackets
seq.each do |s|
  if s.clear_close == 0
    left[s.clear_open] += 1
  elsif s.clear_open == 0
    right[s.clear_close] += 1
  end
end

left.each { |key, value| count += [value, right[key]].min }

# Output
puts correct_count / 2 + count

def stack_output(s)
    stack = Array.new
    opening_count = 0
    closing_count = 0
    s.split('').each do |char|
        if char == '('
            stack.push(char)
            opening_count += 1
        elsif char == ')'
            unless stack.empty?
                stack.pop
                opening_count -= 1
            else
                closing_count += 1
            end
        end
    end
    if opening_count != 0 && closing_count != 0
        return ['unbalanced', -1]
    elsif opening_count != 0
        return ['open', opening_count]
    elsif closing_count != 0
        return ['close', closing_count]
    else
        return ['balanced', -1]
    end
end

s_arr = []
n = gets.chomp.to_i

0.upto(n-1) do |i|
    s_arr << gets.chomp
end

open_bracket = {}
closing_bracket = {}
balanced_bracket = 0

s_arr.each do |s|
    type, count = stack_output(s)
    case type
    when 'open'
        open_bracket[count] ||= 0
        open_bracket[count] += 1
    when 'close'
        closing_bracket[count] ||= 0
        closing_bracket[count] += 1
    when 'balanced'
        balanced_bracket += 1
    end
end

ac = 0
open_bracket.each do |k, v|
    ac += [v, closing_bracket[k]].min unless closing_bracket[k].nil?
end

ac += balanced_bracket/2
print ac

N = gets.to_i
es = {}

def judge(s)
  t = []
  s.each{ |c|
    if t.size > 0 && t[-1] == "(" && c == ")"
      t.pop
    else
      t << c
    end
  }
  t.size == 0 ? 0 : (t[0] == t[-1] ? (t[0] == "(" ? t.size : -t.size) : nil)
end

N.times {
  s = gets.chomp.split("")
  x = judge(s)
  #p [s.join(""),x]
  next if !x
  es[x] = (es[x] || 0) + 1
}
#p es
p es.keys.select{ |x| x > 0 }.reduce(0){ |a,x| a + [es[x] || 0, es[-x] || 0].min } + (es[0] || 0)/2

st0 = Time.now
n = gets().to_i
arr = []
n.times do
  arr += [gets().chomp]
end
st1 = Time.now
b = Hash.new([0, ''])
# arr.size.times do
#   b += [[0, '']]
# end
# puts "1- #{Time.now - st1}"
t = 0

st2 = Time.now
arr.each_with_index do |e, ind|
  l = true
  r = e[-1] == ')'
  min_i = 0
  min = 1e9
  lst = 0
  b[ind] = [0, '']
  e.each_char.with_index do |s, indd|
    lst = indd
    b[ind][0] += (s == '(') ? 1 : -1
    l = l && (b[ind][0] >= 0)
    if (b[ind][0] <= min)
      min = b[ind][0]
      min_i = indd
    end
  end
  r = r && min_i == lst && b[ind][0] <= 0
  b[ind][1] += 'l' if l
  b[ind][1] += 'r' if r
  if l && r
    t += 1
  end
end
# puts "2- #{Time.now - st2}"
# puts arr.to_s
# puts b.to_s
p = Hash.new(0)
m = Hash.new(0)
st3 = Time.now
b.values.each do |e|
  if e[0] < 0
    m[-e[0]] += 1
  end
  if e[0] > 0
    p[e[0]] += 1
  end
end
# puts "3- #{Time.now - st3}"
# puts p
# puts m
res = 0
st4 = Time.now
(p.keys & m.keys).each do |e|
  lp = p[e]
  rm = m[e]
  res += [lp, rm].min
end

# puts "4- #{Time.now - st4}"
# puts "sum- #{Time.now - st0}"
# puts t
puts res + t/2

n = gets().to_i
arr = []
n.times do
  arr += [gets().chomp]
end
b = []
arr.size.times do
  b += [[0, '']]
end
t = 0
arr.each_with_index do |e, ind|
  l = true
  r = e[-1] == ')'
  min_i = 0
  min = 1e9
  lst = 0
  e.each_char.with_index do |s, indd|
    lst = indd
    b[ind][0] += (s == '(') ? 1 : -1
    l = l && (b[ind][0] >= 0)
    if (b[ind][0] <= min)
      min = b[ind][0]
      min_i = indd
    end
  end
  r = r && min_i == lst
  b[ind][1] += 'l' if l
  b[ind][1] += 'r' if r
  if l && r
    t += 1
  end
end
# puts arr.to_s
# puts b.to_s
p = Hash.new('')
m = Hash.new('')
b.each do |e| #TODO: e[0] == 0
  if e[0] < 0
    m[-e[0]] += e[1]
  end
  if e[0] > 0
    p[e[0]] += e[1]
  end
end
res = 0
(p.keys & m.keys).each do |e|
  lp = p[e].count('l')
  rp = p[e].count('r')
  lm = m[e].count('l')
  rm = m[e].count('r')
  res += [lp, rm].min + [rp, lm].min
end
puts res + t/2

st0 = Time.now
n = gets().to_i
arr = []
n.times do
  arr += [gets().chomp]
end
st1 = Time.now
b = Array.new(arr.size) {[0, '']}
# b = Hash.new([0, ''])
# puts "1- #{Time.now - st1}"
t = 0

st2 = Time.now
arr.each_with_index do |e, ind|
  l = true
  r = e[-1] == ')'
  min_i = 0
  min = 1e9
  lst = 0
  # b[ind] = [0, '']
  e.each_char.with_index do |s, indd|
    lst = indd
    b[ind][0] += (s == '(') ? 1 : -1
    l = l && (b[ind][0] >= 0)
    if (b[ind][0] <= min)
      min = b[ind][0]
      min_i = indd
    end
  end
  r = r && min_i == lst && b[ind][0] <= 0
  b[ind][1] += 'l' if l
  b[ind][1] += 'r' if r
  if l && r
    t += 1
  end
end
# puts "2- #{Time.now - st2}"
# puts arr.to_s
# puts b.to_s
p = Hash.new(0)
m = Hash.new(0)
st3 = Time.now
b.each do |e|
  if e[0] < 0
    m[-e[0]] += 1
  end
  if e[0] > 0
    p[e[0]] += 1
  end
end
# puts "3- #{Time.now - st3}"
# puts p
# puts m
res = 0
st4 = Time.now
(p.keys & m.keys).each do |e|
  lp = p[e]
  rm = m[e]
  res += [lp, rm].min
end

# puts "4- #{Time.now - st4}"
# puts "sum- #{Time.now - st0}"
# puts t
puts res + t/2


$a = [0]
def bs(w,x,y)
		pi = (x+y)/2
		if w <= $a[pi] and w > $a[pi-1]
			return pi
		elsif w > $a[pi]
			return bs(w,pi+1,y)
		else
			return bs(w,x,pi-1)
		end

end
n = gets.to_i
c = 1
gets.split.map(&:to_i).each do |i|
	$a[c] = $a[c-1] + i
	c += 1
end
m = gets.to_i
gets.split.map(&:to_i).each do |i|
	puts bs(i,0,n)
end

n = gets.to_i
a = gets.split.map &:to_i
m = gets.to_i
q = gets.split.map &:to_i
(1...n).each do |i|
    a[i] += a[i - 1]
end
a = [0] + a
n.downto(1).each do |i|
    a[i] = a[i - 1] + 1
end
q.each do |x|
    ans = 1
    l, r = 1, n
    while l <= r do
        mid = (l + r) / 2
        if x >= a[mid] then
            l = mid + 1
            ans = [ans, mid].max
        else
            r = mid - 1
        end
    end
    puts ans
end

n = gets.chomp.to_i
a = gets.chomp.split(" ").map { |e| e.to_i }
m = gets.chomp.to_i
q = gets.chomp.split(" ").map { |e| e.to_i }

hash = {}
c = 1
a.each_with_index { |val, idx|
  val.times {
    hash[c] = idx + 1
    c += 1
  }
}

q.each { |val|
  puts hash[val]
}

n = STDIN.readline.to_i
piles = STDIN.readline.split.map {|s| s.to_i }
total = piles.inject(:+)
index = Array.new(total+1)
pos = 0
piles.each_with_index do |pile, i|
	pile.times do
		pos += 1
		index[pos] = i+1
	end
end
m = STDIN.readline.to_i
results = []
xs = STDIN.readline.split.map {|s| s.to_i }
xs.each {|x| results.push(index[x]) }
puts results.join("\n")

#!/usr/bin/ruby
t = 0
p = []
gets
gets.split(' ').each{|x|
  t += 1
  p << [t] * x.to_i
}
p.flatten!
gets
gets.split(' ').each{|x|
  puts p[x.to_i - 1]
}

gets
arr = gets.split.map &:to_i
gets
best = gets.split.map &:to_i
key = 1
hash = {}
arr.each_with_index do |item, index|
  item.times do |x|
    hash[key] = index + 1
    key += 1
  end
end
best.each { |x| puts hash[x] }

gets
a = gets.split.map(&:to_i)
s = []
temp = 0
a.each.with_index do |i, id|
  s << [temp + 1, temp + i, id + 1]
  temp += i
end
gets
qs = gets.split.map(&:to_i)
qs.each do |q|
  ans = s.bsearch do |x|
    if x[0] <= q && q <= x[1]
      0
    elsif q < x[0]
      -1
    else
      1
    end
  end
  puts ans[2]
end

n = Integer(gets.chomp)
numbers = gets
numbers_split = numbers.split
a = Array.new
for i in 0...n
    a[i] = Integer(numbers_split[i])
end
m = Integer(gets.chomp)
numbers2 = gets
numbers2_split = numbers2.split
q = Array.new
for i in 0...m
    q[i] = Integer(numbers2_split[i])
end

def binary_search(object,a)
    lo = 0
    hi = a.length - 1
    while lo != hi - 1
        mid = lo + (hi - lo) / 2
        if object <= a[mid]
            hi = mid
        elsif object > a[mid]
            lo = mid
        end
    end
    return lo + 1
end

a2 = Array.new
a2[0] = 0
my = 0
for i in 0...n
    my += a[i]
    a2.push(my)
end

for i in 0...m
    puts binary_search(q[i],a2)
end

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

arr = []
for i in (0..n-1)
	if i != 0
		sum = arr[i-1] + a[i]
		arr << sum
	else
		arr << a[i]
	end
end

for i in (0..m-1)
	first = 0
	last = n-1
	mid = (first + last)/2
	while first < last
		if arr[mid] < q[i]
			first = mid+1
		else
			last = mid
		end
		mid = (first + last)/2
	end
	puts first+1
end

=begin
5
2 7 3 4 9
3
1 25 11
=end
n = gets.to_i
ns = gets.split.map(&:to_i)
m = gets.to_i
ms = gets.split.map(&:to_i)
s = []
stack = 1
n.times do |i|
  ns[i].times do
    s.push stack
  end
  stack += 1
end
m.times do |i|
  puts s[ms[i] - 1]
end

n = gets.chomp
m = Array.new
k = 0

gets.split.map do |e|

  k += 1

  for i in 1..e.to_i
    m << k
  end

end

gets.chomp

gets.split.map do |e|

  puts m[e.to_i-1]

end

def read_int_array
    $stdin.readline.split(' ').map(&:to_i)
end

unless Array.method_defined? :bsearch_index
    class Array
        def bsearch_index
            ibegin, iend = 0, length
            found = false
            while ibegin < iend
                imid = ibegin + (iend - ibegin) / 2
                val = at(imid)
                if yield val
                    found = true
                    iend = imid
                else
                    ibegin = imid + 1
                end
            end
            found ? ibegin : nil
        end
    end
end

PILES_AMOUNT = $stdin.readline.to_i

PILES = read_int_array.reduce([]) { |array, pile| array.push (array[-1] or 0) + pile }

WORMS_AMOUNT = $stdin.readline.to_i

result = read_int_array.map { |worm| PILES.bsearch_index { |pile| pile >= worm } + 1 }
puts result

gets
a = gets.split(' ').each_with_index.map { |n, i| [i+1]*n.to_i }.flatten.unshift(0)

gets
gets.split(' ').each do |x|
  puts a[x.to_i]
end

i=0;
j=[];

gets
gets.split(' ').each{|x| i+=1; j << [i] * x.to_i}
j.flatten!
gets
gets.split(' ').each{|x| puts j[x.to_i-1]}

n = gets.to_i
a = gets.split(' ').map(&:to_i)
m = gets.to_i
q = gets.split(' ').map(&:to_i)
(1).upto(n-1) do |i|
  a[i]+=a[i-1]
end
b=[1]
a.each {|ai| b.push(ai+1)}
q.each do |i|
  s,e,mid,best=0,n,0,0
  while s<=e
    mid=s+e>>1
    if(b[mid]<=i)
      best=mid
      s=mid+1
    else
      e=mid-1
    end
  end
  puts best+1
end

n = Integer(gets.chomp)
numbers = gets
numbers_split = numbers.split
a = Array.new
for i in 0...n
    a[i] = Integer(numbers_split[i])
end
m = Integer(gets.chomp)
numbers2 = gets
numbers2_split = numbers2.split
q = Array.new
for i in 0...m
    q[i] = Integer(numbers2_split[i])
end

def binary_search(object,a)
    lo = 0
    hi = a.length - 1
    while lo != hi - 1
        mid = lo + (hi - lo) / 2
        if object <= a[mid]
            hi = mid
        elsif object > a[mid]
            lo = mid
        end
    end
    return mid + 1
end

a2 = Array.new
a2[0] = 0
my = 0
for i in 0...n
    my += a[i]
    a2.push(my)
end

for i in 0...m
    puts binary_search(q[i],a2)
end

n = Integer(gets.chomp)
numbers = gets
numbers_split = numbers.split
a = Array.new
for i in 0...n
    a[i] = Integer(numbers_split[i])
end
m = Integer(gets.chomp)
numbers2 = gets
numbers2_split = numbers2.split
q = Array.new
for i in 0...m
    q[i] = Integer(numbers2_split[i])
end

def binary_search(object,a)
    lo = 0
    hi = a.length - 1
    while lo <= hi
        mid = lo + (hi - lo) / 2
        if object < a[mid]
            hi = mid - 1
        elsif object > a[mid]
            lo = mid + 1
        else object = a[mid]
            return mid
        end
    end
    return mid
end

a2 = Array.new
a2[0] = 0
my = 0
for i in 0...n
    my += a[i]
    a2.push(my)
end

for i in 0...m
    puts binary_search(q[i],a2)
end