#!usr/local/bin/ruby -w

def isPerfectSqr?(a)
	k = Math.sqrt(a).ceil
	if(k*k == a) then return true
	else
		return false
	end
end

n = gets.chomp.to_i

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

ans = -1e7;

arr.each do |a|
	if(a<0 || !isPerfectSqr?(a) ) then ans = [ans,a].max end
end

puts ans

n,*a=$<.read.split.map &:to_i
p a.sort_by(&:-@).find{|e|e<0||Math.sqrt(e).to_i**2!=e}

n = gets.to_i
a = gets.split.map(&:to_i)
a.sort!
k = a.pop
while k >= 0 && (k ** 0.5).to_i ** 2 == k do
  k = a.pop
end
puts k

gets
p gets.split.map(&:to_i).select {|x| x < 0 || Math.sqrt(x).modulo(1) != 0}.max

a = gets.to_i
array = gets.chomp.split(" ")
array = array.map { |n| n.to_i }
x = array.select { |n| n>=0 and Math.sqrt(n)%1!=0 }.max
y = array.select { |n| n<0 }.max
ans = []
if x !=nil
    ans << x
end

if y !=nil
    ans << y
end

if ans.length !=0
    puts ans.max
end

n = gets.to_i
num = gets.chomp.split(' ').map{|n| n.to_i }.sort
address = n -1
while (address > 0) do
  if num[address] == -1
    break
  end
  if ((Math.sqrt(num[address].abs) -  Math.sqrt(num[address].abs).to_i) != 0)
    break
  end
  address = address - 1
end

puts num[address]

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

a.each{|t|
  y = Math.sqrt(t.abs).to_i
  if y*y!=t
    puts t
    exit
  end
}

n = gets.to_i
a = gets.split.map(&:to_i)
a.sort!
k = a.pop
while k > 0 && (k ** 0.5).to_i ** 2 == k do
  k = a.pop
end
puts k

n = gets.to_i
num = gets.chomp.split(' ').map{|n| n.to_i }.sort
address = n -1
while (address > 0) do
  if num[address].abs == 1
    break
  end
  if ((Math.sqrt(num[address].abs) -  Math.sqrt(num[address].abs).to_i) != 0)
    break
  end
  address = address - 1
end

puts num[address]

n = gets.to_i
num = gets.chomp.split(' ').map{|n| n.to_i }.sort
address = n -1
while (address > 0) do
  if ((Math.sqrt(num[address].abs) -  Math.sqrt(num[address].abs).to_i) != 0)
    break
  end
  address = address - 1
end
puts num[address]

n = gets.to_i
num = gets.chomp.split(' ').map{|n| n.to_i }
address = n -1
while (address > 0) do
  if ((Math.sqrt(num[address].abs) -  Math.sqrt(num[address].abs).to_i) != 0)
    break
  end
  address = address - 1
end
puts num[address]

gets
p gets.split.map(&:to_i).select {|x| x >= 0 && Math.sqrt(x).modulo(1) != 0}.max

n=gets.to_i;p gets.split.map(&:to_i).reject{|x|x<0 or Math.sqrt(x).floor**2==x}.sort[-1]

a = gets.to_i
array = gets.chomp.split(" ")
array = array.map { |n| n.to_i }
x = array.select { |n| n>=0 and (Math.sqrt(n)%1!=0 or n==1) }.max
y = array.select { |n| n<0 }.max
ans = []
if x !=nil
    ans << x
end

if y !=nil
    ans << y
end

if ans.length !=0
    puts ans.max
end

a = gets.to_i
array = gets.chomp.split(" ")
array = array.map { |n| n.to_i }
x = array.select { |n| n>=0 and (Math.sqrt(n)%1!=0 or n==1) }.max
y = array.select { |n| n<0 and (Math.sqrt(n*-1)%1!=0 or n==-1) }.max
ans = []
if x !=nil
    ans << x
end

if y !=nil
    ans << y
end

if ans.length !=0
    puts ans.max
end

a = gets.to_i
array = gets.chomp.split(" ")
array = array.map { |n| n.to_i }
x = array.select { |n| n>=0 and Math.sqrt(n)%1!=0 }.max
y = array.select { |n| n<0 and Math.sqrt(n*-1)%1!=0 }.max
ans = []
if x !=nil
    ans << x
end

if y !=nil
    ans << y
end

if ans.length !=0
    puts ans.max
end


n=gets.to_i
mas=gets.split.map &:to_i
i=mas.index(mas.max)+1
mas[mas.index(mas.max)]=-1
puts "#{i} #{mas.max}"

n = gets.to_i
dx = gets.split().map{|i| i.to_i }
i = dx.index(dx.max) + 1
dx.sort!.reverse!
puts i.to_s + " " + dx[1].to_s

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

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

highest_bid = 0
highest_bid_index = 0
second_highest_bid = 0

bids.each_with_index do |bid, index|
  if bid > highest_bid
    second_highest_bid = highest_bid
    highest_bid = bid
    highest_bid_index = index
  elsif bid > second_highest_bid
    second_highest_bid = bid
  end
end

puts "#{highest_bid_index+1} #{second_highest_bid}"

n = gets.to_i
v = gets.split.map(&:to_i)
ans = v.map.with_index.to_a.sort{ |a, b| b[0] <=> a[0] }
puts "#{ans[0][1] + 1} #{ans[1][0]}"

#!/usr/bin/ruby
gets
a=gets.split.map(&:to_i).each_with_index.to_a.sort.reverse
puts "#{a[0].last+1} #{a[1].first}"


n,h = gets.split.map(&:to_f)
for i in 1..n-1
p h*((i/n)**0.5)
end

n, h = gets.chomp.split(" ").map(&:to_f)
b = 1

hh = h / Math.sqrt(n)

(n.to_i - 1).times do |i|
  print(hh * Math.sqrt(i+1), " ")
end
puts

n, h = gets.chomp.split.map(&:to_i)
a = []
(1...n).each { |i|
   a << Math.sqrt(i.to_f / n) * h
}
puts a.map(&:to_s).join(' ')


inp = gets.split(' ')

a = gets.chomp
b = gets.chomp

def match(a,b)
	min_errors_size = 10**9
	min_errors_array = Array.new
	for i in (0..b.size-a.size)
		errors = []
		for j in (0..a.size-1)
			if a[j]!=b[i+j]
					errors << j+1
			end
		end
		if errors.size < min_errors_size
			min_errors_array = errors
			min_errors_size = errors.size
		end
	end
	return min_errors_array
end

ans = match(a,b)

puts ans.size

puts ans.join(' ')

sub_str_length, str_length = gets.split.map(&:to_i)

sub_str = gets.chomp
str = gets.chomp
min_replacements = 1000;
min_replace = *(1..sub_str_length)

def string_diff(str1, str2)
  return [] if (str1 == str2)
  (0..str1.length).map { |i| i + 1 if str1[i] != str2[i] }.compact
end

if str == sub_str
  puts 0
elsif sub_str == ''
  puts str.length
else
  (0..(str_length - sub_str_length)).each do |i|
    replacements = string_diff(str[i, sub_str_length], sub_str)
    min_replace == replacements if i == 0
    if replacements.empty?
      min_replacements = 0
      min_replace = []
      break
    elsif replacements.length < min_replacements
      min_replacements = replacements.length
      min_replace = replacements
    end
  end
  puts min_replacements
  puts min_replace.join(' ')
end

str = gets.split(" ")
n = str[0].to_i; m = str[1].to_i
s = gets.chomp
t = gets.chomp

res = []
ans = 1e5

for i in (0...(m-n+1))
      cnt = 0
      temp = []
      k = i
      for j in (0...n)
            if t[k] != s[j]
                  cnt+=1
                  temp.push(j+1)
            end
            k+=1
      end
      if cnt < ans
            ans = cnt
            res = temp
      end
end

print ans
print "\n"

res.each do |val|
      print "#{val} "
end

def go a, b
  res = []
  for i in 0..(a.length)
    if a[i] != b[i]
      res.push i
    end
  end

  return res
end

n, m = gets.strip.split.map &:to_i
a = gets.strip
b = gets.strip

res = *(1..n)
for i in 0..(m-n)
  curr = go(a, b[i..i+n-1]).map{ |x| x + 1 }
  if curr.length < res.length
    res = curr
  end
end

print res.length.to_s + "\n"
res.each{ |x| print x.to_s + " " }
print "\n"

sub_str_length, str_length = gets.split.map(&:to_i)

sub_str = gets.chomp
str = gets.chomp
min_replacements = 1000;
min_replace = []

def string_diff(str1, str2)
  return [] if(str1 == str2)
  (0..str1.length).map { |i| i + 1 if str1[i] != str2[i] }.compact
end

if str == sub_str
  puts 0
else
  (0..(str_length - sub_str_length)).each do |i|
    replacements = string_diff(str[i, sub_str_length + i - 1], sub_str)
    if replacements.empty?
      min_replacements = 0
      min_replace = []
      break
    elsif replacements.length < min_replacements
      min_replacements = replacements.length
      min_replace = replacements
    end
  end
  puts min_replacements
  puts min_replace.join(' ')
end

sub_str_length, str_length = gets.split.map(&:to_i)

sub_str = gets.chomp
str = gets.chomp
min_replacements = 1000;
min_replace = []

def string_diff(str1, str2)
  return [] if(str1 == str2)
  (0..str1.length).map { |i| i + 1 if str1[i] != str2[i] }.compact
end

if str == sub_str
  puts 0
else
  (0..(str_length - sub_str_length)).each do |i|
    replacements = string_diff(str[i, sub_str_length], sub_str)
    if replacements.empty?
      min_replacements = 0
      min_replace = []
      break
    elsif replacements.length < min_replacements
      min_replacements = replacements.length
      min_replace = replacements
    end
  end
  puts min_replacements
  puts min_replace.join(' ')
end

sub_str_length, str_length = gets.split.map(&:to_i)

sub_str = gets.chomp
str = gets.chomp
min_replacements = 1000;
min_replace = []

def string_diff(str1, str2)
  return [] if(str1 == str2)
  (0..str1.length).map { |i| i + 1 if str1[i] != str2[i] }.compact
end

if str == sub_str
  puts 0
else
  (0..(str_length - sub_str_length)).each do |i|
    replacements = string_diff(str[i, sub_str_length + i], sub_str)
    if replacements.empty?
      min_replacements = 0
      min_replace = []
      break
    elsif replacements.length < min_replacements
      min_replacements = replacements.length
      min_replace = replacements
    end
  end
  puts min_replacements
  puts min_replace.join(' ')
end

sub_str_length, str_length = gets.split.map(&:to_i)

sub_str = gets.chomp
str = gets.chomp
min_replacements = 1000;
min_replace = []

def string_diff(str1, str2)
  return [] if(str1 == str2)
  puts "=====#{str1}========#{str2}===="
  (0..str1.length).map { |i| i + 1 if str1[i] != str2[i] }.compact
end

if str == sub_str
  puts 0
else
  (0..(str_length - sub_str_length)).each do |i|
    replacements = string_diff(str[i, sub_str_length], sub_str)
    if replacements.empty?
      min_replacements = 0
      min_replace = []
      break
    elsif replacements.length < min_replacements
      min_replacements = replacements.length
      min_replace = replacements
    end
  end
  puts min_replacements
  puts min_replace.join(' ')
end

sub_str_length, str_length = gets.split.map(&:to_i)

sub_str = gets.chomp
str = gets.chomp
min_replacements = 1000;
min_replace = []

def string_diff(str1, str2)
  (0..str1.length).map { |i| i + 1 if str1[i] != str2[i] }.compact
end

(0..(str_length - sub_str_length)).each do |i|
  replacements = string_diff(str[i, sub_str_length + i - 1], sub_str)
  if replacements.length < min_replacements
    min_replacements = replacements.length
    min_replace = replacements
  end
end

puts min_replacements
puts min_replace.join(' ')

sub_str_length, str_length = gets.split.map(&:to_i)

sub_str = gets.chomp
str = gets.chomp
min_replacements = 1000;
min_replace = []

def string_diff(str1, str2)
  (0..str1.length).map { |i| i + 1 if str1[i] != str2[i] }.compact
end

(0..(str_length - sub_str_length)).each do |i|
  replacements = string_diff(str[i, sub_str_length + i - 1], sub_str)
  if replacements.length < min_replacements
    min_replacements = replacements.length
    min_replace = replacements
  end
end

puts min_replacements
p min_replace.join(' ')

inp = gets.split(' ')

n = inp.first.to_i
m = inp.last.to_i

a = gets.chomp
b = gets.chomp

def match(a,b)
	min_errors_size = 10**9
	min_errors_array = Array.new
	for i in (0..b.size-1)
		errors = []
		for j in (0..a.size-1)
			if a[j]!=b[i+j]
					errors << j+1
			end
		end
		if errors.size < min_errors_size
			min_errors_array = errors
			min_errors_size = errors.size
		end
	end
	return min_errors_array
end

ans = match(a,b)

puts ans.size

puts ans.join(' ')


n = gets.to_i
arr = []
b_arr = []
n.times do
	arr << gets.split(" ").map(&:to_i)
	b_arr << arr[-1][1]
end
arr.sort!
# max_h = {}
# x = arr.chunk{|x| x[0]}.each do |a|
# 	max_h[a[0]] = a[1].collect{|e| e[1]}.max
# end
max = 0
arr.each do |a|
	if max <= a[1]
		max = a[1]
	else
		max = a[0]
	end
end
puts "#{max}"

n = gets.to_i
a = []
n.times do
	a << gets.split.map(&:to_i)
end
a.sort!

prev = 0
n.times do |i|
	prev = a[i][1] >= prev ? a[i][1] : a[i][0]
end
puts prev

n = gets.to_i
a = []
n.times do
  a << gets.chomp.split.map(&:to_i)
end
a.sort!
d = 0
for i in 0...n
  a[i].sort!
  if a[i][0] >= d
    s = a[i][0]
  elsif a[i][1] >= d
    s = a[i][1]
  end
  d = s
end
puts d

n, k = STDIN.readline.split.map {|s| s.to_i }
pairs = []
n.times do
	a, b = STDIN.readline.split.map {|s| s.to_i }
	pairs.push([a, b])
end
pairs.sort!
pos = 0
pairs.each do |late, early|
	if early >= pos
		pos = early
	else
		pos = late
	end
end
puts pos

n = gets.chomp.to_i;
arr = Array.new(n);

n.times { |x|
  arr[x] = gets.chomp.split(' ').map(&:to_i);
}
arr.sort!;
pre = -1;

arr.each { |x, y|
  if (pre <= y)
    pre = y;
  else
    pre = x;
  end
}
puts pre;

n=gets.to_i
arr=[]
n.times{|e|
	x=gets.split.map{|e| e.to_i}
	arr<<x
}
arr.sort!
ans=1

arr.each{|e|
	if e[1]<ans
		ans=e[0]
	else
		ans=e[1]
	end
}
puts ans

# coding: utf-8

# if __FILE__ == $0
# end
Day = Struct.new(:a, :b)
n = gets.to_i
days = []
n.times {
    a, b = gets.split.map(&:to_i)
    days << Day.new(a, b)
}
days.sort! { |d1, d2|
    if d1.a != d2.a
        d1.a - d2.a
    else
        d1.b - d2.b
    end
}
# 이전에 풀었던 아이디어가 완전히 틀린 건 아니었음.
# 단, 무조건 마지막 아이템을 참고해서 풀면 언젠가 틀린다.
# days 는 a(원 응시일), b(조기 응시일) 오름차순으로 정렬되어있다.
# 따라서 a 날짜에 따라 각 시험을 응시하면 순서대로 완성되나 최소가 되기 어렵다. (특이한 케이스가 있음)
# 따라서 b의 정보를 참고해서 시험을 응시하게 되는데,
# min_day <= day.b 가 유지되는 경우는
# days의 전체 b정렬상태가 감소하지 않는 추세로 표현된 상태이다.
# 이때는 계속 b의 날짜를 따라 시험을 봐도 되므로, days.last.b 가 성립한다.
# 만약에 b에서 흐름이 깨질 경우가 문제인데,
# 정렬 순서에서 벗어나서 시험을 봐야하므로, b의 날짜에 시험을 볼 수 없다.
# b의 날짜에 볼 경우, 성적표 기재 순서가 바뀌게 됨. 어쩔 수 없이 a 날짜를 택해야한다.
# 그리고 그 날짜 기준으로 b의 날짜에 봤을 때 성적표 기재 순서가 유지되는지 확인해야한다.
# 정렬 흐름에서 깨진 시험의 a날짜는 마지노선이 된다.

min_day = 0
days.each { |day|
    if min_day <= day.b
        min_day = day.b
    else
        min_day = day.a
    end
}

puts min_day

n = Integer(gets)
a = []
nums = []
for i in 0...n
    a[i] = []
    nums[i] = []
    nums[i] = gets.chomp.split
    a[i][0] = Integer(nums[i][0])
    a[i][1] = Integer(nums[i][1])
end

a = a.sort_by{|x,y|[x,y]}
best = -1
for i in 0...n
    if best <= a[i][1]
        best = a[i][1]
    else
        best = a[i][0]
    end
end
print best

n = gets.chomp.to_i
arr = []
for i in (0..n-1)
	arr << gets.chomp.split.map(&:to_i)
end

arr = arr.sort_by{|x| x}

x = arr[0].min
for i in (1..n-1)
	if arr[i].min >= x
		x =  arr[i].min
	else
		x = arr[i].max
	end
end

print x

# coding: utf-8

# if __FILE__ == $0
# end
Day = Struct.new(:a, :b)
n = gets.to_i
days = []
n.times {
    a, b = gets.split.map(&:to_i)
    days << Day.new(a, b)
}
days.sort! { |d1, d2|
    if d1.a != d2.a
        d1.a - d2.a
    else
        d1.b - d2.b
    end
}
bday_broken = false
bprev = 0
days.each { |day|
    if bprev <= day.b
        bprev = day.b
    else
        bday_broken = true
    end
}

if bday_broken
    puts days.last.a
else
    puts days.last.b
end

# coding: utf-8

# if __FILE__ == $0
# end
Day = Struct.new(:a, :b)
n = gets.to_i
days = []
n.times {
    a, b = gets.split.map(&:to_i)
    days << Day.new(a, b)
}
days.sort! { |d1, d2|
    if d1.a != d2.a
        d1.a - d2.a
    else
        d1.b - d1.b
    end
}
bday_broken = false
bprev = 0
days.each { |day|
    if bprev <= day.b
        bprev = day.b
    else
        bday_broken = true
    end
}

if bday_broken
    puts days.last.a
else
    puts days.last.b
end

n = Integer(gets)
a = []
nums = []
for i in 0...n
    a[i] = []
    nums[i] = []
    nums[i] = gets.chomp.split
    a[i][0] = Integer(nums[i][0])
    a[i][1] = Integer(nums[i][1])
end

a = a.sort_by{|x,y|x}
best = -1
for i in 0...n
    if best <= a[i][1]
        best = a[i][1]
    else
        best = a[i][0]
    end
end
print best

n = Integer(gets)
a = []
nums = []
for i in 0...n
    a[i] = []
    nums[i] = []
    nums[i] = gets.chomp.split
    a[i][0] = Integer(nums[i][0])
    a[i][1] = Integer(nums[i][1])
end
pointer = 1
for i in 0...n-1
    if a[i][0] == a[i + 1][0]
        pointer = 1
    else
        pointer = 0
        break
    end
end
best = -1
if pointer == 0
    a = a.sort_by{|x,y|x}
else
    a = a.sort_by{|x,y|y}
end
for i in 0...n
    if best <= a[i][1]
        best = a[i][1]
    else
        best = a[i][0]
    end
end
print best

n = gets.chomp.to_i
arr = []
for i in (0..n-1)
	arr << gets.chomp.split.map(&:to_i)
end

arr = arr.sort_by{|x,y| x&&y}

x = arr[0].min
for i in (1..n-1)
	if arr[i].min >= x
		x =  arr[i].min
	else
		x = arr[i].max
	end
end

print x

n = gets.chomp.to_i
arr = []
for i in (0..n-1)
	arr << gets.chomp.split.map(&:to_i)
end

arr = arr.sort_by{|x,y| y&&x}

x = arr[0].min
for i in (1..n-1)
	if arr[i].min >= x
		x =  arr[i].min
	else
		x = arr[i].max
	end
end

print x

n = gets.chomp.to_i
arr = []
for i in (0..n-1)
	arr << gets.chomp.split.map(&:to_i)
end

arr = arr.sort_by{|x,y| y&&x}
if arr[0].min <= arr[n-1].min
	print arr[n-1].min
else
	print arr[n-1].max
end

n = gets.to_i
arr = []
b_arr = []
n.times do
	arr << gets.split(" ").map(&:to_i)
	b_arr << arr[-1][1]
end
arr.sort!
max_h = {}
x = arr.chunk{|x| x[0]}.each do |a|
	max_h[a[0]] = a[1].collect{|e| e[1]}.max
end
max = 0
max_h.each do |k,v|
	if max <= v
		max = v
	else
		max = k
	end
end
puts "#{max}"

n = gets.to_i
arr = []
b_arr = []
n.times do
	arr << gets.split(" ").map(&:to_i)
	b_arr << arr[-1][1]
end
arr.sort!
max_h = {}
x = arr.chunk{|x| x[0]}.each do |a|
	max_h[a[0]] = a[1].collect{|e| e[1]}.max
end
max = 0
max_h.each do |k,v|
	if v >= max
		max = v
	else
		max = k
	end
end
puts "#{max}"

n = gets.to_i
arr = []
b_arr = []
n.times do
	arr << gets.split(" ").map(&:to_i)
	b_arr << arr[-1][1]
end
arr.sort!
x = arr.chunk{|x| x[0]}.to_a.last[1].collect{|e| e[1]}
z = x.max
if b_arr.all?{|e| z >= e}
	ans = z
else
	ans = arr[-1][0]
end
puts ans

n = gets.to_i
z = []
n.times {
  z << gets.chomp.split.map(&:to_i)
}

z.sort! { |x, y| x[0] <=> y[0] }
x = z[0][1]
(1...n).each do |i|
  x = z[i][1] >= x ? z[i][1] : z[i][0]
end
puts x


h = {}
# ?a.upto(?z) { |c| h[c] = 0 }
s = STDIN.readline.chop
s.each_char do |c|
	if h[c] == nil ;
		h[c] = 0
	end
	h[c] += 1
end

ans = 0
flag = true
s = STDIN.readline.chop
s.each_char do |c|
	if h[c] == nil ;
		flag = false
	elsif h[c] > 0 ;
		h[c] -= 1
		ans += 1
	end
end

print flag ? ans : -1

#!/usr/bin/ruby
h=Hash.new(0)
gets.chomp.each_char{|c|h[c]+=1}
g=Hash.new(0)
gets.chomp.each_char{|c|g[c]+=1}
r=0
g.each{|k,v|
	if h[k]==0
		p -1
		exit
	end
	r+=[h[k],v].min
}
p r

a,b,ans=Array.new(26,0),Array.new(26,0),0
gets.chomp.split('').each{|i| a[i.ord-97]+=1}
gets.chomp.split('').each{|i| b[i.ord-97]+=1}
26.times do |i|
	if a[i]==0 and a[i]!=b[i]
		puts "-1"
		exit
	end
end
26.times{|i| ans+=[a[i],b[i]].min}
puts ans

s1 = gets.chomp.split("")
s2 = gets.chomp.split("")
count1 = Hash.new(0)
s1.each do |a|
	count1[a] += 1
end

count2 = Hash.new(0)
s2.each do |a|
	count2[a] += 1
end

ans = true
s = 0
count2.each do |k,v|
	if count1[k] != 0
		s += [count1[k],v].min
	else
		ans = false
		break
	end
end
puts ans ? s : "-1"

c1, c2 = {}, {}
gets.chomp.each_byte{|c| c1[c]=c1[c].nil? ? 1 : c1[c]+1}
gets.chomp.each_byte{|c| c2[c]=c2[c].nil? ? 1 : c2[c]+1}
sum = 0
c2.each do |k,v|
	if c1[k].nil?
		puts -1
		exit 0
	end
	sum += [v, c1[k]].min
end
puts sum

a = gets.chomp
b = gets.chomp
cnt1 = Hash.new
cnt2 = Hash.new
for x in a.scan /./
  if cnt1[x] == nil
    cnt1[x] = 0
  end
  cnt1[x] += 1
end
for x in b.scan /./
  if cnt2[x] == nil
    cnt2[x] = 0
  end
  cnt2[x] += 1
end
ans = 0
cnt2.each_pair do |k, v|
  if cnt1[k] == nil
    puts -1
    exit
  end
  ans += [v, cnt1[k]].min
end
puts ans

h = {}
?a.upto(?z) { |c| h[c] = 0 }
s = STDIN.readline.chop
s.each_char { |c| h[c] += 1 }

ans = 0
s = STDIN.readline.chop
s.each_char do |c|
	if h[c] > 0
		h[c] -= 1
		ans += 1
	end
end
ans = -1 if ans == 0
print ans

t = gets.to_i
t.times do
	n = gets.to_i
	s = 0
	i = 1
	ans = -1
	(1..n).each do |i|
		s += i
		if s >= n
			ans = i
			s -= i
			break
		end
	end
	row,col = ans,n - s

	sum = row + 1
	numerator = sum - col
	denominator = col

	numerator,denominator = denominator,numerator if row.even?

	puts "TERM #{n} IS #{numerator}/#{denominator}"
end

c1, c2 = {}, {}
gets.chomp.each_byte{|c| c1[c]=c1[c].nil? ? 1 : c1[c]+1}
gets.chomp.each_byte{|c| c2[c]=c2[c].nil? ? 1 : c2[c]+1}
sum = 0
c1.each{|k,v| sum+=[v,c2[k].nil? ? 0 : c2[k]].min}
sum = -1 if sum == 0
puts sum


require 'openssl'
N = gets.chomp.to_i
A = gets.split.map(&:to_i)
M = 1000000007
sign = 1
until (N - 1) % 4 == 0
  na = Array.new(N - 1, 0)
  (N - 1).times { |i| na[i] = A[i] + sign * A[i + 1]; sign *= -1 }
  N, A, na = N - 1, na, A
end
f = (1..N / 2 + 1).each_with_object([1]) { |i, o| o << o[-1] * i % M }
vf = (-(N / 2)..0).each_with_object([f[N / 2 + 1].to_bn.mod_exp(M - 2, M)]) { |i, o| o << o[-1] * (-i + 1) % M }.reverse
ans = 0
(0...N).step(2).each { |i| ans = (ans + A[i] * f[N / 2] * vf[i / 2] * vf[N / 2 - i / 2]) % M }
ans += M if ans < 0
p ans


m,n=gets.split.map(&:to_i)
f,n,m=0,m,n if m%2>z=0
s=[[i=1,j=1]]
v="s.unshift [n,m,z=1,n<2?1:j]if j%2>0||n<2&&m>2;n<2&&j=1"
loop{s<<[i+=1,j]while i<n
break eval v if m==j
s<<[i,j+=1]
s<<[i-=1,j]while i>2
break eval v if m==j
s<<[i,j+=1]}
s<<[1,j+1]until 0>j-=1
f||s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}
puts z,s.map{|i|i*" "}

n,m=gets.split.map(&:to_i)
f,n,m=0,m,n if n%2==0
s=[[i=1,j=1]]
z = 0
loop do
    while i < n
        s << [i+=1,j]
    end
    if m == j
        if n == 1
            s.unshift [1,m,1,1]
            s << [1,1]
        else
            s.unshift [n,m,1,j=m]
            if i > 1
                s << [1,j]
                while j > 1
                    s << [1,j-=1]
                end
            end
        end
        z = 1
        break
    end
    s << [i,j+=1]
    while i > 2
        s << [i-=1,j]
    end
    if m == j
        if n == 1
            if m > 2
                z = 1
                s.unshift [1,m,1,1]
            end
            s << [1,1]
        else
            #s.unshift [n,m,1,j=m]
            if i > 1
                s << [1,j]
                while j > 1
                    s << [1,j-=1]
                end
            end
        end
        break
    end
    s << [i,j+=1]
end
p z
if f
    s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}
end
s.each{|i|puts i*" "}

def generate_teleport_path(n, m)
  path = []
  columns = [ (1 .. m).to_a.reverse, (1 .. m).to_a ]
  (1 .. n).each do |row|
    index = row % 2
    columns[index].each { |col| path.push([row, col]) }
  end
  path.push([1, 1])
  return path
end

def generate_path(n, m)
  if n % 2 == 1
    result = generate_path(m, n)
    return result.map { |v| v.reverse }
  end
  path = []
  (1 .. m).each { |col| path.push([1, col]) }
  columns = [ (2 .. m).to_a.reverse, (2 .. m).to_a ]
  (2 .. n).each do |row|
    index = row % 2
    columns[index].each { |col| path.push([row, col]) }
  end
  n.downto(1) { |row| path.push([row, 1]) }
  return path
end

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

teleports = []

if n == 1 and m == 1
  path = [[1, 1], [1, 1]]
elsif (n == 1 and m == 2) or (n == 2 and m == 1)
  path = [[1, 1], [n, m], [1, 1]]
elsif n % 2 == 1 and m % 2 == 1 or n == 1 or m == 1
  teleports = [[n, m, 1, 1]]
  path = generate_teleport_path(n, m)
else
  path = generate_path(n, m)
end

puts teleports.size
teleports.each { |port| puts port.join(' ') }
path.each { |pair| puts pair.join(' ') }

n,m=gets.split.map(&:to_i)
f,n,m=0,m,n if n%2==0
s=[[i=1,j=1]]
z = 0
loop do
    while i < n
        s << [i+=1,j]
    end
    if m == j
        z = 1
        s.unshift [n,m,1,j=m]
        break
    end
    s << [i,j+=1]
    while i > 2
        s << [i-=1,j]
    end
    if m == j
        break
    end
    s << [i,j+=1]
end
s << [1,j] if i>1
while j > 1
    s << [1,j-=1]
end
p z
if f
    s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}
end
s.each{|i|puts i*" "}

n,m=gets.split.map(&:to_i)
f,n,m=0,m,n if n%2==0
s=[[i=1,j=1]]
z = 0
loop do
    while i < n
        s << [i+=1,j]
    end
    if m == j
        if n == 1
            s.unshift [1,m,1,1]
            s << [1,1]
        else
            s.unshift [n,m,1,j=m]
            if i > 1
                s << [1,j]
                while j > 1
                    s << [1,j-=1]
                end
            end
        end
        z = 1
        break
    end
    s << [i,j+=1]
    while i > 2
        s << [i-=1,j]
    end
    if m == j
        if n == 1
            s.unshift [1,m,1,1]
            s << [1,1]
        else
            #s.unshift [n,m,1,j=m]
            if i > 1
                s << [1,j]
                while j > 1
                    s << [1,j-=1]
                end
            end
        end
        z = 1
        break
    end
    s << [i,j+=1]
end
p z
if f
    s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}
end
s.each{|i|puts i*" "}

n,m=gets.split.map(&:to_i)
f,n,m=0,m,n if n%2==0
s=[[i=1,j=1]]
z = 0
loop do
    while i < n
        s << [i+=1,j]
    end
    if m == j
        z = 1
        s.unshift [n,m,1,j=m]
        break
    end
    s << [i,j+=1]
    while i > 2
        s << [i-=1,j]
    end
    if m == j
        break
    end
    s << [i,j+=1]
end
s << [1,j]
while j > 1
    s << [1,j-=1]
end
p z
if f
    s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}
end
s.each{|i|puts i*" "}

n,m=gets.split.map(&:to_i)
f,n,m=0,m,n if n%2==0
s=[[i=1,j=1]]
z = 0
loop do
    while i < n
        s << [i+=1,j]
    end
    if m == j
        if n == 1
            z = 1
            s.unshift [1,m,1,1]
            s << [1,1]
        else
            z = 1
            s.unshift [n,m,1,j=m]
            if i > 1
                s << [1,j]
                while j > 1
                    s << [1,j-=1]
                end
            end
        end
        z = 1
        break
    end
    s << [i,j+=1]
    while i > 2
        s << [i-=1,j]
    end
    if m == j
        if n == 1
            z = 1
            s.unshift [1,m,1,1]
            s << [1,1]
        else
            #s.unshift [n,m,1,j=m]
            if i > 1
                s << [1,j]
                while j > 1
                    s << [1,j-=1]
                end
            end
        end
        z = 1
        break
    end
    s << [i,j+=1]
end
p z
if f
    s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}
end
s.each{|i|puts i*" "}

n,m=gets.split.map(&:to_i)
f,n,m=0,m,n if n%2==0
s=[[i=1,j=1]]
z = 0
loop do
    while i < n
        s << [i+=1,j]
    end
    if m == j
        if n == 1
            s.unshift [1,m,1,1]
            s << [1,1]
        else
            s.unshift [n,m,1,j=m]
            if i > 1
                s << [1,j]
                while j > 1
                    s << [1,j-=1]
                end
            end
        end
        z = 1
        break
    end
    s << [i,j+=1]
    while i > 2
        s << [i-=1,j]
    end
    if m == j
        if n == 1
            s.unshift [1,m,1,1]
            s << [1,1]
        else
            s.unshift [n,m,1,j=m]
            if i > 1
                s << [1,j]
                while j > 1
                    s << [1,j-=1]
                end
            end
        end
        z = 1
        break
    end
    s << [i,j+=1]
end
p z
if f
    s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}
end
s.each{|i|puts i*" "}

n,m=gets.split.map(&:to_i)
f,n,m=0,m,n if n%2==0
s=[[i=1,j=1]]
z = 0
loop do
    while i < n
        s << [i+=1,j]
    end
    if m == j
        if n == 1
            s.unshift [1,m,1,1]
            s << [1,1]
        else
            s.unshift [n,m,1,j=m]
            if i > 1
                s << [1,j]
                while j > 1
                    s << [1,j-=1]
                end
            end
        end
        z = 1
        break
    end
    s << [i,j+=1]
    while i > 2
        s << [i-=1,j]
    end
    if m == j
        if n == 1
            z = 1
            s.unshift [1,m,1,1]
            s << [1,1]
        else
            #s.unshift [n,m,1,j=m]
            if i > 1
                s << [1,j]
                while j > 1
                    s << [1,j-=1]
                end
            end
        end
        break
    end
    s << [i,j+=1]
end
p z
if f
    s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}
end
s.each{|i|puts i*" "}

n,m=gets.split.map(&:to_i)
f,n,m=0,m,n if n%2==0
s=[[i=1,j=1]]
z = 0
loop do
    while i < n
        s << [i+=1,j]
    end
    if m == j
        z = 1
        s.unshift [m,n,j=m,1]
        break
    end
    s << [i,j+=1]
    while i > 2
        s << [i-=1,j]
    end
    if m == j
        break
    end
    s << [i,j+=1]
end
s << [1,j]
while j > 1
    s << [1,j-=1]
end
p z
if f
    s.map!{|i|i.each_slice(2).to_a.flat_map &:reverse}
end
s.each{|i|puts i*" "}

def generate_teleport_path(n, m)
  path = []
  columns = [ (1 .. m).to_a.reverse, (1 .. m).to_a ]
  (1 .. n).each do |row|
    index = row % 2
    columns[index].each { |col| path.push([row, col]) }
  end
  path.push([1, 1])
  return path
end

def generate_path(n, m)
  if n % 2 == 1
    result = generate_path(m, n)
    return result.map { |v| v.reverse }
  end
  path = []
  (1 .. m).each { |col| path.push([1, col]) }
  columns = [ (2 .. m).to_a.reverse, (2 .. m).to_a ]
  (2 .. n).each do |row|
    index = row % 2
    columns[index].each { |col| path.push([row, col]) }
  end
  n.downto(1) { |row| path.push([row, 1]) }
  return path
end

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

teleports = []

if n == 1 and m == 1
  path = [[1, 1], [1, 1]]
elsif n % 2 == 1 and m % 2 == 1 or n == 1 or m == 1
  teleports = [[n, m, 1, 1]]
  path = generate_teleport_path(n, m)
else
  path = generate_path(n, m)
end

puts teleports.size
teleports.each { |port| puts port.join(' ') }
path.each { |pair| puts pair.join(' ') }


gets
w = {}
while(ln = gets)
  dst, _, src = ln.downcase.split(' ')
  w[dst] = (w[src] || 1) + 1
end
puts w.values.max

@data = $stdin.read.split
n = @data.shift.to_i
result = 0
h = {}
(@data.size / 3).times do
	a, rep, b = @data.shift, @data.shift, @data.shift
	raise 'wrong data' unless rep == 'reposted'
	h[b.downcase] ||= 1
	h[a.downcase] = h[b.downcase] + 1
	result = [result, h[a.downcase]].max
end
puts result

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(name1, name2)
    if vertices[name1].nil? then
      vertices[name1] = List.new(name2, nil)
    else
      vertices[name1] = List.new(name2, vertices[name1])
    end
  end

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

  # def print_verteces
  #   puts vertices.keys.join(" ")
  # end
end

def dfs(graph, name)
  current_vertex = graph.vertices[name]
  if current_vertex.nil?
    return 1
  else
    max = 1
    while !current_vertex.nil?
      max = [max, dfs(graph, current_vertex.element)].max
      current_vertex = current_vertex.next_elem
    end
  end
  return max + 1
end

reposts = Graph.new({})
n = gets.strip.to_i
n.times do |i|
  str = gets.strip.split(" ")
  reposts.add_edge(str.last.downcase, str.first.downcase)
end
# reposts.print_edges
puts dfs(reposts, "polycarp")

rlevels = Hash.new

rlevels["polycarp"] = 1

repcount = gets.strip.to_i

repcount.times do |i|
    string = gets.strip.downcase.split(" ")
    name1 = string[0]
    name2 = string[2]
    rl = rlevels[name2]
    rlevels[name1] = rl+1
end

p rlevels.values.max

h = Hash.new

n = gets.to_i

h['polycarp'] = 1
ans = 1

n.times do |i|
    a, b, c = gets.split.map {|s| s.downcase }
    h[a] = h[c] + 1

    ans = [ans, h[a]].max
end

puts ans

amount =  gets.chomp.to_i
$names = []

amount.times {
	repost = gets.chomp.split(' ')
	$names.push([repost[0].downcase, repost[2].downcase])
}

$max = 0

def dfs(name, length)
	$names.each { |x|
		if x[1] == name
			dfs(x[0], length+1)
		end
	}

	if length > $max
		$max = length
	end
end

dfs("polycarp", 0)

puts $max + 1

gets
w = {}
while(ln = gets)
  dst, src = ln.downcase.split(' ') - ['reposted']
  w[dst] = (w[src] || 1) + 1
end
puts w.values.max

h=Hash.new(0)

gets.to_i.times do |x|
  a=gets.chomp.split
  n1=a[0].downcase
  n2=a[2].downcase
  h[n2]=1 if x==0
  h[n1]=h[n2]+1
end

p h.values.max

n = gets.sub("\n","").to_i
h = {"polycarp"=>1}
n.downto(1) do
	a,b = gets.sub("\n","").split(" reposted ").map{|i| i.downcase}
	h[a] = h[b] + 1
end
max = 0
h.values.each{|i| max = i if(i>max)}
puts max

@inf = 1000000000
e = gets.strip.to_i

depth = {}
depth['polycarp'] = 1

e.times do |i|
  x, _, y = gets.strip.split.map(&:to_s).map(&:downcase)
  depth[x] = (depth[y] || 0) + 1
end

puts depth.values.max

i = gets.to_i
seq = 0
reposts = Array.new()
owners = Array.new().push("polycarp")
reposters = Array.new()
1.upto(i) { reposts.push(gets.split(' ').map { |e| e.downcase  } ) }
while owners.count > 0
	owners.each do |owner|
		reposts.each do |repost|
			reposters<< repost.first if repost.last == owner
		end
	end
	owners = reposters.clone()
	reposters.clear()
	seq+=1
end
puts seq


require 'set'
require 'rational'
require 'mathn'
include Math
$stdin = File.open("./input.txt", "r") if ENV["USER"] == "new"
# ====================================

n = gets.to_i

if n%2!=0 then
  print -1
  exit
end

n.downto(1) do |index|
  print index," "
end

n = gets.to_i
if n.odd?
	puts -1
else
	p = (1..n).each_slice(2).map{|a| [a[1],a[0]]}.flatten
	puts p.join(" ")
end

l = (1..gets.to_i).to_a
i = 1
while i < l.size
	l[i - 1], l[i] = l[i], l[i - 1]
	i += 2
end

if l.each_with_index.all? { |x, i| l[x - 1] == i + 1 and x != i + 1 }
	puts l.join(" ")
else
	puts -1
end

n = gets.to_i

if n.odd?
	puts -1
else
	p = Array.new(n) { |i, v| v = i + 1 }
	(n / 2).times do |i|
		p[i * 2], p[i * 2 + 1] = p[i * 2 + 1], p[i * 2]
	end
	puts p.join ' '
end

n = gets.to_i
if n%2==0
    puts (1..n).to_a.select{|x| x%2!=0}.map{|x| [x+1,x]}.flatten.join(' ')
else
    p -1
end

a=gets.chomp.to_i
if a%2==1
puts "-1"
else
a.downto(1) do |i|
printf"#{i} "
end
end

n = gets.to_i
if n%2 == 0
  (n/2).times {|x| print x*2 + 2, ' ', x*2 + 1, ' '}
else
  puts -1
end

#!/usr/bin/env ruby
$stdin.readlines.each do |line|
    n = line.strip.to_i
    if n % 2 == 0
        nums = (1..n).to_a
        i = 0
        while i < n-1
            t = nums[i]
            nums[i] = nums[i+1]
            nums[i+1] = t
            i += 2
        end
        puts nums.join(' ')
    else
        puts '-1'
    end
end

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

n = Integer(gets.chomp)
if n.even?
  a = []
  for i in (1..n).step(2)
    a << i + 1 << i
  end
  puts(a * ' ')
else
  puts -1
end

n = gets.to_i
if n % 2 == 1
  puts -1
else
  puts (1..n).each_slice(2).map{|x,y| [y,x]}.inject(:+).map(&:to_s).join(' ')
end

sin = STDIN
sout = STDOUT
# sin = File.open("test.in", "r")
# sout = File.open("test.out", "w")

n = sin.readline.to_i
sout.puts(n.even? ? (1..n).to_a.reverse.to_s.gsub(",", "")[1...-1] : -1)

jom = gets.to_i

if jom%2 == 1
       print "-1"
else
  print "2 1 "
  jom.downto(3) { |n| print n.to_s + " " }
end

#!/usr/bin/ruby
n=gets.to_i
puts n%2==1 ? -1 : [*1..n].each_slice(2).map{|a,b|[b,a]}*' '

n = gets.to_i
puts n.odd? ? -1 : [*1..n].each_slice(2).map(&:reverse)

n=gets.to_i
if n%2!=0
puts -1
else
	a=(1..n).to_a
	i=0
	while i<n do
		a[i],a[i+1]=a[i+1],a[i]; i+=2; end
	print a.join(" ")
	end

n = gets.to_i

if n % 2 == 1
  puts "-1"
  exit
end

for i in 1..n/2
  print "#{i*2} #{i*2 - 1} "
end

a=1
n=gets.to_i
half=n/2

if n==2
	puts '2 1'
elsif n%2==0
	half.times{|i|
	print a+1,' ',a
	if i!=(half-1) then
		print ' '
	else
		print "\n"
	end
	a+=2}
else
	puts '-1'
end

def main(n)
  ans = []
  if n % 2 == 0
    1.step(n, 2) do |i|
      ans << i + 1
      ans << i
    end
  else
    ans << -1
  end

  return ans
end

n = gets.chomp.to_i
ans = main(n)
puts ans.join(" ")

n = gets.to_i
if n%2 == 1
  print "-1"
else
  for i in 1..n
    if i%2 == 1
	  print (i+1).to_s + " "
	else
	  print (i-1).to_s + " "
	end
  end
end

n = gets.to_i
if n%2==1
	p -1
	exit
end
(n/2).times do |x|
	print "#{2*x+2} #{2*x+1} "
end

def permute(n)
  return -1 if n % 2 == 1
  a = (1..n).to_a

  i = 0
  p = []
  while i < n-1
    p[i] = a[i+1]
    p[i+1] = a[i]
    i +=2
  end
  p.join(' ')
end

n = gets.to_i
puts permute(n)

n=gets.to_i
a=[0]
if n&1==1
	puts "-1"
	exit
end
for i in 1..n
	a.push(i)
end
for k in 1..(n/2)+2
	if 2*(k)<=n
		a[2*k],a[(2*k)-1]=a[(2*k)-1],a[2*k]
	end
end
for i in 1..n
	print a[i].to_s+' '
end
puts

n = gets.to_i
if n.odd?
  puts (-1)
  exit
else
  a = (1..n).to_a
  (0...n).select { |x| x.even? }.map { |x| a[x], a[x+1] = a[x+1], a[x]}
  puts a*' '
end

n = gets.to_i
if n % 2 == 1 then
    puts -1
else
    (n / 2).times do |i|
        print (2 * (i + 1)).to_s + " " + (2 * (i + 1) - 1).to_s
        if i == n - 1 then print "\n" else print " " end
    end
end

n = gets.to_i

if n.odd?
  puts -1
else
  ans = []
  (1..n).each do |i|
    if i.odd?
      ans << i + 1
    else
      ans << i - 1
    end
  end
  puts ans.join(" ")
end

n = gets.chomp.to_i
if n.even?
    array = (1..n).to_a
    index = 0
    while index < n
        array[index], array[index + 1] = array[index + 1], array[index]
        index += 2
    end
    puts array.join(" ")
else
    puts "-1"
end

n = gets.to_i
if n % 2 == 0
  (1..n/2).each { |i|
    print 2*i, ' ', 2*i-1, ' '
  }
else
  puts -1
end

n=gets.to_i
if n%2==1 then
	puts -1
else
	arr=[]
	2.step(n,2){|i|
		arr<<(i)
		arr<<(i-1)
	}
	puts arr*" "
end

n = gets.to_i
if n % 2 == 1
  puts "-1"
  exit
end
a = -1
n.times do |i|
  if i % 2 == 0
    a += 3
  else
    a -= 1
  end
  print a
  if n != i-1
    print " "
  else
    print "\n"
  end
end

jom = gets.to_i

if jom == 1 or jom == 3
  puts "-1"
else
  print "2 1 "
  jom.downto(3) { |n| print n.to_s + " " }
end

def main(n)
  return [-1] if n == 1

  ans = []
  if n % 2 == 0
    1.step(n, 2) do |i|
      ans << i + 1
      ans << i
    end
  else
    1.step(n, 3) do |i|
      ans << i + 1
      ans << i + 2
      ans << i
    end
  end

  return ans
end

n = gets.chomp.to_i
ans = main(n)
puts ans.join(" ")

def permute(n)
  return -1 if n == 1
  a = (1..n).to_a
  # Swapping elements with their consecutives
  (1..n-1).each {|i| t = a[i-1]; a[i-1] = a[i]; a[i] = t}
  a.join(' ')
end

n = gets.to_i
puts permute(n)

def permute(n)
  return -1 if n == 1
  a = (1..n).to_a

  i = 0
  p = []
  while i < n-1
    p[i] = a[i+1]
    p[i+1] = a[i]
    i +=2
  end
  p.join(' ')
end

n = gets.to_i
puts permute(n)

n = gets.chomp.to_i
if n > 1
    array = (1..n).to_a
    index = 0
    while index < n
        array[index], array[index + 1] = array[index + 1], array[index]
        index += 2
    end
    puts array.join(" ")
else
    puts "-1"
end

n=gets.to_i
if n==1 then
	puts -1
else
	puts (1..(n-1)).to_a.unshift(n)*" "
end

n=gets.to_i
half=n/2

if n==1 then
	puts '-1'
elsif n==2
	puts '2 1'
else
	half.downto(1){|i|
	print i,' '
	}

	(n).downto(half+1){|i|
	print i
	print (if i!=(half+1) then
		' '
	else
		"\n"
	end)
	}
end

n=gets.to_i
half=n/2

if n==2
	puts '2 1'
elsif n%2==0
	half.downto(1){|i|
	print i,' '
	}

	(n).downto(half+1){|i|
	print i
	print (if i!=(half+1) then
		' '
	else
		"\n"
	end)
	}
else
	puts '-1'
end


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

d1acc = 0
current = nil
ans = nil
a.each_with_index do |x, i|
  change, div = x
  if div == 1
    d1acc += change
  elsif div == 2
    ans = 'Impossible' if i > 0 && a[i - 1][1] == 1 && d1acc >= 0
    d1acc = 0
    current = 1899 unless current
  end
  if current
    current += change
    if current < 1900 && i < n - 1 && a[i + 1][1] == 1
      current = 1900
    elsif current >= 1900 && i < n - 1 && a[i + 1][1] == 2
      current = 1899
    end
  end
end
if current
  try = current
  a.reverse.each do |change, div|
    try -= change
    ans = 'Impossible' if try < 1900 && div != 2 || try >= 1900 && div != 1
  end
else
  ans = 'Infinity'
end
puts ans || current

#!/usr/bin/ruby
ma=Float::INFINITY
mi=-ma
s=0
gets.to_i.times{
	c,d=gets.split.map &:to_i
	if d==1
		mi=[mi,1900-s].max
	else
		ma=[ma,1899-s].min
	end
	s+=c
}
puts ma==Float::INFINITY ? :Infinity : ma>=mi ? ma+s : :Impossible

def solve(a)
  current = nil
  a.each do |change, div|
    current ||= 1899 if div == 2
    if current
      current = 1900 if div == 1 && current < 1900
      current = 1899 if div == 2 && current >= 1900
      current += change
    end
  end

  if current
    a.reverse_each.inject(current) do |try, (change, div)|
      try -= change
      return 'Impossible' if div == 1 && try < 1900 || div == 2 && try >= 1900
      try
    end
  else
    return 'Infinity'
  end

  return current
end

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

puts solve(a)


require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
t = gets.chomp.to_i
t.times do
  n,r = gets.chomp.split.map(&:to_i)
  if n > r
    num = r
    puts num * (num+1) / 2
  else
    num = n - 1
    puts num * (num+1) / 2 + 1
  end
end
#######

t = gets.to_i
t.times do
	n, r = gets.split.map &:to_i
	x = 0
	k = [r, n-1].min
	x += [0, (k+1)*k/2].max
	x += 1 if r >= n
	p x
end

n = gets.chomp.to_i
n.times do
    n, r = gets.chomp.split(" ").map(&:to_i)
    if n > r
        ans =  r * (1 + r)
        puts ans / 2
    elsif n <= r
        ans = (n-1) * n
        puts ans / 2 + 1
    end
end

# this code is just to observe speed
t = gets.chomp.to_i
a = Array.new(t)
for i in 0..t-1 do
  n,r = gets.chomp.split.map(&:to_i)
  if n > r
    num = r
    a[i] = num * (num+1) / 2
  else
    num = n - 1
    a[i] = num * (num+1) / 2 + 1
  end
end

puts a.join("\n")


s = STDIN.readline.strip

def fail
  puts -1
  exit
end

result = []
sum = 0
s.each_char do |ch|
  if ch == '('
    sum += 1
  elsif ch == ')'
    sum -= 1
    fail if sum < 0
  else
    result.push(1)
    sum -= 1
    fail if sum < 0
  end
end
result[-1] += sum

pos = s.index('(', s.rindex('#'))
if pos != nil
  tail_sum = 0
  s[pos..-1].each_char do |ch|
    if ch == '('
      tail_sum += 1
    else
      tail_sum -= 1
    end
  end
  fail if tail_sum > 0
end

puts result.join("\n")

def solve(s)
    to = s.count {|c| c == '('}
    tc = s.count {|c| c == ')'}
    tp = s.count {|c| c == '#'}
    co = 0
    cc = 0
    cp = 0
    res = []
    i = 0
    r = tc
    s.each do |c|
        if c == '#'
            cp += 1
            if cp < tp
                res << 1
                cc += 1
            else
                if cc >= to
                    return nil
                end
                diff = to - cc - r
                return nil if diff == 0
                res << diff
                cc += diff
            end
        elsif c == '('
            co += 1
        elsif c == ')'
            cc += 1
            r -= 1
        end
        if cc > co
            #puts "#{i}: #{co}  #{cc}"
            return nil
        end
        i += 1
    end
    return res
end
s = STDIN.gets.chomp.split(//)
res = solve(s)
if not res
    puts "-1"
else
    res.each do |r|
        puts r
    end
end


# Consider an example:
# a = 5
# Then the values from 0 to ... are:
# 0 1 2 3 4   1 2 3 4 5   2 3 4 5 6   3 4 5 6 7
# And so, if we are looking for the maximum, we should only consider:
# (1) Within each group, the farthest value to the right in the group that is
# available in the range l .. r
# (2) The last two groups.
# The reason for (2) is that, if a number is not in the last two groups, then
# it must be small than the last item in the second-to-last group.
# The last group might not be complete, which is why we need to check the second-
# to-last group as well.
# Answer is either :
# - Largest number in set (last item in last group) OR
# - Largest number i such that i % a = a - 1.     The mod of this is higher than the first choice.
#
# It's sufficient to check these two numbers:
# r
# r / a * a - 1, but only if it's in the range l .. r
#

gets.to_i.times do
  l,r,a = gets.split.map { |i| i.to_i }

  f = lambda {|i| i / a + i % a }
  last_of_second_last = r / a * a - 1
  if last_of_second_last.between?(l, r) then
    best = [f.call(r), f.call(last_of_second_last)].max
  else
    best = f.call(r)
  end
  puts(best)
end

n = STDIN.gets.chomp.to_i
n.times.each do
  l,r,a = STDIN.gets.chomp.split(" ").map(&:to_i)
    puts [r/a+r%a,(r-r%a-1)/a+(r-r%a-1)%a].max if r-r%a-1>=l
    puts r/a+r%a if r-r%a-1<l
end

def f(x,a)
  return(x/a + x % a)
end

def process(l, r, a)

  return [f(l, a),f(r,a)].max if r-l<=1
  m = (l + r ) / 2

  #puts "#{l} #{m} #{r} f#{f(l,a)} f#{f(m,a)} f#{f(r,a)}"
  #func = [l,m,r]
  #func = [l,m,r].sort!{|x,y| f(x,a) <=> f(y,a)}.drop(1).sort!
  #puts(" xxx #{func} xxx")
  fl=f(l,a)
  fm=f(m,a)
  fr=f(r,a)

  if fm>fl
    return process(m,r,a)
  elsif fm>fr
    return process(l,m,a)
  elsif fl>fr
    return process(l,m,a)
  else
    return process(m,r,a)

  end

  #if f(m,a)>=f(l,a)
#
  #  return process(m,r,a)
  #elsif f(m,a)>=f(r,a)
#
  #  return process(l,m,a)
  #else
  #  return process(m,r,a)
  #end
end

n = STDIN.gets.chomp.to_i
n.times.each do
  l,r,a = STDIN.gets.chomp.split(" ").map(&:to_i)
  #puts "#### #{l} #{r} #{a} ####"
  puts("#{process(l,r,a)}")
end

#n = STDIN.gets.chomp.to_i
#n.times.each do
#  l,r,a = STDIN.gets.chomp.split(" ").map(&:to_i)
#
#  puts ([r-(r%a)-1,l].max ... r+1).to_a.map { |value| (value/a) + value%a }.max
#end

#352038877 421606206 705339697
#
#l=352038877
#r=421606206
#a=705339697
#
#puts([r-a-1,l].max ... r+1)
#puts("count : #{([r-a-1,l].max ... r+1).count}\n")
#puts( "r%a : #{r%a}")
#
#([r-(r%a)-1,l].max ... r+1).to_a.each { |x|
#  puts "#{x}/#{a} + #{x}%#{a}  #{x/a} #{x%a} = #{x/a+x%a}"
#}
#

#r-(r/a)-1
#12-(1)-1
#a=8
#l=0
#(1...12).to_a.each do |i|
#  x=l+i
#
#  puts "#{x}/#{a} + #{x}%#{a}  #{x/a} #{x%a} = #{x/a+x%a}"
#end
#
#a=10
#l=90
#r=110
#x=r
#while x % a != a-1 and x >= l
#  x-=1
#end
#puts x

#l=5
#r=8
#a=4
##x=r
#puts ([r-(r/a),l].max ... r+1).to_a.map { |value| (value/a) + value%a }.max

# l 5
# r 8
# a 4
# x 7
#
# 4 = 7/4 + 7%4
#
# 10/2 + 10%2  5 0 = 0
# 11/2 + 11%2  5 1 = 1
#
#
#
#
#  x/a + x%a = Y

def f(x,a)
  return(x/a + x % a)
end

def process(l, r, a)

  return [f(l, a),f(r,a)].max if r-l<=1
  m = (l + r ) / 2

  if f(m,a)>=f(l,a)

    return process(m,r,a)
  elsif f(m,a)>=f(r,a)

    return process(l,m,a)
  else
    return process(m,r,a)
  end
end

n = STDIN.gets.chomp.to_i
n.times.each do
  l,r,a = STDIN.gets.chomp.split(" ").map(&:to_i)

  puts(process(l,r,a))
end

n = STDIN.gets.chomp.to_i
n.times.each do
  l,r,a = STDIN.gets.chomp.split(" ").map(&:to_i)
  puts ([a-l-1,l].max ... r+1).map { |value| (value/a) + value%a }.max
end

n = STDIN.gets.chomp.to_i
n.times.each do
  l,r,a = STDIN.gets.chomp.split(" ").map(&:to_i)
  puts (a-l ... r+1).map { |value| (value/a) + value%a }.max
end


n = gets.to_i
a = []

def find_ans(arr)
  i = 1
  j = i + 1
  while arr[i] + arr[j] != arr.last - arr[0]
    if j == i + 1
      j += 1
    else
      i += 1
    end
  end
  [arr[0], arr[i], arr[j]]
end

(0..n-1).each do |x|
	q = gets.chomp.split().map { |e| e.to_i  }
  p
	a.append(find_ans(q))
end

a.each do |x|
 puts x.join(' ')
end

t = gets.to_i
ans = []
t.times do
  b = gets.split.map(&:to_i)
  a = [b[0],b[1]]
  if b[0]+b[1] == b[2]
    a << b[3]
  else
    a << b[2]
  end
  ans << a
end
ans.each do |arr|
  puts arr.join(" ")
end

testcases = Integer(gets.chomp)
resultados = []

for i in 0..testcases-1
    arreglo = gets.chomp
    b = arreglo.split(" ")
    numeroAConstruir = b[6].to_i
    validar = true
    finalPrincipal = false
    aumentoPrincipal = 0
    finalSecundario = false
    aumentoSecundario = 1
    finalTerceario = false
    aumentoTercerario = 2
    while validar
        if finalTerceario
            finalTerceario = false
            aumentoSecundario+=1
            if aumentoSecundario == 5
                finalSecundario = true
            end
            aumentoTercerario = aumentoSecundario + 1
        end
        if finalSecundario
            finalSecundario = false
            aumentoPrincipal += 1
            aumentoSecundario = aumentoPrincipal + 1
            aumentoTercerario = aumentoSecundario + 1
        end
            b1 = b[aumentoPrincipal].to_i
            b2 = b[aumentoSecundario].to_i
            b3 = b[aumentoTercerario].to_i
        if b1+b2+b3 == numeroAConstruir
            resultados.push(b1.to_s+" "+b2.to_s+" "+b3.to_s)
            break
        end
        aumentoTercerario +=1
        if aumentoTercerario == 6
            finalTerceario = true
        end
    end
end
puts resultados

n = gets.to_i
a = []

def find_ans(arr)
  i = 1
  j = i + 1
  while arr[i] + arr[j] != arr.last - arr[0]
    if j == i + 1
      j += 1
    else
      i += 1
    end
  end
  [arr[0], arr[i], arr[j]]
end

(0..n-1).each do |x|
	q = gets.chomp.split().map { |e| e.to_i  }
  p
	a.append(find_ans(q))
end

a.each do |x|
 p x.map(&:inspect).join(' ')
end

n = gets.to_i
a = []

def find_ans(arr)
  i = 1
  j = i + 1
  while arr[i] + arr[j] != arr.last - arr[0]
    if j == i + 1
      j += 1
    else
      i += 1
    end
  end
  [arr[0], arr[i], arr[j]]
end

(0..n-1).each do |x|
	q = gets.chomp.split().map { |e| e.to_i  }
  p
	a.append(find_ans(q))
end

a.each do |x|
 p x
end


n = gets.chomp.to_i
a = gets.chomp.split(" ").map{|i| i.to_i}
mbits = gets.chomp

length = mbits.length
max = 0
length.times.each do |i|
  max += a[i] if mbits[i] == '1'
end

default = max
sub_sum = 0
i = 0
while i < n do
  if mbits[i] == '1'
    last_sum = default + sub_sum - a[i]
    max = last_sum if last_sum > max
  else
    sub_sum += a[i]
  end
  i += 1

end

puts max

n = gets.to_i
a = gets.chomp.split(" ").map{|i| i.to_i}
b = gets.chomp.split("").map{|i| i.to_i}

S = []
T = []
s = 0
S[0] = a[0]
(1..n-1).each do |i|
  S[i] = S[i-1] + a[i]
end

max = 0
j = n-1
T[n] = 0
while j>= 0 do
    if b[j] == 0
     T[j] = T[j+1]
    else
        T[j] = T[j+1] + a[j]
    end
    j -= 1
end

max = T[0]

(1..n-1).each do |i|
    if b[i] == 1
        s = S[i-1] + T[i+1]
    end
    if s > max
        max = s
    end
end

puts max


array = gets.split(" ")
n = array.shift
big_max = -999999999999999999999
shuzu = gets.split(" ")
sum=[]
sum[0] = -9999999999999999999999
for i in 0..n.to_i-1 do
    sum[i] = sum[i-1] if i>0
    temp = array[0].to_i*shuzu[i].to_i
    if temp > sum[i]
        sum[i] = temp;
    end
end

sum2 = []
sum2[0] = -9999999999999999999999
for i in 0..n.to_i-1 do
    sum2[i] = sum2[i-1] if i>0
    temp = sum[i]+array[1].to_i*shuzu[i].to_i
    if temp > sum2[i]
            sum2[i] = temp;
    end
end

#p sum
#p sum2
for i in 0..n.to_i-1
    max = sum2[i]+array[2].to_i*shuzu[i].to_i
    big_max=max if max>big_max
end
print big_max

n, p, q, r = gets.split.map{|x| x.to_i}
arr = gets.split.map{|x| x.to_i}

minus = arr.min
plus  = arr.max

p p * (p < 0 ? minus : plus) + q * (q < 0 ? minus : plus) + r * (r < 0 ? minus : plus)

n, p, q, r = gets.split.map{|x| x.to_i}
arr = gets.split.map{|x| x.to_i}

INF = 10**18

dp = [[-INF, -INF, -INF]]

n.times do |i|
	dp << [0, 0, 0]
	dp[i + 1][0] = [dp[i][0], p * arr[i]].max
	dp[i + 1][1] = [dp[i][1], dp[i + 1][0] + q * arr[i]].max
	dp[i + 1][2] = [dp[i][2], dp[i + 1][1] + r * arr[i]].max
end

ans = -INF
n.times{|i| ans = [ans, dp[i + 1][2]].max}

p ans

array = gets.split(" ")
n = array.shift
big_max = -9999999999999999999
shuzu = gets.split(" ")
sum=[]
sum[0] = -9999999999999999999
for i in 0..n.to_i-1 do
    sum[i] = sum[i-1] if i>0
    temp = array[0].to_i*shuzu[i].to_i
    if temp > sum[i]
        sum[i] = temp;
    end
end

sum2 = []
sum2[0] = -9999999999999999999
for i in 0..n.to_i-1 do
    sum2[i] = sum2[i-1] if i>0
    temp = sum[i]+array[1].to_i*shuzu[i].to_i
    if temp > sum2[i]
            sum2[i] = temp;
    end
end

p sum
p sum2
for i in 0..n.to_i-1
    max = sum2[i]+array[2].to_i*shuzu[i].to_i
    big_max=max if max>big_max
end
print big_max


def icpc_baloons(str, n)
  map = {}
  str.chars.each do |s|
    if map.key?(s)
      map[s] += 1
    else
      map[s] = 2
    end
  end
  ans = 0

  map.each do |k, v|
    ans += v
  end
  ans
end
t = gets.chomp.to_i
inputs = []
(0..t-1).each do
  n = gets.chomp.to_i
  str = gets.chomp
  inputs.push([str, n])
end

inputs.each do |input|
  puts icpc_baloons(input[0], input[1])
end

#!/usr/bin/env ruby

numtests = gets.chomp.to_i

(1..numtests).each do |numline|
  ballons = 0
  solved = []
  n = gets.chomp.to_i
  l = gets.chomp
  (0..n-1).each do |i|
    c = l[i]
    if solved.include?(c)
      ballons += 1
    else
      ballons += 2
      solved << c
    end
  end
  puts ballons
end

require 'set'

t = gets.to_i

t.times do
  gets
  ln = gets.chomp
  s = Set.new
  b = 0
  ln.each_char do |c|
    b += 1 if not s.include? c
    s << c
    b += 1
  end
  puts b
end


n=gets.split[0]
n=n.bytes.to_a
k=0
l=n.length
ans=0
(l-1).downto(0){|i|
    if i==0 && k==0 then
        ans+=1
    else
        if n[i]+k==49 then
            ans+=1
            k=1
        elsif n[i]+k==50 then
            k=1
        else
            k=0
        end
        ans+=1
    end
}
ans+=k
puts ans-1

n=gets.split[0]
n=n.bytes.to_a
k=0
l=n.length
ans=0
(l-1).downto(0){|i|
    if i==0 && k==0 then
        ans+=1;k=1
    else
        if n[i]+k==49 then
            ans+=1
            k=1
        elsif n[i]+k==50 then
            k=1
        else
            k=0
        end
        ans+=1
    end
}
ans+=k
puts ans-1

#=================================
require 'prime'
require 'set'
require 'matrix'
require 'tsort'
include Math

if ARGV.include?("ONLINE_JUDGE")
	$stdin = File.open("./input.txt", "r")
	ARGV.delete("ONLINE_JUDGE")
end
#=================================

b=gets.strip

if b.length==1 && b=="1"
	puts 0
	exit
end

ans=count=0

loop do
	if b[-1]=="1"
		count+=1
		i=b.length-1

		while b[i]=="1"
			b[i]="0"
			i-=1
			count+=1
		end

		b[i]="1" if i>=0
		b=b[0..i]
	else
		i=b.length-1

		while b[i]=="0"
			count+=1
			i-=1
		end

		b=b[0..i]
	end

	ans=count if b.length!=0
	break if b.length==0
end

puts ans


n, vb, vs = gets.split(/\s+/).map{|x| x.to_i}
x = gets.split(/\s+/).map{|x| x.to_i}
xu, yu = gets.split(/\s+/).map{|x| x.to_i}

res = 0
rest = 0.0
resd = 0.0
(1...n).each {|i|
  dx = (x[i] - xu).to_f
  dy = (0 - yu).to_f
  d = Math.sqrt(dx * dx + dy * dy)
  t = x[i].to_f / vb + d / vs
  if res == 0 || t < rest || (t == rest && d < resd) then
    res = i
    rest = t
    resd = d
  end
}
p res + 1

#� ������ ������ ���� ��� ����� �����: 2???n? ??100, 1???vb,?vs? ??1000. �� ������ ������ ���� n  ��������������� ����� ����� � ������� �����������
#: ���������� xi ��������� ����� i. �������������, ��� x1  ����� ����, � xn? ??105.
#� ������� ������ ���� ���������� ������������, ����� ����� xu � yu, �� ������ �� ����������� 105.

n, vb, vs = gets.split(' ').map{|z|z.to_i}
crd = gets.split(' ').map{|z|z.to_i}
xu,yu = gets.split(' ').map{|z|z.to_i}

min = 105000000
ru = 105000000
res=0
crd[1..-1].each_with_index{|xi,i|
  mru = (xu-xi)*(xu-xi)+yu*yu
  d = (Math.sqrt(xi*xi)*vs+Math.sqrt(mru)*vb)
  if (d < min)||((d==min)&&(mru < ru)) then
    min = d
    res = i+1
    ru = mru
  end
}

puts res+1

n,vb,vs = gets.chomp.split(/ /).map!{|x| x.to_i}
ar = gets.chomp.split(/ /).map!{|x| x.to_i}
xu,yu = gets.chomp.split(/ /).map!{|x| x.to_i}

mint = 0
mind = 0
idx = 0
for i in 1..n-1
	wk = (ar[i]-xu).abs
	wkt = ar[i].to_f/vb+Math.sqrt(wk*wk + yu*yu)/vs
	if idx == 0 || mint > wkt
		mint = wkt
		mind = wk
		idx = i+1
	elsif mint == wkt
		if mind > wk
			mint = wkt
			mind = wk
			idx = i+1
		end
	end
end
puts idx

n, vb, vs = gets.split.map{|i| i.to_f}
x = gets.split.map{|i| i.to_i}
xu, yu = gets.split.map{|i| i.to_i}
ans = [1e100, -1, -1]
1.upto(x.length - 1) do |i|
	d = (xu - x[i]) ** 2 + yu ** 2
	t = x[i] / vb + Math.sqrt(d) / vs
	ans = [t, d, i] if t < ans[0] - 1e-6 || (t < ans[0] + 1e-6 && d < ans[1])
end
p ans[2] + 1

#

n,vb,vs=STDIN.gets.chomp.split
xn=STDIN.gets.chomp.split
xu,yu=STDIN.gets.chomp.split
n=n.to_i
vb=vb.to_i
vs=vs.to_i
xu=xu.to_i
yu=yu.to_i
for i in 0...xn.length do xn[i]=xn[i].to_i end
idx=0
min_t=-1
min_u=-1
for i in 1...xn.length
  d=Math::sqrt((xu-xn[i])*(xu-xn[i])+yu*yu)
  t=1.0*(xn[i]-xn[1])/vb
  t+=1.0*d/vs
  if min_t==-1
    min_t=t
    min_u=d
    idx=i
  elsif t<min_t
    min_t=t
    min_u=d
    idx=i
  elsif t==min_t && d<min_u
    min_u=d
    idx=i
  end
end
puts(idx+1)

n, Vb, Vs = gets.split.collect { |x| x.to_i }
i = gets.split.collect { |x| x.to_i }
Xu, Yu = gets.split.collect { |x| x.to_i }

min_time = -1
min_dist = -1
best_stop = -1

1.upto(i.size - 1) do |x|
	dist = Math.sqrt((Xu - i[x])**2 + Yu**2)
	time = i[x] * 1.0 / Vb + dist * 1.0 / Vs

	if min_time == -1 or time < min_time
		min_time = time
		min_dist = dist
		best_stop = x + 1
	elsif time == min_time and dist < min_dist
		min_dist = dist
		best_stop = x + 1
	end
end

puts best_stop

# -*- coding: utf-8 -*-
def dist (x0, y0, x1, y1)
  dx = (x1 - x0).to_f
  dy = (y1 - y0).to_f
  return Math.sqrt(dx * dx + dy * dy)
end

n,vb,vs = gets.split.map(&:to_i)
bus = gets.split.map(&:to_i)
xu,yu = gets.split.map(&:to_i)

time = Array.new

for i in 2..n do
  x = bus[i-1]
  time[i] = x.to_f / vb.to_f + dist(x, 0, xu, yu) / vs;
end

min_time = time[2..n].min;

for i in 2..n do
  if min_time == time[i] then
    ans = i
  end
end

print ans
puts

include Math
fst=gets.split
n=fst[0].to_i
vb=fst[1].to_f
vs=fst[2].to_f
bus_stops=gets.split.map{ |x| x.to_f}
univ = gets.split.map{ |x| x.to_f}
t = nil
res = nil
bu = nil
(n-1).times do |i|
  bx = bus_stops[i+1]
  l = sqrt((univ[0]-bx)**2 + (univ[1])**2)
  temp_t = (bx/vb)+(l/vs)
  if t==nil || t>temp_t
    t=temp_t
    bu = l
    res = i+2
  elsif t==temp_t
    if bu>l
      t=temp_t
      bu = l
      res = i+2
    end
  end
end
puts res

def dist(x1,y1,x2,y2)
	Math.sqrt(((x2-x1)**2) + ((y2-y1)**2))
end

n,v_b,v_s = gets.split(" ").map(&:to_i)
arr = gets.split(" ").map(&:to_i)
univ_x,univ_y = gets.split(" ").map(&:to_i)

ans = {}

arr[1..-1].each_with_index do |a,i|
	bus_time = a/v_b.to_f
	# puts "h33 #{bus_time}"
	walk_time = (dist(univ_x,univ_y,a,0))/v_s
	# puts "#{[bus_time + walk_time,walk_time]}"
	ans[[bus_time + walk_time,walk_time]] = i

end
# puts "#{ans}"

key = ans.keys.min

puts "#{ans[key]+2}"

#$stdin = File.open('in.txt', 'r')
@n,@vb,@vs = gets.split(/\s+/).map {|x| x.to_i}
@stopes = gets.split(/\s+/).map {|x| x.to_i}
@xu,@yu = gets.split(/\s+/).map {|x| x.to_i}

@stopes.unshift(0)
# a = 2
# b = @n
#
def compute(index)
  @stopes[index]/@vb.to_f + Math.sqrt(@yu*@yu+(@stopes[index]-@xu)*(@stopes[index]-@xu))/@vs
end

if @vs > @vb
  puts 2
else
  kms = @stopes[2].abs
  x = @stopes[2]
  answer = 2
  min = kms/@vb.to_f + Math.sqrt(@yu*@yu+(x-@xu)*(x-@xu))/@vs

  i = 3
#  puts "#{answer} #{min} #{compute(2)}"

  while i <= @n
    kms += (@stopes[i-1].abs-@stopes[i].abs).abs
    x = @stopes[i]
    val = kms/@vb.to_f + Math.sqrt(@yu*@yu+(x-@xu)*(x-@xu))/@vs

    if val < min
      answer = i
      min = val
    elsif (val == min) && ((@stopes[answer]-@xu).abs > (@stopes[i]-@xu).abs)
      answer = i
    end
    i += 1
  end
  puts answer
end
# av = compute(a)
# bv = compute(b)
#
# while b > a
#   # puts "a #{a} #{av}"
#   # puts "b #{b} #{bv}"
#   if bv > av
#     b = ((b+a) / 2)
#     bv = compute(b)
#   else
#     a = ((b+a) / 2) + 1
#     av = compute(a)
#   end
# end
# #puts "#{a} #{b}"
# # if (b-a) == 1
# #   mv = compute(a+1)
# #   if mv < av
# #     a += 1
# #     av = mv
# #   end
# # end
# #puts "#{av} #{bv}"
# if av > bv
#   puts b
# else #if bv > av
#   puts a
# # else
# #   av = (@stopes[a]-@xu).abs
# #   bv = (@stopes[b]-@xu).abs
# #   puts bv > av ? a : b
# end
#

n,vb,vs = gets.chomp.split(/ /).map!{|x| x.to_i}
ar = gets.chomp.split(/ /).map!{|x| x.to_i}
xu,yu = gets.chomp.split(/ /).map!{|x| x.to_i}

mind = 0
idx = 0
for i in 0..n-1
	wk = (ar[i]-xu).abs
	if idx == 0 || mind > wk
		mind = wk
		idx = i+1
	end
end
puts idx

n,vb,vs = gets.chomp.split(/ /).map!{|x| x.to_i}
ar = gets.chomp.split(/ /).map!{|x| x.to_i}
xu,yu = gets.chomp.split(/ /).map!{|x| x.to_i}

mint = 0
idx = 0
for i in 1..n-1
	wk = (ar[i]-xu).abs
	wkt = ar[i]/vb+Math.sqrt(wk*wk + yu*yu)/vs
	if idx == 0 || mint >= wkt
		mint = wkt
		mind = wk
		idx = i+1
	end
end
puts idx

n,vb,vs = gets.chomp.split(/ /).map!{|x| x.to_i}
ar = gets.chomp.split(/ /).map!{|x| x.to_i}
xu,yu = gets.chomp.split(/ /).map!{|x| x.to_i}

mint = 0
idx = 0
for i in 1..n-1
	wk = (ar[i]-xu).abs
	wkt = ar[i]/vb+Math.sqrt(wk*wk + yu*yu)/vs
	if idx == 0 || mint + 1e-6 > wkt
		mint = wkt
		mind = wk
		idx = i+1
	elsif (mint - wkt).abs < 1e-6
		if mind > wk
			mint = wkt
			mind = wk
			idx = i+1
		end
	end
end
puts idx

n,vb,vs = gets.chomp.split(/ /).map!{|x| x.to_i}
ar = gets.chomp.split(/ /).map!{|x| x.to_i}
xu,yu = gets.chomp.split(/ /).map!{|x| x.to_i}

mint = 0
mind = 0
idx = 0
for i in 1..n-1
	wk = (ar[i]-xu).abs
	wkt = ar[i]/vb+Math.sqrt(wk*wk + yu*yu)/vs
	if idx == 0 || mint > wkt
		mint = wkt
		mind = wk
		idx = i+1
	elsif mint == wkt
		if mind > wk
			mint = wkt
			mind = wk
			idx = i+1
		end
	end
end
puts idx

n,vb,vs = gets.chomp.split(/ /).map!{|x| x.to_i}
ar = gets.chomp.split(/ /).map!{|x| x.to_i}
xu,yu = gets.chomp.split(/ /).map!{|x| x.to_i}

mint = 0
idx = 0
for i in 1..n-1
	wk = (ar[i]-xu).abs
	wkt = ar[i]/vb+Math.sqrt(wk*wk + yu*yu)/vs
	if idx == 0 || mint > wkt
		mint = wkt
		mind = wk
		idx = i+1
	elsif mint == wkt
		if mind > wk
			mint = wkt
			mind = wk
			idx = i+1
		end
	end
end
puts idx

n,vb,vs = gets.chomp.split(/ /).map!{|x| x.to_i}
ar = gets.chomp.split(/ /).map!{|x| x.to_i}
xu,yu = gets.chomp.split(/ /).map!{|x| x.to_i}

mint = 0
mind = 0
idx = 0
for i in 1..n-1
	wk = (ar[i]-xu).abs
	wkt = ar[i]/vb+Math.sqrt(wk*wk + yu*yu)/vs
	if idx == 0 || mint > wkt
		mint = wkt
		mind = wk
		idx = i+1
	end
end
puts idx

n,vb,vs = gets.chomp.split(/ /).map!{|x| x.to_i}
ar = gets.chomp.split(/ /).map!{|x| x.to_i}
xu,yu = gets.chomp.split(/ /).map!{|x| x.to_i}

mint = 0
idx = 0
for i in 1..n-1
	wk = (ar[i]-xu).abs
	wkt = ar[i]/vb+Math.sqrt(wk*wk + yu*yu)/vs
	if idx == 0 || mint > wkt
		mint = wkt
		mind = wk
		idx = i+1
	elsif (mint - wkt).abs < 1e-6
		if mind > wk
			mint = wkt
			mind = wk
			idx = i+1
		end
	end
end
puts idx

n, vb, vs = gets.split.map{|i| i.to_f}
x = gets.split.map{|i| i.to_i}
xu, yu = gets.split.map{|i| i.to_i}
ans = [1e100, -1, -1]
1.upto(x.length - 1) do |i|
	d = (xu - x[i]) ** 2 + yu ** 2
	t = x[i] / vb + Math.sqrt(d) / vs
	ans = [d, t, i] if t < ans[0] - 1e-8 || (t < ans[0] + 1e-8 && d < ans[1])
end
p ans[2] + 1

n, vb, vs = gets.split.map{|i| i.to_i}
x = gets.split.map{|i| i.to_i}
xu, yu = gets.split.map{|i| i.to_i}
best = 1e100
ans = -1
x.each_index do |i|
	temp = x[i] / vb + Math.sqrt(yu * yu + (xu - x[i]) * (xu - x[i])) / vs
	ans, best = i, temp if temp < best
end
p ans

n, vb, vs = gets.split.map{|i| i.to_f}
x = gets.split.map{|i| i.to_i}
xu, yu = gets.split.map{|i| i.to_i}
x = 1.upto(x.length - 1).map do |i|
	d = (xu - x[i]) ** 2 + yu ** 2
	t = x[i] / vb + Math.sqrt(d) / vs
	[t, -d, i + 1]
end
p x.min[2]

n, vb, vs = gets.split.map{|i| i.to_i}
x = gets.split.map{|i| i.to_i}
xu, yu = gets.split.map{|i| i.to_i}
best = 1e100
ans = -1
1.upto(x.length - 1) do |i|
	temp = x[i] / vb + Math.sqrt((xu - x[i]) * (xu - x[i]) + yu * yu) / vs
	ans, best = i, temp if temp <= best + 1e-8
end
print ans + 1, "\n"

n, vb, vs = gets.split.map{|i| i.to_i}
x = gets.split.map{|i| i.to_i}
xu, yu = gets.split.map{|i| i.to_i}
best = 1e100
ans = -1
x.each_index do |i|
	temp = x[i] / vb + Math.sqrt(yu * yu + (xu - x[i]) * (xu - x[i])) / vs
	ans, best = i, temp if temp < best
end
print ans + 1, "\n"

n,vb,vs=STDIN.gets.chomp.split
xn=STDIN.gets.chomp.split
xu,yu=STDIN.gets.chomp.split
n=n.to_i
vb=vb.to_i
vs=vs.to_i
xu=xu.to_i
yu=yu.to_i
for i in 0...xn.length do xn[i]=xn[i].to_i end
xn<<xn[xn.length-1]
idx=0
min=-1
ts=0
for i in 1...xn.length-1
  d=Math::sqrt((xu-xn[i])*(xu-xn[i])+yu*yu)
  t=d/vs+ts
  if min==-1
    min=t
    idx=i
  elsif t<min
    min=t
    idx=i
  end
  t+=(xn[i+1]-xn[i])/vb
end
puts(idx+1)

n,vb,vs=STDIN.gets.chomp.split
xn=STDIN.gets.chomp.split
xu,yu=STDIN.gets.chomp.split
n=n.to_i
vb=vb.to_i
vs=vs.to_i
xu=xu.to_i
yu=yu.to_i
for i in 0...xn.length do xn[i]=xn[i].to_i end
idx=0
min=-1
for i in 1...xn.length
  d=Math::sqrt((xu-xn[i])*(xu-xn[i])+yu*yu)
  t=1.0*(xn[i]-xn[1])/vb
  t=d/vs+t
  if min==-1
    min=t
    idx=i
  elsif t<min
    min=t
    idx=i
  end
end
puts(idx+1)

# -*- coding: utf-8 -*-
def dist (x0, y0, x1, y1)
  dx = (x1 - x0).to_f
  dy = (y1 - y0).to_f
  return Math.sqrt(dx * dx + dy * dy)
end

n,vb,vs = gets.split.map(&:to_i)
bus = gets.split.map(&:to_i)
xu,yu = gets.split.map(&:to_i)

time = Array.new

for i in 2..n do
  x = bus[i-1]
  time[i] = x.to_f / vb.to_f + dist(x, 0, xu, yu) / vs;
end

min_time = time[2..n].min;

for i in 2..n do
  if min_time == time[i] then
    print i
    puts
    break
  end
end

include Math
fst=gets.split
n=fst[0].to_i
vb=fst[1].to_f
vs=fst[2].to_f
bus_stops=gets.split.map{ |x| x.to_f}
univ = gets.split.map{ |x| x.to_f}
t = nil
res = nil
(n-1).times do |i|
  bx = bus_stops[i+1]
  l = sqrt((univ[0]-bx)**2 + (univ[1])**2)
  temp_t = (bx/vb)+(l/vs)
  if t==nil || t>temp_t
    t=temp_t
    res = i+2
  end
end
puts res

n,vb,vs=gets.split.map &:to_i
z=[1e9,1e9,0];
a=gets.split.map &:to_i
x,y=gets.split.map &:to_i
n.times{|i|d=((x-a[i])**2+y**2)**0.5;z=[[d/vs+x[i]/vb,d,i],z].min}
print z[2]+1

def dist(x1,y1,x2,y2)
	Math.sqrt(((x2-x1)**2) + ((y2-y1)**2))
end

n,v_b,v_s = gets.split(" ").map(&:to_i)
arr = gets.split(" ").map(&:to_i)
univ_x,univ_y = gets.split(" ").map(&:to_i)

ans = {}

arr[1..-1].each_with_index do |a,i|
	bus_time = a/v_b
	walk_time = (dist(univ_x,univ_y,a,0))/v_s
	ans[[bus_time + walk_time,walk_time]] = i
end
# puts "#{ans}"

key = ans.keys.min

puts "#{ans[key]+2}"

#$stdin = File.open('in.txt', 'r')
@n,@vb,@vs = gets.split(/\s+/).map {|x| x.to_i}
@stopes = gets.split(/\s+/).map {|x| x.to_i}
@xu,@yu = gets.split(/\s+/).map {|x| x.to_i}

@stopes.unshift(0)
a = 2
b = @n

def compute(index)
  @stopes[index]/@vb.to_f + Math.sqrt(@yu*@yu+(@stopes[index]-@xu)*(@stopes[index]-@xu))/@vs
end

av = compute(a)
bv = compute(b)

while b > a
  if av > bv
    a = ((b+a) / 2) + 1
    av = compute(a)
  else
    b = ((b+a) / 2)
    bv = compute(b)
  end
end
# if (b-a) == 1
#   mv = compute(a+1)
#   if mv < av
#     a += 1
#     av = mv
#   end
# end
#puts "#{av} #{bv}"
if av > bv
  puts b
else bv > av
  puts a
# else
#   puts a
  # av = (@stopes[a]-@xu).abs
  # bv = (@stopes[b]-@xu).abs
  # puts av > bv ? b : a
end

@n,@vb,@vs = gets.split(/\s+/).map {|x| x.to_i}
@stopes = gets.split(/\s+/).map {|x| x.to_i}
@xu,@yu = gets.split(/\s+/).map {|x| x.to_i}

@stopes.unshift(0)
a = 1
b = @n

def compute(index)
  @stopes[index]/@vb.to_f + Math.sqrt(@yu*@yu+(@stopes[index]-@xu)*(@stopes[index]-@xu))/@vs
end

av = compute(a)
bv = compute(b)

while (b-a) > 1
  if av > bv
    a = ((b+a) / 2)
  else
    b = ((b+a) / 2)+1
  end

  av = compute(a)
  bv = compute(b)
end
#puts "#{av} #{bv}"
if av > bv
  puts b
elsif bv > av
  puts a
else
  av = (@stopes[a]-@xu).abs
  bv = (@stopes[b]-@xu).abs
  puts av > bv ? b : a
end

#$stdin = File.open('in.txt', 'r')
@n,@vb,@vs = gets.split(/\s+/).map {|x| x.to_i}
@stopes = gets.split(/\s+/).map {|x| x.to_i}
@xu,@yu = gets.split(/\s+/).map {|x| x.to_i}

@stopes.unshift(0)
a = 2
b = @n

def compute(index)
  @stopes[index]/@vb.to_f + Math.sqrt(@yu*@yu+(@stopes[index]-@xu)*(@stopes[index]-@xu))/@vs
end

av = compute(a)
bv = compute(b)

while (b-a) > 1
  if av > bv
    a = ((b+a) / 2)
  else
    b = ((b+a) / 2)
  end

  av = compute(a)
  bv = compute(b)
end
if (b-a) == 1
  mv = compute(a+1)
  if mv < av
    a += 1
    av = mv
  end
end
#puts "#{av} #{bv}"
if av > bv
  puts b
else bv > av
  puts a
# else
#   puts a
  # av = (@stopes[a]-@xu).abs
  # bv = (@stopes[b]-@xu).abs
  # puts av > bv ? b : a
end

@n,@vb,@vs = gets.split(/\s+/).map {|x| x.to_i}
@stopes = gets.split(/\s+/).map {|x| x.to_i}
@xu,@yu = gets.split(/\s+/).map {|x| x.to_i}

@stopes.unshift(0)
a = 2
b = @n

def compute(index)
  @stopes[index]/@vb.to_f + Math.sqrt(@yu*@yu+(@stopes[index]-@xu)*(@stopes[index]-@xu))/@vs
end

av = compute(a)
bv = compute(b)

while (b-a) > 1
  if av > bv
    a = ((b+a) / 2)
  else
    b = ((b+a) / 2)
  end

  av = compute(a)
  bv = compute(b)
end
#puts "#{av} #{bv}"
if av > bv
  puts b
elsif bv > av
  puts a
else
  av = (@stopes[a]-@xu).abs
  bv = (@stopes[b]-@xu).abs
  puts av > bv ? b : a
end

#$stdin = File.open('in.txt', 'r')
@n,@vb,@vs = gets.split(/\s+/).map {|x| x.to_i}
@stopes = gets.split(/\s+/).map {|x| x.to_i}
@xu,@yu = gets.split(/\s+/).map {|x| x.to_i}

@stopes.unshift(0)
a = 2
b = @n

def compute(index)
  @stopes[index]/@vb.to_f + Math.sqrt(@yu*@yu+(@stopes[index]-@xu)*(@stopes[index]-@xu))/@vs
end

av = compute(a)
bv = compute(b)

while (b-a) > 1
  if av > bv
    a = ((b+a) / 2)
  else
    b = ((b+a) / 2)
  end

  av = compute(a)
  bv = compute(b)
end
if (b-a) == 1
  mv = compute(a+1)
  if mv < av
    a += 1
    av = mv
  end
end
#puts "#{av} #{bv}"
if av > bv
  puts b
elsif bv > av
  puts a
else
  av = (@stopes[a]-@xu).abs
  bv = (@stopes[b]-@xu).abs
  puts av > bv ? b : a
end

#$stdin = File.open('in.txt', 'r')
@n,@vb,@vs = gets.split(/\s+/).map {|x| x.to_i}
@stopes = gets.split(/\s+/).map {|x| x.to_i}
@xu,@yu = gets.split(/\s+/).map {|x| x.to_i}

@stopes.unshift(0)
a = 2
b = @n

def compute(index)
  @stopes[index]/@vb.to_f + Math.sqrt(@yu*@yu+(@stopes[index]-@xu)*(@stopes[index]-@xu))/@vs
end

av = compute(a)
bv = compute(b)

while b > a
  # puts "a #{a} #{av}"
  # puts "b #{b} #{bv}"
  if bv > av
    b = ((b+a) / 2)
    bv = compute(b)
  else
    a = ((b+a) / 2) + 1
    av = compute(a)
  end
end
#puts "#{a} #{b}"
# if (b-a) == 1
#   mv = compute(a+1)
#   if mv < av
#     a += 1
#     av = mv
#   end
# end
#puts "#{av} #{bv}"
if av > bv
  puts b
else #if bv > av
  puts a
# else
#   av = (@stopes[a]-@xu).abs
#   bv = (@stopes[b]-@xu).abs
#   puts bv > av ? a : b
end

#� ������ ������ ���� ��� ����� �����: 2???n? ??100, 1???vb,?vs? ??1000. �� ������ ������ ���� n  ��������������� ����� ����� � ������� �����������
#: ���������� xi ��������� ����� i. �������������, ��� x1  ����� ����, � xn? ??105.
#� ������� ������ ���� ���������� ������������, ����� ����� xu � yu, �� ������ �� ����������� 105.

n, vb, vs = gets.split(' ').map{|z|z.to_i}
crd = gets.split(' ').map{|z|z.to_i}
xu,yu = gets.split(' ').map{|z|z.to_i}

min = 105000000
res= 0
crd[1..-1].each_with_index{|xi,i|
  d = Math.sqrt(xi*xi)*vs+Math.sqrt((xu-xi)*(xu-xi)+yu*yu)*vb
  if d < min then
    min = d
    res = i+1
  end
}

puts res+1


n,q=gets.split.map(&:to_i)
s=gets.chomp.chars.map{|x|x.ord-96}
t=[0]
s.each do |ss|
  t << t[-1]+ss
end
q.times do
  l,r=gets.split.map(&:to_i)
  puts t[r]-t[l-1]
end

inputs = STDIN.read.strip.split("\n")
inputs.shift

class NumArray
  def initialize(nums)
    @x = nums.clone
    @x.unshift(0)
    (1...@x.size).each do |i|
      @x[i] += @x[i-1]
    end
  end

  def sum_range(left, right)
    @x[right+1] - @x[left]
  end
end

nums = []
inputs.shift.bytes.each do |b|
  nums << b - 96
end

nums.unshift(0)
nums = NumArray.new(nums)

inputs.each do |inp|
  from, to = inp.split(' ').map(&:to_i)

  puts nums.sum_range(from, to)
end


n=Array.new(3)
t=Array.new(3)
k,n[0],n[1],n[2],t[0],t[1],t[2]=gets.split.map(&:to_i)

starts=Array.new(k){0}

def when_free (k, n, t, starts, nnum)
	num=n[nnum]
	x=k+1-num

	time=0
	if(x>=0)
		time=starts[x]

		if (nnum==2)
			time+=(t[0]+t[1]+t[2])
		end

		if (nnum==1)
			time+=(t[0]+t[1])
		end

		if(nnum==0)
			time+=t[0]
		end
	else
		if (nnum==2)
			time+=(t[0]+t[1])
		end

		if (nnum==1)
			time+=(t[0])
		end
	end
	time
end

starts[0]=0
for i in 1...k do
	t2free=when_free(i-1,n,t,starts,2)
	t1free=when_free(i-1,n,t,starts,1)
	t0free=when_free(i-1,n,t,starts,0)

	start=t2free-t[1]-t[0]
	if (t1free>start+t[0])
		start=t1free-t[0]
	end

	if (t0free>start)
		start=t0free
	end
	starts[i]=start
end

puts (starts[k-1]+t[0]+t[1]+t[2])

$n = Array.new(3)
$t = Array.new(3)
k, $n[0], $n[1], $n[2], $t[0], $t[1], $t[2] = gets.split.map &:to_i

$now = Array.new(k) { 0 }

1.upto(2) do |i|
  $t[i] += $t[i - 1]
end

def make (q, p)
  x = q + 1 - $n[p]
  time = 0
  if x >= 0
    time = $now[x]
    time += $t[p]
  elsif p > 0
    time += $t[p - 1]
  end
  time
end

$now[0] = 0

0.upto(k - 2) do |i|
  ans = []
  ans << make(i, 2) - $t[1] << make(i, 1) - $t[0] << make(i, 0)
  st = ans.max
  $now[i + 1] = st
end
puts ($now[k - 1] + $t[2])


n = gets.to_i
array = gets.chop!.split(' ').map(&:to_i)
fixed_points, remain_points, plus = [], [], 0
array.each_with_index do |e, i|
  if e == i
    fixed_points.push e
  else
    plus = 2 if array[e] == i
    plus = 1 if plus == 0
  end
end
puts fixed_points.size + plus

n = Integer(gets)
input = gets.chomp
nums = input.split
a = Array.new
for i in 0...n
	a[i] = Integer(nums[i])
end
c = 0
for i in 0...n
	if a[i] == i
		c += 1
	end
end
def match(a,i,j)
	if a[i] == j && a[j] == i
		return true
	else
		return false
	end
end
d = 0
for i in 0...n
	j = a[i]
		if a[i] == j && a[j] == i && i != j
			d = 1
			break
		end

end
if c == n
	puts n
else
	if d == 1
		puts c + 2
	else
		puts c + 1
	end
end

def main()
	n=gets.chomp.to_i
	ar=gets.chomp.split(" ").map{|i| i.to_i}
	ans=0
	key=[]
	for i in 0...n
		if i==ar[i]
			ans+=1
		else
			key<<i
		end
	end
	if ans==n
		puts ans
		return
	end
	ans+=1
	for i in key
		val=ar[i]
		if ar[val]==i
			ans+=1
			break
		end
	end
	puts ans
end
main()

input = ARGF.read

numbers = input.lines.to_a[1].split(" ").map(&:to_i)

score = 0

old_posns = {}
swap = :no

numbers.each.with_index do |number, index|
  if number == index
    score += 1
  else
    old_posns[number] = index
    if swap == :no || swap == :single
      if old_posns[index] == number
        swap = :double
      end
    end

    if swap == :no
      if old_posns.include?(index)
        swap = :single
      end
    end
  end
end

case swap
when :single
  score += 1
when :double
  score += 2
end

puts score

n = gets.chomp.to_i
a = gets.chomp.split.map { |x| x.to_i }
count = 0
double_swap = false
for i in 0...n
  if a[i] == i
    count += 1
  elsif !double_swap && (v = a[i]) > i && a[v] == i
    double_swap = true
  end
end
count += double_swap ? 2 : 1 if count < n
puts count

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

cnt = 0
flag = false
n.times do |i|
	if p[i] == i
		cnt += 1
	elsif p[p[i]] == i
		flag = true
	end
end

if cnt == n
	puts cnt
elsif flag
	puts cnt + 2
else
	puts cnt + 1
end

n = gets.to_i
array = gets.chop!.split(' ').map(&:to_i)
fixed_points, remain_points = [], []
array.each_with_index do |e, i|
  fixed_points.push e if e == i
  remain_points.push [e, i] if e != i
end
result = fixed_points.size
remain_points.each do |point|
  if array[point[0]] == point[1]
    result += 2
    break
  end
end
result += 1 if result == fixed_points.size && remain_points.size != 0
puts result

n = gets.to_i
array = gets.chop!.split(' ').map(&:to_i)
fixed_points = array.select.with_index { |e, i| e == i}
plus = array.select.with_index { |e, i| e != i && array[e] == i }.empty? ? 1 : 2
plus -= 1 if fixed_points.size == array.size
puts fixed_points.size + plus

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

cnt = 0
flag = false
n.times do |i|
	if p[i] == i
		cnt += 1
	elsif p[p[i]] == i
		puts i, p[i], p[p[i]]
		flag = true
	end
end

if cnt == n
	puts cnt
elsif flag
	puts cnt + 2
else
	puts cnt + 1
end


n = readline.to_i
poles = (0...n).map { |_| readline.split.map(&:to_i) }

def line_x(x1, y1, x2, y2)
  if y1 == y2
    [nil, nil]
  else
    slope = Rational(x1-x2, y1-y2)
    [slope, x1 - slope * y1]
  end
end

def c2(n)
  n * (n-1) / 2
end

lines = {}
lines.default = 0
parallels = {}
parallels.default = 0
for i in 0...n do
  x1, y1 = poles[i]
  for j in i+1...n do
    x2, y2 = poles[j]
    sx, lx = line_x(x1, y1, x2, y2)
    sy, ly = line_x(y1, x1, y2, x2)
    line = [sx, lx, ly]
    lines[line] += 1
    parallels[[sx,sy]] += 1 if lines[line] == 1
  end
end

r = c2(lines.length)
parallels.values.each { |x| r -= c2(x) }
p r

# coding: utf-8
n = readline.to_i
poles = (0...n).map { |_| readline.split.map(&:to_i) }

def c2(n)
  n * (n-1) / 2
end

lines = {}
lines.default = 0
parallels = {}
parallels.default = 0
for i in 0...n do
  x1, y1 = poles[i]
  for j in i+1...n do
    x2, y2 = poles[j]
    a = y1 - y2
    b = x2 - x1
    if a < 0 or (a == 0 and b < 0)
      a = -a
      b = -b
    end
    d = a.gcd b
    a /= d
    b /= d
    c = a*x1 + b*y1
    line = [a, b, c]
    STDERR.print "(#{x1},#{y1})—(#{x2},#{y2}): #{a}x+#{b}y+#{c}=0\n"
    lines[line] += 1
    parallels[[a, b]] += 1 if lines[line] == 1
  end
end

r = c2(lines.length)
parallels.values.each { |x| r -= c2(x) }
p r

n = readline.to_i
poles = (0...n).map { |_| readline.split.map(&:to_i) }

def c2(n)
  n * (n-1) / 2
end

lines = {}
lines.default = 0
parallels = {}
parallels.default = 0
for i in 0...n do
  x1, y1 = poles[i]
  for j in i+1...n do
    x2, y2 = poles[j]
    a = y1 - y2
    b = x2 - x1
    d = a.gcd b
    a /= d
    b /= d
    c = a*x1 + b*y1
    line = [a, b, c]
    lines[line] += 1
    parallels[[a, b]] += 1 if lines[line] == 1
  end
end

r = c2(lines.length)
parallels.values.each { |x| r -= c2(x) }
p r

n = readline.to_i
poles = (0...n).map { |_| readline.split.map(&:to_i) }

def line_x(x1, y1, x2, y2)
  if y1 == y2
    [nil, nil]
  else
    slope = Rational((x1-x2)/(y1-y2))
    [slope, x1 - slope * y1]
  end
end

def c2(n)
  n * (n-1) / 2
end

lines = {}
lines.default = 0
parallels = {}
parallels.default = 0
for i in 0...n do
  x1, y1 = poles[i]
  for j in i+1...n do
    x2, y2 = poles[j]
    sx, lx = line_x(x1, y1, x2, y2)
    sy, ly = line_x(y1, x1, y2, x2)
    line = [sx, sy, lx, ly]
    lines[line] += 1
    parallels[[sx, sy]] += 1 if lines[line] == 1
  end
end

r = c2(lines.length)
parallels.values.each { |x| r -= c2(x) }
p r


gets.to_i.times do
    n = gets.to_i
    a = gets.chomp.split.map(&:to_i)
    ans = 0
    cur = a[0]
    down = 0
    for i in 1..n-1
        if(cur >= a[i] - down)
            ans += cur - (a[i] - down)
            cur = a[i] - down
        else
            ans += (a[i] - down) - cur
            down += (a[i] - down) - cur
        end
    end
    ans += cur > 0 ? cur : -cur

    puts ans
end

gets.to_i.times do
    n = gets.to_i
    a = gets.chomp.split.map(&:to_i)
    ans = 0
    cur = a[0]
    down = 0
    (1..n-1).each do |i|
        ans += [cur - (a[i] - down), (a[i] - down) - cur].max
        down += [(a[i] - down) - cur, 0].max
        cur = a[i] - down
    end
    puts ans + (cur > 0 ? cur : -cur)

end

gets.to_i.times do
    n = gets.to_i
    a = gets.chomp.split.map(&:to_i)
    ans = 0
    cur = a[0]
    down = 0
    for i in 1..n-1
        ans += [cur - (a[i] - down), (a[i] - down) - cur].max
        down += [(a[i] - down) - cur, 0].max
        cur = a[i] - down
    end
    puts ans + (cur > 0 ? cur : -cur)

end


$n = gets.chomp.to_i
$n.times do
  s = gets.chomp.to_i
  ans = 0
  while s > 0
    ans = [ans, s % 10].max
    s = s / 10
  end
  puts ans
end

gets.to_i.times do |i|
  puts gets.chomp.chars.max
end


input = STDIN.read.split("\n")

(0..input.shift.to_i - 1).to_a.reverse.each do |i|
  wh = input.shift.split(' ').map(&:to_i)
  h1a = input.shift.split(' ').map(&:to_i)
  h2a = input.shift.split(' ').map(&:to_i)
  w1a = input.shift.split(' ').map(&:to_i)
  w2a = input.shift.split(' ').map(&:to_i)

  h1 = h1a[h1a[0]] - h1a[1]
  h2 = h2a[h2a[0]] - h2a[1]
  maxh = [h1, h2].max

  w1 = w1a[w1a[0]] - w1a[1]
  w2 = w2a[w2a[0]] - w2a[1]
  maxw = [w1, w2].max

  puts [maxw * wh[0], maxh * wh[1]].max
end

area = ->(x1, y1, x2, y2, x3, y3) {
  (x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)).abs
}

gets.to_i.times do
  w, h = gets.split.map(&:to_i)
  as = gets.split.drop(1).map { |x| [x.to_i, 0] }
  bs = gets.split.drop(1).map { |x| [x.to_i, h] }
  cs = gets.split.drop(1).map { |x| [0, x.to_i] }
  ds = gets.split.drop(1).map { |x| [w, x.to_i] }
  all = as + bs + cs + ds
  p([as, bs, cs, ds].map do |s|
    x1, y1 = s[0]
    x2, y2 = s[-1]
    all.map { |x3, y3| area[x1, y1, x2, y2, x3, y3] }.max
  end.max)
end


n,m = gets.split.map(&:to_i)
arr = gets.split.map(&:to_i)
res = arr[0]-1
for i in 1...m
  if arr[i] < arr[i-1]
    res += n - (arr[i] - arr[i-1]).abs
  else
    res += arr[i] - arr[i-1];
  end
end

puts res

n, m = gets.split(' ').map(&:to_i)
ar = gets.split(' ').map(&:to_i)
puts ar.each_cons(2).select{|x,y| x>y}.count * n + ar[-1] - 1

#!/usr/bin/ruby
n=gets.to_i
p ([0]+gets.split.map{|e|e.to_i-1}).each_cons(2).map{|a,b|b-a<0 ? b+n-a : b-a}.reduce(:+)

line1 = gets.chomp.split(" ")
n = line1[0].to_i
m = line1[1].to_i
task = gets.chomp.split(" ").map {|x| x.to_i}
pos = 1
ans = 0
for t in task
  if t > pos
    ans += t-pos
  elsif t < pos
    ans += t+n-pos
  end
  pos = t
end
puts ans

def get_i
  return gets.split(' ').map(&:to_i)
end
n,m=get_i
a=get_i.unshift(1)
ans=0
for i in 1..m do
  ans+=(a[i]-a[i-1]+n)%n
end
puts ans

n, m = gets.split.map { |i| i.to_i }
a = gets.split.map { |i| i.to_i }

s = a[0] - 1
for i in 1..(a.count - 1) do
  y = a[i] - a[i - 1]
  if y < 0 then y = n + y end
  s += y
end

puts s

#!/usr/bin/ruby1.9

n, m = STDIN.readline.split.collect {|s| s.to_i }
tasks = STDIN.readline.split.collect {|s| s.to_i }

total = 0
pos = 1
tasks.each do |next_pos|
	if next_pos >= pos
		total += next_pos - pos
	else
		total += (n - pos) + 1 + (next_pos - 1)
	end
	pos = next_pos
end
puts total

hn, dn = gets.split.map(&:to_i)
deals = gets.split.map(&:to_i)
time = 0
curh = 1
deals.each {|d|
	time += (d-curh)%hn
	curh = d
}
puts time

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

input = string_to_int(gets.chomp)
dest = string_to_int(gets.chomp)

walk = dest[0] - 1

for i in 0...dest.length - 1
	if dest[i] <= dest[i+1]
		walk += dest[i+1] - dest[i]
	else
		walk += input[0] + dest[i+1] - dest[i]
	end
end

puts walk

r = -> { gets.split.map(&:to_i )}
n,m = r[]
v = r[]
v.unshift(1)
s = 0
(1..m).each do |x|
    if v[x - 1] < v[x]
        s += v[x] - v[x - 1]
    elsif v[x - 1] > v[x]
        s += n - v[x - 1] + v[x]
    end
end
p s

n,m=gets.chomp.split.map(&:to_i)
a=gets.chomp.split.map(&:to_i)
y,ans,x=1,0,0
a.each do |i|
	ans+=1 if i<y
	y=i
	x=i
end
puts ans*n+x-1

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

prev = 1
s = 0
a.each do |el|
  if el < prev
    s += (el - prev + n)
  else
    s += el - prev
  end
  prev = el
end
puts s

n, m = gets.split.map &:to_i
arr = gets.split.map &:to_i
moves = 0
prev = 1
arr.each do |item|
  if item >= prev
    moves += item - prev
    prev = item
  else
    moves += n - prev + item
    prev = item
  end
end
puts moves

n, m = gets.chomp.split(/ /).map(&:to_i)
tasks = gets.chomp.split(/ /).map(&:to_i)
ans = 0
prev_task = 0
(0...m).each do |task|
    current_task = tasks[task]
    if prev_task == 0
        ans += current_task
    else
        if current_task != prev_task
            if current_task < prev_task
                ans += (n - prev_task) + current_task
            else
                ans += current_task - prev_task
            end
        end
    end
    prev_task = current_task
end
puts ans - 1

n,m=gets.split.map{|e| e.to_i}
x=gets.split.map{|e| e.to_i-1}

ans=x[0]
(m-1).times{|i|
	if x[i+1]>=x[i] then
		ans=ans+x[i+1]-x[i]
	else
		ans=ans+x[i+1]+n-x[i]
	end
}
puts ans

s = gets.split.map { |e| e.to_i  }
s2 = gets.split.map { |e| e.to_i  }
n = s[0]
m = s[1]
x = m[0]
c = 0
for i in s2
	if i < x
		c +=1
	end
	x = i
end
puts (c * n) + s2[m-1] - 1

n,m = gets.split(" ").map { |x| x.to_i }
a = gets.split(" ").map { |x| x.to_i }
res = 0
xprev = 1
a.each do |x|
  if xprev > x then
    res += n
  end
  res += x - xprev
  xprev = x
end
puts res

input = gets.chomp
num = input.split
n = Integer(num[0])
m = Integer(num[1])
input2 = gets.chomp
nums = input2.split
a = Array.new
for i in 0...m
    a[i] = Integer(nums[i])
end

b = Array.new
b[0] = a[0]
for i in 0...m-1
    if a[i+1] != a[i]
        b.push(a[i+1])
    end
end
time = 0
l = b.length
for i in 0...l-1
    if b[i+1] < b[i]
        time += 1
    end
end

puts time * n - 1 + b[l-1]

nm = gets.chomp
nm = nm.split
houses = nm[0].to_i
tasks = nm[1].to_i
each_task = gets.chomp
each_task = each_task.split

hours = 0
position = 1
for i in (0..each_task.size-1)
	if position < each_task[i].to_i
		hours += (each_task[i].to_i - position)
		position = each_task[i].to_i
	elsif position > each_task[i].to_i
		hours += (houses - position) + each_task[i].to_i
		position = each_task[i].to_i
	end
end

print hours

n,m = gets.split(" ").map(&:to_i)
tasks = gets.split(" ").map(&:to_i)
cost = 0
current = 1
tasks.each do |a|
	if a > current
		cost += a - current

		current = a
	elsif a < current
		cost += (n - current) + a
		current = a
	end
end
puts cost

n, m = gets.split.map &:to_i
a = gets.split.map &:to_i
s = 0
p = 1

for i in (0..m-1)
  a[i] < p ? s += n - p + a[i] : s += a[i] - p
  p = a[i]
end
puts s

#!/usr/bin/env ruby

n,m = gets.split.map(&:to_i)
x = gets.split.map(&:to_i)
now = 1
ans = 0
x.each do |p|
  if now <= p
    ans += p - now
  else
    ans += p + n - now
  end
  now = p
end
puts ans

n, m = gets.strip.split.map(&:to_i)
a = gets.strip.split.map(&:to_i)
now = 1
dis = 0
a.each do |x|
  if x < now
    dis += (n - (now - x))
  else
    dis += x - now
  end
  now = x
end
puts dis

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

curr = 1
puts(
  gets.split(' ').map(&:to_i).inject(0) do |result, x|
    c = curr
    curr = x
    result + (x >= c ? x - c : n - c + x)
  end
)

n, m = gets.chomp.split.map { |x| x.to_i }
h = [1].concat(gets.chomp.split.map { |x| x.to_i })
count = 0
for i in 1..m
  if h[i] > h[i - 1]
    count += h[i] - h[i - 1]
  elsif h[i] < h[i - 1]
    count += n - h[i - 1] + h[i]
  end
end
puts count

r = gets.split(" ")[0].to_i
s = gets.split(" ").map { |i| i.to_i }

b = 1
res = 0
s.each do |i|
	if b < i
		res += (i-b)
	elsif b > i
		res += (r-b+i)
	end
	b = i
end

puts res

def read_line
	line = gets.chomp.split(' ')
	line.map { |elem| elem.to_i }
end

def distance(a, b, n)
	return b - a if a <= b
	n - a + 1 + b - 1
end

n, m = read_line
a = read_line
current = 1
res = 0
a.each do |after|
	res += distance(current, after, n)
	current = after
end

puts res

# f = File.new('test1.txt', 'r')
f = STDIN
while s = f.gets
  n, m = s.split.map(&:to_i)
  arr = f.gets.split.map(&:to_i)
  ans, start = 0, 1
  arr.each do |e|
    if e >= start
      ans += e - start
    else
      ans += n - start + e
    end
    start = e
  end
  puts ans
end
f.close

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

input = string_to_int(gets.chomp)
dest = string_to_int(gets.chomp)

walk = dest[0] - 1

for i in 0...dest.length - 1
	if dest[i] < dest[i+1]
		walk += dest[i+1] - dest[i]
	else
		walk += input[0] + dest[i+1] - dest[i]
	end
end

puts walk

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

input = string_to_int(gets.chomp)
dest = string_to_int(gets.chomp)

house_no = 0
houses = Array.new(input[0]){|house_no| house_no+1}
walk = 0

j = 0
for i in 0...dest.length
	while houses[j] != dest[i]
		if j > dest.length - 1
			j = 0
			walk += 1
		else
			j += 1
			walk += 1
		end
	end
end

puts walk

def read_line
	line = gets.chomp.split(' ')
	line.map { |elem| elem.to_i }
end

def distance(a, b, n)
	return b - a if a <= b
	n - a + 1 + b - 1
end

n, m = read_line
a = read_line.uniq
current = 1
res = 0
a.each do |after|
	res += distance(current, after, n)
	current = after
end

puts res


TABLE_PAT = '<table>'
ROW_PAT = '<tr>'
CELL_PAT = '<td>'

class Solution
  def initialize()
    @s = ""
    while line=gets do
      @s = @s + line.chomp!
    end
    @count_stack = []
    @count_array = []
  end

  def cell()
    @s = @s[CELL_PAT.length..-1]
    if /^#{TABLE_PAT}/ =~ @s
      table
    end
    @count_stack[-1] += 1
    @s = @s[CELL_PAT.length+1..-1]
  end

  def row()
    @s = @s[ROW_PAT.length..-1]
    while /^#{CELL_PAT}/ =~ @s do
      cell
    end
    @s = @s[ROW_PAT.length+1..-1]
  end

  def table()
    @s = @s[TABLE_PAT.length..-1]
    @count_stack.push(0)
    while /^#{ROW_PAT}/ =~ @s do
      row
    end
    @count_array.push(@count_stack.pop)
    @s = @s[TABLE_PAT.length+1..-1]
  end

  def solve()
    while /^#{TABLE_PAT}/ =~ @s do
      table
    end
    puts @count_array.sort!.join(' ')
  end
end

solution = Solution.new
solution.solve

a = [0]
b = []
(readlines.map(&:chomp) * '').scan(/<(ta|\/ta|td)/) do |_,|
	case _
	when 'ta' then a << 0
	when '/ta' then b << a.pop
	when 'td' then a[-1] += 1
	end
end
puts b.sort * ' '

s = ''
x = ''
s += x.chomp while x = gets

def read_next(s)
  return [nil, nil] if !s || s.empty?
  pos = s.index('>')
  [s[0..pos], s[pos+1..-1]]
end

stack = []
ans = []

while true
  head, s = read_next(s)
  break unless head
  case head
    when "
" then stack.push(0)
    when "
" then ans << stack.pop
    when "	" then stack[-1] += 1
  end
end

puts ans.sort.join(' ')

a = [0]
b = []
(readlines * '').scan(/<(ta|\/ta|td)/) do |_,|
	case _
	when 'ta' then a << 0
	when '/ta' then b << a.pop
	when 'td' then a[-1] += 1
	end
end
puts b.sort * ' '

a = [0]
b = []
(readlines * ' ').scan(/<(table|\/table|td)>/) do |_,|
	case _
	when 'table' then a << 0
	when '/table' then b << a.pop
	when 'td' then a[-1] += 1
	end
end
puts b.sort * ' '


def solve
  n = gets.strip.to_i
  if n == 1
    puts "FastestFinger"
    return nil
  end
  if n == 2 || n.odd?
    puts "Ashishgup"
    return nil
  end

  sq = Math.sqrt(n).to_i
  (2..sq).each { |i|
    if (n % i).zero?
      if (i.odd? && (n / i) > 2) || ((n / i).odd? && (n / (n / i)) > 2)
        puts "Ashishgup"
        return nil
      end
    end
  }
  puts "FastestFinger"
end

gets.strip.to_i.times { solve }

n = gets.chomp.to_i

a = 'Ashishgup'
b = 'FastestFinger'

def is_prime?(num)
  return if num <= 1
  (2..Math.sqrt(num)).none? { |i| (num % i).zero? }
end

(1..n).each do
  x = gets.chomp.to_i
  if x == 1
    puts b
  elsif x == 2
    puts a
  elsif x % 2 == 1
    puts a
  elsif x % 4 != 0
    if is_prime?(x/2)
      puts b
    else
      puts a
    end
  elsif x.to_s(2).count('1') == 1
    puts b
  else
    puts a
  end
end

def solve
  n = gets.strip.to_i
  if n == 1
    puts "FastestFinger"
    return nil
  end
  if n == 2 || n.odd?
    puts "Ashishgup"
    return nil
  end

  sq = Math.sqrt(n).to_i
  (2..sq).each { |i|
    if (n % i).zero?
      if (i.odd? || (n / i).odd?)
        if n / (n / i) > 3 || n / i > 3
          puts "Ashishgup"
          return nil
        end
      end
    end
  }
  puts "FastestFinger"
end

gets.strip.to_i.times { solve }

n = gets.chomp.to_i

a = 'Ashishgup'
b = 'FastestFinger'

(1..n).each do
  x = gets.chomp.to_i
  if x == 1
    puts b
  elsif x == 2
    puts a
  elsif x % 2 == 1
    puts a
  elsif x % 4 != 0
    puts b
  elsif x.to_s(2).count('1') == 1
    puts b
  else
    puts a
  end
end


s=gets.chomp
MOD=1000000007
ans=0
m=1
for i in 0...s.length
	if s[i]=='a'
		m=(m*2)%MOD
	else
		ans=(ans+m-1)%MOD
	end
end
puts ans

res, q, m=0, 1, 10**9+7
gets.chomp.chars{|c| c==?a ? q=q*2%m : res=(res+q-1+m)%m}
p res

s=gets.chomp
m=10**9+7
a=s.split(?b).map(&:size)
a.pop if s[-1]!=?b
n=a.size
for i in 1...n
    a[i]+=a[i-1]
end
res=0
a.each{|e| res+=2**e-1; res%=m; }
p res


END { load __FILE__ unless $stdin.eof? }

t = gets.to_i
t.times do

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

x = a.inject(:&)
p x

end

gets.to_i.times do
  n=gets.to_i
  puts gets.split.map(&:to_i).inject(:&)
end


N, K = gets.split.map(&:to_i)
str = gets.chomp
hash = Hash.new(0)
str.split('').sort[0, K].each do |c|
    hash[c] += 1
end
ans = ''
str.chars do |c|
    if hash[c] > 0
        hash[c] -= 1
    else
        ans << c
    end
end
puts ans

def solution
  _, k = read_ints
  s = read_string.chars

  ixs = (0..25).map{ |i| [] }

  (0...s.size).each do |i|
    c = s[i]
    x = c.ord - 97
    ixs[x] << i
  end

  to_remove = ixs.flatten

  k.times do
    i = to_remove.shift
    s[i] = '*'
  end

  # puts s.gsub('*', '')
  s.each do |c|
    print c if c > '*'
  end
  puts

end

def solution_16s
  # perf problem was not the hash; it was the string ops
  # Apparently s[i] = 'c' is expensive.
  # Using s.chars instead is much better
  _, k = read_ints
  s = read_string

  ixs = Hash.new { |h, i| h[i] = [] }

  (0...s.size).each do |i|
    c = s[i]
    ixs[c] << i
  end

  l = 'a'

  k.times do
    l = l.succ while ixs[l].size < 1
    ix = ixs[l].shift
    s[ix] = ' '
  end

  # puts s.gsub(' ', '')
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']

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

chars = str.split('').sort
hsh = {}
k.times do |i|
  hsh[chars[i]] = (hsh[chars[i]] || 0) + 1
end

ans_str = ""
str.each_char do |c|
  if hsh[c].nil? || hsh[c] <= 0
    ans_str << c
  else
    hsh[c] -= 1 if hsh[c] && hsh[c] > 0
  end
end
puts ans_str

n, k = gets.chomp.split.map(&:to_i)
s = gets.chomp

a = s.split("").sort

hash = Hash.new { |hash, key| hash[key] = 0 }

k.times do |i|
  hash[a[i]] += 1
end

result = ""

s.each_char do |char|
  if hash[char].nil? || hash[char] <= 0
    result << char
  elsif hash[char] && hash[char] > 0
    hash[char] -= 1
  end
end

puts result

n, k = gets.split.map(&:to_i)
s = gets.chomp
pos = (1..26).map { [] }
s.chars.each_with_index { |c, i| pos[c.ord - 'a'.ord] << i }

flag = [true] * n
pos.each do |a|
	a.each do |pos|
		if k > 0
			flag[pos] = false
			k -= 1
		end
	end
end
puts (0...n).select { flag[_1] }.map { s[_1] }.join

n, k = gets.split(" ").map{|n| n.to_i }
s = gets.chomp

require 'pp'
strs = "abcdefghijklmnopqrstuvwxyz".split("")
maps = {}
s.length.times{|i|
  maps[s[i]] ||= 0
  maps[s[i]] += 1
}

counts = maps.to_a.sort{|a, b|a[0]<=>b[0]}
erase_counts = {}
while 0 < k
  counts.each{|char, count|
    erase = [count, k].min
    k -= erase
    erase_counts[char] = erase
    break if k == 0
  }
end

s.length.times{|i|
  char = s[i]
  if not erase_counts[char].nil? and 0 < erase_counts[char]
    erase_counts[char] -= 1
  else
    print char
  end
}
puts ""

def solution
  _, k = read_ints
  s = read_string.chars

  ixs = (0..25).map{ |i| [] }

  (0...s.size).each do |i|
    c = s[i]
    x = c.ord - 97
    ixs[x] << i
  end

  to_remove = ixs.flatten

  k.times do
    i = to_remove.shift
    s[i] = '*'
  end

  # puts s.gsub('*', '')
  s.each do |c|
    print c, false if c > '*'
  end
  puts

end

def solution_16s
  _, k = read_ints
  s = read_string

  ixs = Hash.new { |h, i| h[i] = [] }

  (0...s.size).each do |i|
    c = s[i]
    ixs[c] << i
  end

  l = 'a'

  k.times do
    l = l.succ while ixs[l].size < 1
    ix = ixs[l].shift
    s[ix] = ' '
  end

  # puts s.gsub(' ', '')
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']

def solution
  _, k = read_ints
  s = read_string.chars

  ixs = (0..25).map{ |i| [] }

  (0...s.size).each do |i|
    c = s[i]
    x = c.ord - 97
    ixs[x] << i
  end

  to_remove = ixs.flatten

  k.times do
    i = to_remove.shift
    s[i] = '*'
  end

  s.each do |c|
    print c, false if c > '*'
  end
  puts

end

def solution_16s
  _, k = read_ints
  s = read_string

  ixs = Hash.new { |h, i| h[i] = [] }

  (0...s.size).each do |i|
    c = s[i]
    ixs[c] << i
  end

  l = 'a'

  k.times do
    l = l.succ while ixs[l].size < 1
    ix = ixs[l].shift
    s[ix] = ' '
  end

  # puts s.gsub(' ', '')
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']


s = gets.chomp
letters = ["A", "H", "I", "M", "O", "T", "U", "V", "W", "X", "Y"]
s.split("").each do |ch|
    unless letters.include?(ch)
        puts "NO"
        exit
    end
end
if s.reverse != s
    puts "NO"
    exit
end
puts "YES"

#!/usr/bin/ruby
s=gets.chomp
puts s.tr('A-Z','A@@@@@@HI@@@M@O@@@@TUVWXY@').reverse==s ? :YES : :NO

s = gets.chomp
if s.match(/[^AHIOMTUVWXY]/).nil? and s == s.reverse
  puts 'YES'
else
  puts 'NO'
end

sym = ['A', 'H', 'I', 'M', 'O', 'T', 'U', 'V', 'W', 'X', 'Y']

input = gets.chomp
if input != input.reverse
    puts "NO"
else
    input.each_char do |char|
        next if sym.include? char

        puts "NO"
        exit
    end
    puts "YES"
end

def solve(s)
	return ((/^[AHIMOTUVWXY]*$/.match s) and (s == s.reverse))
end

def main()
	return "YES" if solve(gets.chomp)
	return "NO"
end

puts main

s = gets.chomp
if (s.size == 1 or s[0..s.size / 2 - 1] == s[(s.size / 2.0).ceil..-1].reverse) and s.scan(/[AHIMOTUVWXY]/i).size == s.size
	puts "YES"
else
	puts "NO"
end

s = gets.chomp
letters = ["A", "H", "I", "M", "O", "T", "U", "V", "W", "X", "Y"]
unless (s.split("").uniq-letters).empty?
    puts "NO"
    exit
end
if s.reverse != s
    puts "NO"
    exit
end
puts "YES"

MIRROR = "AHIMOTUVWXY"
s = gets.chomp
len = s.length
0.upto(len>>1) do |i|
	if s[i] != s[len-1-i] || !MIRROR.include?(s[i]) || !MIRROR.include?(s[len-1-i])
		puts "NO"
		exit 0
	end
end
puts "YES"

s = gets.chomp
if s[0..s.size / 2 - 1] == s[(s.size / 2.0).ceil..-1].reverse and s.scan(/[AHIMOTUVWXY]/i).size == s.size
	puts "YES"
else
	puts "NO"
end

gets.chomp.each_char do |i|
	if !"AHIMOTUVWY".include?(i)
		puts "NO"
		exit 0
	end
end
puts "YES"

#!/usr/bin/ruby
s=gets.chomp
puts s.tr('A-Z','A@@@@@@HI@@M@O@@@@TUVWXY@').reverse==s ? :YES : :NO

s = gets.chomp
if s.match(/[^AHIOTUVWXY]/).nil? and s == s.reverse
  puts 'YES'
else
  puts 'NO'
end