Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison.

Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters.

If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared.

NoteIf you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site: http://en.wikipedia.org/wiki/Lexicographical_order

first = gets.chomp
second = gets.chomp
first_letters = first.split("")
second_letters = second.split("")
x = 1
alphabet = ('a'..'z').to_a

i = 0
counter = 0
while counter == 0 && i < first.length.to_i
	if first_letters[i].downcase == second_letters[i].downcase
		counter = 0
	elsif first_letters[i].downcase < second_letters[i].downcase
		counter -= 1
	elsif first_letters[i].downcase > second_letters[i].downcase
		counter += 1
	end
	i += 1
end

puts counter

a, b = gets.downcase, gets.downcase
puts a == b ? 0 : (a < b ? -1 : 1)

string1 = gets
string2 = gets

if string1.downcase() == string2.downcase()
  puts "0"
elsif string1.downcase() > string2.downcase()
  puts "1"
else
  puts "-1"
end

l1 = gets.chomp.downcase
l2 = gets.chomp.downcase

puts l1 <=> l2

puts gets.to_s.downcase <=> gets.to_s.downcase

word1 = gets.chomp.downcase
word2 = gets.chomp.downcase

if word1 < word2 then
    print '-1'
elsif word1 > word2 then
    print '1'
else
    print '0'
end

s1 = gets.chomp
s2 = gets.chomp
if s1.capitalize==s2.capitalize
    puts "0"
elsif s2.capitalize < s1.capitalize
    puts "1"
elsif s2.capitalize > s1.capitalize
    puts "-1"
end

def compare s,a
	s=s.downcase
	a=a.downcase
	return s<=>a
end

s=gets
a=gets
p compare(s,a)

a,b=[gets, gets].map(&:downcase)
p a<=>b

s = gets.chomp.to_s
t = gets.chomp.to_s

s.downcase!
t.downcase!

if s>t
    puts 1
elsif s==t
    puts 0
else
    puts -1
end

s = gets.chomp.upcase
t = gets.chomp.upcase
p -1 if s < t
p 0 if s == t
p 1 if s > t

string1 = gets.chomp.downcase
string2 = gets.chomp.downcase

if string1 < string2
  puts "-1"
elsif string1 > string2
  puts "1"
else
  puts "0"
end

s1, s2 = gets.downcase, gets.downcase
if s1 > s2
	puts 1
elsif s1 < s2
	puts -1
elsif s1 == s2
	puts 0
end

firstSen = gets.chomp.downcase
secondSen = gets.chomp.downcase

puts firstSen <=> secondSen

a = gets.chomp
b = gets.chomp

a.downcase!
b.downcase!
if a == b
	puts 0
elsif a > b
	puts 1
else  a < b
	puts -1
end

m = gets.chomp
n = gets.chomp
puts m.downcase >= n.downcase ? m.downcase == n.downcase ? 0 : 1 : -1

a = gets
b = gets
puts a.downcase <=> b.downcase

#! usr/bin/env ruby

str1 = gets
str2 = gets
puts str1.casecmp str2

str1 = gets.chomp.downcase

str2 = gets.chomp.downcase

if str1 == str2
  print "0"
elsif str1 < str2
  print "-1"
elsif str1 > str2
  print "1"
end

puts gets.capitalize <=> gets.capitalize

#!/usr/bin/env ruby
a = gets.capitalize
b = gets.capitalize
puts a <=> b

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

first = gets.chomp
second = gets.chomp

puts first.downcase <=> second.downcase

a = gets.strip
b = gets.strip
a.downcase!
b.downcase!
puts a < b ? -1 : (a == b ? 0 : 1)

puts gets.to_s.downcase <=> gets.to_s.downcase

a = gets.chomp.downcase
b = gets.chomp.downcase
if(a==b)
  puts 0
else
  puts a < b ? -1 : 1
end

#http://codeforces.com/problemset/problem/112/A

str1 = gets.chomp
str2 = gets.chomp

puts str1.downcase  <=> str2.downcase

def run(input = STDIN.read)
  line1, line2 = input.split("\n")
  line1.each_char.each_with_index do |char, index|
    next if char.downcase == line2[index].downcase

    puts char.downcase > line2[index].downcase ? "1" : "-1"
    return
  end
  puts "0"
end
run

a = gets.downcase
b = gets.downcase
puts (a<b ? -1 : (a>b ? 1 : 0))

a,b=[1,2].map{gets.chomp.downcase}
p a==b ?0:[a,b].sort.index(a)*2-1

#! ruby -Ku
# -*- coding: UTF-8 -*-
begin
  inputs = open("input.txt")
rescue
  inputs = STDIN
end

first = inputs.gets.downcase.chomp.split(//)
second = inputs.gets.downcase.chomp.split(//)

order = 0

first.each_with_index do |ch, i|
  if ch < second[i]
    order = -1
    break
  elsif ch > second[i]
    order = 1
    break
  end
end

puts order

s1=gets.chomp.downcase.split("")
s2=gets.chomp.downcase.split("")
n=s1.length
i,f = 0,1
until n==0
    if s1[i].ord<s2[i].ord
        puts -1
        f=0
        break
    elsif s1[i].ord>s2[i].ord
        puts 1
        f=0
        break
    end
    n -= 1
    i += 1
end
puts 0 if f==1

a, b = gets.chomp.downcase, gets.chomp.downcase

if a < b
  puts "-1"
elsif a > b
  puts "1"
else
  puts "0"
end

a = gets.chomp.downcase
b = gets.chomp.downcase
if a > b
	puts "1"
elsif a < b
	puts "-1"
else
	puts "0"
end

s1 = gets.chomp
s2 = gets.chomp

puts s1.casecmp s2

first_str = gets.chomp
second_str = gets.chomp
res = 0
for i in 0..first_str.length-1
	if first_str[i].downcase.ord < second_str[i].downcase.ord
		res = -1
		break
	elsif first_str[i].downcase.ord > second_str[i].downcase.ord
		res = 1
		break
	end
end
puts res

str1 = gets.chomp.capitalize
str2 = gets.chomp.capitalize
puts str1 <=> str2

s1 = gets.chomp.downcase
s2 = gets.chomp.downcase

puts s1 <=> s2

s = gets.chomp.upcase
t = gets.chomp.upcase
p -1 if s < t
p 0 if s == t
p 1 if s > t

s1 = gets
s2 = gets

s1 = s1.downcase
s2 = s2.downcase

if s1 > s2
    puts 1
elsif s1 == s2
    puts 0
else
    puts -1
end

a = gets.chomp.downcase
b = gets.chomp.downcase

puts a <=> b

s1 = gets.chomp
s2 = gets.chomp

if s1.size < s2.size
    p -1
elsif s2.size < s1.size
    p 1
else
    s1 = s1.downcase
    s2 = s2.downcase
    len = s1.size - 1

    for i in 0..len
        if s1[i] < s2[i]
            p -1
            break
        elsif s2[i] < s1[i]
            p 1
            break
        elsif i != len
            next
        else
            p 0
        end
    end
end

a = gets.chomp.downcase
b = gets.chomp.downcase

if a == b
  puts 0
elsif a < b
  puts -1
else
  puts 1
end

string1 = gets.chomp.to_s.upcase
string2 = gets.chomp.to_s.upcase
if string1 == string2
  puts '0'
elsif string1 < string2
  puts '-1'
else
  puts '1'
end

a =  gets.chomp.downcase
b = gets.chomp.downcase

n = a.length
flag = 0
for i in 0..n-1 do
if a[i] == b[i]
next
elsif a[i] < b[i]
flag = 1
puts "-1"
break
else
flag = 1
puts "1"
break
end
end
puts "0" unless flag == 1

a, b = gets.downcase, gets.downcase
puts a == b ? 0 : (a < b ? -1 : 1)

n = gets.chomp.downcase
m = gets.chomp.downcase
a = 0

if n == m
  puts "0"
  exit
end

while n[a] == m[a]
  a += 1
end

if n[a] < m[a]
  puts "-1"
elsif n[a] > m[a]
  puts "1"
end

a = gets.chomp.downcase
b = gets.chomp.downcase

if a < b then puts(-1) elsif a == b then puts(0) else puts(1) end

#!/usr/local/bin/ruby -w

s1 = gets.chomp.downcase
s2 = gets.chomp.downcase

if (s1>s2)
	puts "#{1}"
elsif (s1<s2)
	puts "#{-1}"
else
	puts "#{0}"
end

x = gets.chomp.downcase
y = gets.chomp.downcase

if x==y
	puts 0
elsif x > y
	puts 1
else
	puts -1
end

print gets.chomp.upcase <=> gets.chomp.upcase

first_word, second_word = STDIN.read.split
puts first_word.downcase <=> second_word.downcase

a = gets.strip
b = gets.strip
a.downcase!
b.downcase!
puts a < b ? -1 : (a == b ? 0 : 1)

def order(a,b)
  if a.nil?
    return 0
  end
  if a[0] == b[0]
    order(a[1..-1], b[1..-1])
  elsif a > b
    return 1
  elsif a < b
    return -1
  end
end

def call ()
  a = gets.chomp
  b = gets.chomp
  a.downcase!
  b.downcase!
  puts order(a,b)
end

call

s1 = gets.chomp.downcase
s2 = gets.chomp.downcase

puts s1 <=> s2

s0 = gets.chomp.downcase
s1 = gets.chomp.downcase

if s0 == s1
  puts 0
elsif s0 < s1
  puts -1
else
  puts 1
end

a = gets.chomp
b = gets.chomp
a.downcase!
b.downcase!
if a > b
    puts 1
elsif b > a
    puts -1
else
    puts 0
end

puts gets.capitalize <=> gets.capitalize

a = gets.to_s
b = gets.to_s
if a.upcase == b.upcase
  p 0
else
if a.upcase > b.upcase
  p 1
else
  p -1
end
end

a,b=[gets, gets].map(&:downcase)
p a<=>b

str1 = gets.chomp.capitalize
str2 = gets.chomp.capitalize
puts str1 <=> str2

a = gets.chomp.downcase
b = gets.chomp.downcase
if(a==b)
  puts 0
else
  puts a < b ? -1 : 1
end

a, b = gets.downcase, gets.downcase
puts a == b ? 0 : (a < b ? -1 : 1)

#! usr/bin/env ruby

p gets.casecmp gets
# p gets.upcase <=> gets.upcase

a=gets.chomp.upcase
b=gets.chomp.upcase
p a<=>b

s = gets.strip.downcase
t = gets.strip.downcase
puts(s < t ? -1 : s == t ? 0 : 1)

a = gets.downcase
b = gets.downcase
if a == b
	puts "0"
else
	puts a > b ? 1 : -1
end

a = gets.chomp.split.map(&:downcase).join
b = gets.chomp.split.map(&:downcase).join
puts (a == b) ? 0 : a>b ? 1 : -1

a = $stdin.readline ; b = $stdin.readline
a.upcase! ; b.upcase!
puts a <=> b

first_word, second_word = STDIN.read.split
puts first_word.downcase <=> second_word.downcase

n = gets.chomp.downcase
m = gets.chomp.downcase

if n[-1] < m[-1]
  puts "-1"
elsif n[-1] > m[-1]
  puts "1"
else
  puts "0"
end

a=gets.chomp.upcase
b=gets.chomp.upcase
a.size.times{|x|
if a[x].chr>b[x].chr
print 1
elsif b[x].chr>a[x].chr
print -1
elsif x==a.size-1
print 0
end}

str1 = gets.chomp.downcase

str2 = gets.chomp.downcase

if str1 == str2
  print "equale"
elsif str1 < str2
  print "-1"
elsif str1 > str2
  print "1"
elsif str1 == str2
  print "0"
end

def order(a,b)
  if a.nil?
    return 0
  end
  if a[0] == b[0]
    order(a[1..-1], b[1..-1])
  elsif a > b
    return 1
  elsif a < b
    return -1
  end
end

def call ()
  a = gets.chomp
  b = gets.chomp
  a.downcase!
  b.downcase!
  order(a,b)
end

call

def run(input = STDIN.read)
  line1, line2 = input.split("\n")
  line1.each_char.each_with_index do |char, index|
    puts "-1" && return if char.downcase != line2[index].downcase
  end
  puts "0" && return
end

run

def run(input = STDIN.read)
  line1, line2 = input.split("\n")
  line1.each_char.each_with_index do |char, index|
    return -1 if char.downcase != line2[index].downcase
  end
  return 0
end

run

s1=gets.chomp.downcase.split("")
s2=gets.chomp.downcase.split("")
n=s1.length
i,f=0,1
until n<0
    if s1[i].ord<s2[i].ord
        puts -1
        f=0
        break
    elsif s1[i].ord>s2[i].ord
        puts 1
        f=0
        break
    end
    n -= 1
end
puts 0 if f==1

sum1,sum2,i,j = 0,0,0,0
s1=gets.chomp.downcase.split("").each do |x|
    sum1 += x.ord*(101-i)
    i += 1
end
s2=gets.chomp.downcase.split("").each do |x|
    sum2 += x.ord*(101-j)
    j += 1
end
if sum1 < sum2
    puts -1
elsif sum1 == sum2
    puts 0
elsif sum1 < sum2
    puts 1
end

sum1,sum2=0,0
s1=gets.chomp.downcase.split('').map{|ch| ch.ord}.each {|x| sum1+=x }
s2=gets.chomp.downcase.split('').map{|ch| ch.ord}.each {|x| sum2+=x }
if sum1==sum2
    puts 0
else
    puts (sum1-sum2)/(sum1-sum2).abs
end

sum1,sum2,i,j = 0,0,0,0
s1=gets.chomp.downcase.split("").each do |x|
    sum1 += (x.ord-96)*(101-i)
    i += 1
end
s2=gets.chomp.downcase.split("").each do |x|
    sum2 += (x.ord-96)*(101-j)
    j += 1
end
if sum1 < sum2
    puts -1
elsif sum1 == sum2
    puts 0
elsif sum1 > sum2
    puts 1
end

sum1,sum2=0,0
s1=gets.chomp.downcase.split('').map{|ch| ch.to_i}.each {|x| sum1+=x }
s2=gets.chomp.downcase.split('').map{|ch| ch.to_i}.each {|x| sum2+=x }
if sum1-sum2==0
    puts 0
else
    puts (sum1-sum2)/(sum1-sum2).abs
end

n=0
a=gets.downcase
b=gets.downcase
a.length.times{|i|
n += a[i]<=>b[i]}
n != 0? n/=n : ()
p n

ans=0

a=gets.downcase.sum

b=gets.downcase.sum

if a>b then
	ans=1
elsif a<b then
	ans=-1
end

p ans

la,lb,ans=0,0,0

a=gets.downcase.each_byte {|x|
    la+=x}

b=gets.downcase.each_byte {|x|
    lb+=x}

if la>lb then
	ans=1
elsif a<b then
	ans=-1
end

p ans

la,lb,ans=0,0,0

a=gets.downcase.each_byte {|x|
    la+=x}

b=gets.downcase.each_byte {|x|
    lb+=x}

if la>lb then
	ans=1
elsif la<lb then
	ans=-1
end

p ans

n=0
a=gets.downcase
b=gets.downcase
a.length.times{|i|
n += a[i]<=>b[i]}
n != 0? n/=n.abs : ()
p n

a=gets.downcase.sum
b=gets.downcase.sum
puts a<=>b

str1 = gets.chomp.bytes.to_a
str2 = gets.chomp.bytes.to_a

str1.each_with_index do |c, i|
  if c < str2[i]
    puts '-1'
    exit
  elsif c > str2[i]
    puts '1'
    exit
  end
end

puts '0'

a = gets.to_s
b =  gets.to_s
if a == b
  p 0
else
if a > b
  p 1
else
  p -1
end
end

s1 = gets.chomp
s2 = gets.chomp
if s1.upcase==s2.upcase
    puts 0
end
if s2.upcase<s1.upcase
    puts 1
end
if s1.upcase>s2.upcase
    put -1
end

str1 = gets.chomp.to_s
str2 = gets.chomp.to_s

puts str1 <=> str2

a=gets.strip.downcase
b=gets.strip.downcase
puts 0 and return if a == b
def compare a1,a2
	val = (a1 != a2) ? ((a1 > a2) ? 1 : -1 ) : 0
	return val
end
for i in 0..a.length-1
	c = compare a[i].ord,b[i].ord
	puts c and break if c != 0
end

a=gets.strip
b=gets.strip
t1 = a.downcase.each_byte.to_a.inject(0){|total,num| total+num}
t2= b.downcase.each_byte.to_a.inject(0){|total,num| total+num}
result = t1 == t2 ? 0 : (t1 > t2) ? 1 : -1
puts result

str1 = gets.chomp.downcase
str2 = gets.chomp.downcase

if str1 == str2
    puts 0
else
    puts -1
end

str1 = gets.chomp.capitalize!
str2 = gets.chomp.capitalize!
puts str1 <=> str2

first_line = gets.chomp
second_line = gets.chomp

first_line = first_line.downcase
second_line = second_line.downcase
sum_1 = 0
sum_2 = 0

	first_line.each_char.each do |value|
		sum_1 += value.ord
	end

	second_line.each_char.each do |value|
		sum_2 += value.ord
	end
	puts 0 if sum_1 == sum_2
	puts -1 if sum_1 < sum_2
	puts 1 if sum_1 > sum_2

first_string = gets.strip.split('').map(&:downcase)
second_string = gets.strip.split('').map(&:downcase)

def compare_strings(first_string, second_string)
  return (puts 0) if first_string == second_string
  first_string.each_with_index do |char, index|
    unless char == second_string[index]
      char > second_string[index] ? (return 1) : (return -1)
    end
  end
end

compare_strings(first_string, second_string)

first_string = gets.strip.split('').map(&:downcase)
second_string = gets.strip.split('').map(&:downcase)

def compare_strings(first_string, second_string)
  return 0 if first_string == second_string
  first_string.each_with_index do |char, index|
    unless char == second_string[index]
      char > second_string[index] ? (return ()) : (return -1)
    end
  end
end

puts compare_strings(first_string, second_string)

x = gets.chomp()
y = gets.chomp()
x = x.upcase()
y = y.upcase()
if x>y
	puts -1
elsif x==y
	puts 0
else
	puts 1
end

a = gets.chomp.downcase
b = gets.chomp.downcase

i = a.length
i.times do
if a[i] == b [i]
next
elsif a[i] < b [i]
puts "-1"
break
else
puts "1"
break
end
puts "0"
end

a = gets.chomp.downcase
b = gets.chomp.downcase

i = a.length
i.times do
if a[i-1] == b [i-1]
next
elsif a[i-1] < b [i-1]
puts "-1"
break
else
puts "1"
break
end
puts "0"
end


There are three friend living on the straight line Ox in Lineland. The first friend lives at the point x1, the second friend lives at the point x2, and the third friend lives at the point x3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to travel in order to meet at some point and celebrate the New Year?It's guaranteed that the optimal answer is always integer.

The first line of the input contains three distinct integers x1, x2 and x3 (1 ≤ x1, x2, x3 ≤ 100) — the coordinates of the houses of the first, the second and the third friends respectively.

Print one integer — the minimum total distance the friends need to travel in order to meet together.

NoteIn the first sample, friends should meet at the point 4. Thus, the first friend has to travel the distance of 3 (from the point 7 to the point 4), the second friend also has to travel the distance of 3 (from the point 1 to the point 4), while the third friend should not go anywhere because he lives at the point 4.

input = gets.split(" ").map! { |i| i.to_i }

max = input.sort[input.size-1]
min_d = 300

for p in 1..max
	cDist = (p - input[0]).abs + (p - input[1]).abs + (p - input[2]).abs
	if  cDist < min_d
		min_d = cDist
	end
end

puts min_d

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

puts xs.max - xs.min

d = gets.chomp
distances = d.split

for i in (0..distances.size-1)
	for x in (0..distances.size-1)
		if i != x
			if distances[i].to_i < distances[x].to_i
				temp = distances[x].to_i
				distances[x] = distances[i].to_i
				distances[i] = temp
			end
		end
	end
end

distance = 0
for i in (0..distances.size-1)
	if i != distances.size-1
		if distances[i].to_i <= distances[i+1]
			distance += (distances[i+1].to_i - distances[i].to_i)
		else
			distance += (distances[i].to_i - distances[i+1].to_i)
		end
	end
end

print distance

a, b, c = gets.split.map(&:to_i).sort
p c - a

def max(a,b,c)
    if (a >= b) && (a >= c)
        return a
    end
    if (b >= a) && (b >= c)
        return b
    end
    if (c >= a) && (c >= b)
        return c
    end
end

def min(a,b,c)
    if (a <= b) && (a <= c)
        return a
    end
    if (b <= a) && (b <= c)
        return b
    end
    if (c <= a) && (c <= b)
        return c
    end
end

line = gets
x1 = line.split(' ')[0].to_i
x2 = line.split(' ')[1].to_i
x3 = line.split(' ')[2].to_i

puts  max(x1,x2,x3) - min(x1,x2,x3)

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

puts a.max - a.min

a, b, c = gets.split.map(&:to_i).sort
puts c - a

input = gets.chomp.split(' ').map(&:to_i)
input.sort!
puts input[input.length - 1] - input[0]

# -*- mode: ruby -*-
# vi: set ft=ruby :

arr = gets.split.map{|x| x.to_i}.sort
puts arr[-1]-arr[0]

x1,x2,x3 = gets.split.map(&:to_i).sort

puts x3-x1

xs = gets.split.map(&:to_i)
puts ((1..100).map do |i|
  xs.map { |x| (x - i).abs }.inject(&:+)
end.min)

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

puts (b - a) + (c - b)

a = gets.split.map(&:to_i)
puts a.max - a.min

a = gets.split.map(&:to_i)
a.sort!
puts a[1] - a[0] + a[2] - a[1]

x = gets.split.map(&:to_i)
x.sort!
puts x[1]-x[0] + x[2]-x[1]

debug = FALSE#TRUE
fin = (if debug then File.open "tc.txt" else $stdin end)

input = fin.read.chomp.split /\s/
a = []
input.each do |x|
	a << x.to_i
end
a.sort!

#a.each do |x| print x.to_s + " " end

meet = a[0]
res = 1000000
begin
	sum = ((a[0]-meet).abs) + ((a[1]-meet).abs) + ((a[2]-meet).abs)
	res = sum if sum<res
	meet += 1
end until meet > a[2]

print res
fin.close

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

puts (a-b).abs + (b-c).abs

x, y, z = gets.strip.split.map(&:to_i)
a = [x, y, z].min
b = [x, y, z].max
ans = b - a
puts ans

a, b = gets.split.map(&:to_i).minmax
puts b - a

a = gets.split.map(&:to_i).sort!
puts a[1] - a[0] + a[2] - a[1]

res=0
gets.split.map(&:to_i).sort.each_cons(2){|a, b| res+=b-a}
puts res

while str = STDIN.gets
  array = str.split(' ').map{|_| _.to_i}
  min = 999
  for i in 1..(array.max)
    total = (i - array[0]).abs + (i - array[1]).abs + (i - array[2]).abs
    min = total if min > total
  end
  puts min
end

a, b, c = gets.split.map(&:to_i)
s = a + b + c
if s % 3 == 0
  g = s / 3
  p (a - g).abs + (b - g).abs + (c - g).abs
else
  t1 = (s / 3.0).ceil
  t2 = s / 3
  p [(a - t1).abs + (b - t1).abs + (c - t1).abs, (a - t2).abs + (b - t2).abs + (c - t2).abs].min
end

a, b, c = gets.split.map(&:to_i)
g = (a + b + c) / 3
p (a - g).abs + (b - g).abs + (c - g).abs

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

sum = input.reduce(:+)
sum /= 3
ans = 0

input.each do |i|
	ans += (sum - i).abs
end

puts ans

a = gets.split.map(&:to_i)
a.sort!
x = (a.first + a.last) / 2
puts x - a.first + [ a[1] - x, x - a[1] ].max + a.last - x

while str = STDIN.gets
  array = str.split(' ').map{|_| _.to_i}
  ave = array.inject(0.0){|r, i| r += i } / array.size
  puts array.map{|_| (ave - _).abs}.inject {|sum, n| sum + n}.to_i
end

while str = STDIN.gets
  array = str.split(' ').map{|_| _.to_i}
  ave = array.inject(0.0){|r, i| r += i } / array.size
  puts array.map{|_| (ave - _).abs}.inject {|sum, n| sum + n}.ceil
end

while str = STDIN.gets
  array = str.split(' ').map{|_| _.to_i}
  ave = array.inject(0.0){|r, i| r += i } / array.size
  puts array.map{|_| (ave - _).abs}.inject {|sum, n| sum + n}.round
end

input = gets.split(" ")

middle_pt = 0
input.each do |i|
	middle_pt = middle_pt + i.to_i
end

middle_pt = middle_pt / input.size

total_dist = 0
input.each do |i|
	total_dist = total_dist + (i.to_i - middle_pt).abs
end

puts total_dist

input = gets.split(" ")
input = input.sort

total_dist = 0

for i in 1..input.length-1
	total_dist = total_dist + (input[i].to_i - input[i-1].to_i)
end

puts total_dist


Tonio has a keyboard with only two letters, "V" and "K".One day, he has typed out a string s with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no changes) to maximize the number of occurrences of that string. Compute the maximum number of times "VK" can appear as a substring (i. e. a letter "K" right after a letter "V") in the resulting string.

The first line will contain a string s consisting only of uppercase English letters "V" and "K" with length not less than 1 and not greater than 100.

Output a single integer, the maximum number of times "VK" can appear as a substring of the given string after changing at most one character.

NoteFor the first case, we do not change any letters. "VK" appears once, which is the maximum number of times it could appear.For the second case, we can change the second character from a "V" to a "K". This will give us the string "VK". This has one occurrence of the string "VK" as a substring.For the fourth case, we can change the fourth character from a "K" to a "V". This will give us the string "VKKVKKKKKKVVVVVVVVVK". This has three occurrences of the string "VK" as a substring. We can check no other moves can give us strictly more occurrences.

s = gets
if s[-1] == "\n"
  s = s.split("\n")[0].to_s
end
res = 0
changed = false
i = 0
while i < s.size
  if s[i] == 'V' && s[i+1] == 'K'
    i += 2
    res += 1
    next
  end
  if changed
    i += 1
    next
  end
  if s[i] == 'K' && s[i+1] == 'K' ||
    s[i] == 'V' && s[i+1] == 'V' && (s[i+2] == 'V' || s[i+2] == nil)
    res += 1
    i += 2
    changed = true
    next
  end
  i += 1
end

puts res

# kkk  +1

# kkv skip
# kvk skip
# vkk skip

# vvk skip
# vkv skip
# kvv

# vvv +1

k_counter = 0
v_counter = 0
vk = 0
v = 0
k = 0

s = gets.chomp
s << "V"
s = "K" << s
(0..s.length-1).each do |x|
  if s[x] == "V"
    v_counter = v_counter + 1
    k_counter = 0
    v = 1 if v_counter == 3
    vk = vk + 1 if (x+1 <= (s.length-1)) && s[x+1] =="K"
  else
    k_counter = k_counter + 1
    v_counter = 0
    k = 1 if k_counter == 3
  end
end
vk = vk + 1 if v == 1 || k == 1
puts vk

s=gets.chomp
r=s.scan('VK').size
s.size.times{|i|
	s[i]=s[i].tr('VK','KV')
	r=[r,s.scan('VK').size].max
	s[i]=s[i].tr('VK','KV')
}
p r

str1 = gets().chomp
str1_count = str1.scan(/VK/).size
if (str1.scan(/VVV/).size >= 1) || (str1.scan(/KKK/).size >= 1) || (str1[0,2]=='KK') || (str1[-2,str1.size]=='VV')
  str1_count += 1
end
p str1_count

s = gets
puts s.length - s.gsub('VK', ' ').sub(/KK|VV/, ' ').length

s = gets
res = 0
changed = false
i = 0
while i < s.size
  if s[i] == 'V' && s[i+1] == 'K'
    i += 2
    res += 1
    next
  end
  if changed
    i += 1
    next
  end
  if s[i] == 'K' && s[i+1] == 'K' ||
    s[i] == 'V' && s[i+1] == 'V' && (s[i+2] == 'V' || s[i+2] == nil)
    res += 1
    i += 2
    changed = true
    next
  end
  i += 1
end

puts res

# kkk  +1

# kkv skip
# kvk skip
# vkk skip

# vvk skip
# vkv skip
# kvv

# vvv +1

k_counter = 0
v_counter = 0
vk = 0
v = 0
k = 0

s = gets()
s << "V"
(0..s.length-1).each do |x|
  if s[x] == "V"
    v_counter = v_counter + 1
    k_counter = 0
    v = 1 if v_counter == 3
    vk = vk + 1 if (x+1 <= (s.length-1)) && s[x+1] =="K"
  else
    k_counter = k_counter + 1
    v_counter = 0
    k = 1 if k_counter == 3
  end
end
vk = vk + 1 if v == 1 || k == 1
puts vk

# kkk  +1

# kkv skip
# kvk skip
# vkk skip

# vvk skip
# vkv skip
# kvv

# vvv +1

k_counter = 0
v_counter = 0
vk = 0
v = 0
k = 0

s = gets()
(0..s.length-1).each do |x|
  if s[x] == "V"
    v_counter = v_counter + 1
    k_counter = 0
    v = 1 if v_counter == 3
    vk = vk + 1 if (x+1 <= (s.length-1)) && s[x+1] =="K"
  else
    k_counter = k_counter + 1
    v_counter = 0
    k = 1 if k_counter == 3
  end
end
vk = vk + 1 if v == 1 || k == 1
puts vk

# kkk  +1

# kkv skip
# kvk skip
# vkk skip

# vvk skip
# vkv skip
# kvv

# vvv +1

k_counter = 0
v_counter = 0
vk = 0
v = 0
k = 0

s = gets.chomp
s << "V"
# puts s
(0..s.length-1).each do |x|
  if s[x] == "V"
    v_counter = v_counter + 1
    k_counter = 0
    v = 1 if v_counter == 3
    vk = vk + 1 if (x+1 <= (s.length-1)) && s[x+1] =="K"
  else
    k_counter = k_counter + 1
    v_counter = 0
    k = 1 if k_counter == 3
  end
end
vk = vk + 1 if v == 1 || k == 1
puts vk

str1 = gets().chomp
str1_count = str1.scan(/VK/).size
if (str1_count != 0 && str1.scan(/VVV/||/KKK/).size > 0) || (str1[0,2]=='KK') || (str1[-2,str1.size]=='VV')
  str1_count += 1
end
p str1_count

str1 = gets().chomp
str1_count = str1.scan(/VK/).size
if (str1_count != 0 && str1.scan(/VVV/||/KKK/).size > 0) || (str1_count == 0 && str1.scan(/VV/||/KK/).size > 0) || (str1[0,2]=='KK' || str1[0,2]=='VV')
  str1_count += 1
end
p str1_count

str1 = gets().chomp
str1_count = str1.scan(/VK/).size
if (str1_count != 0 && str1.scan(/VVV/&&/KKK/).size > 0) || (str1_count == 0 && str1.scan(/VV/&&/KK/).size > 0)
  str1_count += 1
end
p str1_count

str1 = gets().chomp
str1_count = str1.scan(/VK/).size
if (str1_count != 0 && str1.scan(/VVV/||/KKK/).size > 0) || (str1_count == 0 && str1.scan(/VV/||/KK/).size > 0) || (str1[0,2]=='KK')
  str1_count += 1
end
p str1_count

str1 = gets().chomp
str1_count = str1.scan(/VK/).size
if (str1.scan(/VVV/||/KKK/).size > 0) || (str1[0,2]=='KK') || (str1[-2,str1.size]=='VV')
  str1_count += 1
end
p str1_count

str1 = gets().chomp
str1_count = str1.scan(/VK/).size
if str1.scan(/VVV/&&/KKK/).size > 0
  str1_count += 1
end
p str1_count

str1 = gets().chomp
str1_count = str1.scan(/VK/).size
if (str1_count != 0 && str1.scan(/VVV/||/KKK/).size > 0) || (str1_count == 0 && str1.scan(/VV/||/KK/).size > 0)
  str1_count += 1
end
p str1_count

s = gets
x = s.gsub('VK', '').length
x -= 2 if x > 1
puts (s.length - x) / 2

s = gets.strip
t = s.gsub('VK', '')
x = t.length
x -= 2 if (x > 2 || x == 2 && t != 'KV')
puts (s.length - x) / 2

s = gets.strip
x = s.gsub('VK', '').length
x -= 2 if x > 1
puts (s.length - x) / 2

s = gets
puts (s.length - s.gsub('VK','').sub('KV','').length) / 2

s = gets.strip
t = s.gsub('VK', '')
x = t.length
x += 2 if (x > 1 && t[0] + t[-1] != 'VK')
puts (t.length - x) / 2

s = gets
t = s.gsub('VK', ' ')
puts s.length - t.length + ((t.include? 'VV'||(t.include? 'KK')) ? 1 : 0)

s = gets
puts (s.length - s.gsub('VK', '').sub('VV', '').sub('KK', '').length) / 2

s = gets.strip
t = s.gsub('VK', '')
x = t.length
x -= 2 if (x > 1 && t[0] + t[-1] != 'VK')
puts (t.length - x) / 2

s = gets
puts (s.length - s.gsub('VK', '').sub('V', '').sub('K', '').length) / 2


Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev decided to build a house of cards. For that they've already found a hefty deck of n playing cards. Let's describe the house they want to make:   The house consists of some non-zero number of floors.  Each floor consists of a non-zero number of rooms and the ceiling. A room is two cards that are leaned towards each other. The rooms are made in a row, each two adjoining rooms share a ceiling made by another card.  Each floor besides for the lowest one should contain less rooms than the floor below. Please note that the house may end by the floor with more than one room, and in this case they also must be covered by the ceiling. Also, the number of rooms on the adjoining floors doesn't have to differ by one, the difference may be more. While bears are practicing to put cards, Horace tries to figure out how many floors their house should consist of. The height of the house is the number of floors in it. It is possible that you can make a lot of different houses of different heights out of n cards. It seems that the elephant cannot solve this problem and he asks you to count the number of the distinct heights of the houses that they can make using exactly n cards.

The single line contains integer n (1 ≤ n ≤ 1012) — the number of cards.

Print the number of distinct heights that the houses made of exactly n cards can have.

NoteIn the first sample you can build only these two houses (remember, you must use all the cards):  Thus, 13 cards are enough only for two floor houses, so the answer is 1.The six cards in the second sample are not enough to build any house.

#!/usr/bin/env ruby

n = gets.to_i

l, r = 0, n
while l != r
  m = (l + r + 1) / 2
  need = 3 * m * (m + 1) / 2 - m
  if need <= n
    l = m
  else
    r = m - 1
  end
end

l -= 1 while l > 0 && [0, 2, 1][l % 3] != n % 3
puts (l + 2) / 3


You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect.The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the two squares only share one common point, they are also considered to intersect.

The input data consists of two lines, one for each square, both containing 4 pairs of integers. Each pair represents coordinates of one vertex of the square. Coordinates within each line are either in clockwise or counterclockwise order. The first line contains the coordinates of the square with sides parallel to the coordinate axes, the second line contains the coordinates of the square at 45 degrees. All the values are integer and between $$$-100$$$ and $$$100$$$.

Print "Yes" if squares intersect, otherwise print "No". You can print each letter in any case (upper or lower).

NoteIn the first example the second square lies entirely within the first square, so they do intersect.In the second sample squares do not have any points in common.Here are images corresponding to the samples:

def check(as, bs)
    ax = [0,2,4,6].map{|i|as[i]}
    ay = [1,3,5,7].map{|i|as[i]}
    bcx = [0,2,4,6].map{|i|bs[i]}.inject(:+)/4.to_f
    bcy = [1,3,5,7].map{|i|bs[i]}.inject(:+)/4.to_f
    [bs[0,2], bs[2,2], bs[4,2], bs[6,2], [bcx,bcy]].each do |bx, by|
        if bx.between?(ax.min, ax.max) && by.between?(ay.min, ay.max)
            puts 'YES'
            exit
        end
    end
end

as = gets.split.map(&:to_i)
bs = gets.split.map(&:to_i)

check(as, bs)
4.times do |i|
    as[2*i], as[2*i+1] = [as[2*i] + as[2*i+1], as[2*i] - as[2*i+1]]
    bs[2*i], bs[2*i+1] = [bs[2*i] + bs[2*i+1], bs[2*i] - bs[2*i+1]]
end
check(bs, as)
puts 'NO'


DO YOU EXPECT ME TO FIND THIS OUT?WHAT BASE AND/XOR LANGUAGE INCLUDES string?DON'T BYTE OF MORE THAN YOU CAN CHEWYOU CAN ONLY DISTORT THE LARGEST OF MATHEMATICS SO FARSAYING "ABRACADABRA" WITHOUT A MAGIC AND WON'T DO YOU ANY GOODTHE LAST STACK RUPTURES. ALL DIE. OH, THE EMBARRASSMENT!I HAVE NO ARRAY AND I MUST SCREAMELEMENTS MAY NOT BE STORED IN WEST HYPERSPACE

The first line of input data contains a single integer n (1 ≤ n ≤ 10). The second line of input data contains n space-separated integers ai (1 ≤ ai ≤ 11).

gets
a=gets.split.map(&:to_i)
p a[-1]^a.max

gets
a = gets.split(/\s+/).map(&:to_i)

last = a[-1]
max = a.max
puts last ^ max


The Fair Nut lives in $$$n$$$ story house. $$$a_i$$$ people live on the $$$i$$$-th floor of the house. Every person uses elevator twice a day: to get from the floor where he/she lives to the ground (first) floor and to get from the first floor to the floor where he/she lives, when he/she comes back home in the evening. It was decided that elevator, when it is not used, will stay on the $$$x$$$-th floor, but $$$x$$$ hasn't been chosen yet. When a person needs to get from floor $$$a$$$ to floor $$$b$$$, elevator follows the simple algorithm:   Moves from the $$$x$$$-th floor (initially it stays on the $$$x$$$-th floor) to the $$$a$$$-th and takes the passenger.  Moves from the $$$a$$$-th floor to the $$$b$$$-th floor and lets out the passenger (if $$$a$$$ equals $$$b$$$, elevator just opens and closes the doors, but still comes to the floor from the $$$x$$$-th floor).  Moves from the $$$b$$$-th floor back to the $$$x$$$-th.  The elevator never transposes more than one person and always goes back to the floor $$$x$$$ before transposing a next passenger. The elevator spends one unit of electricity to move between neighboring floors. So moving from the $$$a$$$-th floor to the $$$b$$$-th floor requires $$$|a - b|$$$ units of electricity.Your task is to help Nut to find the minimum number of electricity units, that it would be enough for one day, by choosing an optimal the $$$x$$$-th floor. Don't forget than elevator initially stays on the $$$x$$$-th floor.

The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of floors. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the number of people on each floor.

In a single line, print the answer to the problem — the minimum number of electricity units.

NoteIn the first example, the answer can be achieved by choosing the second floor as the $$$x$$$-th floor. Each person from the second floor (there are two of them) would spend $$$4$$$ units of electricity per day ($$$2$$$ to get down and $$$2$$$ to get up), and one person from the third would spend $$$8$$$ units of electricity per day ($$$4$$$ to get down and $$$4$$$ to get up). $$$4 \cdot 2 + 8 \cdot 1 = 16$$$.In the second example, the answer can be achieved by choosing the first floor as the $$$x$$$-th floor.

n = gets.to_i
a = gets.split.map(&:to_i)
ans = 10**9
for i in 0..n
    ret = 0
    for j in 0..n-1
        ret += ((j-i).abs+j+i)*a[j]*2
    end
    ans = ret if ans > ret
end
puts ans

n,s,*v=$<.read.split.map &:to_i
p [[(v.reduce(:+)-s)/n,*v].min,-1].max


The protection of a popular program developed by one of IT City companies is organized the following way. After installation it outputs a random five digit number which should be sent in SMS to a particular phone number. In response an SMS activation code arrives.A young hacker Vasya disassembled the program and found the algorithm that transforms the shown number into the activation code. Note: it is clear that Vasya is a law-abiding hacker, and made it for a noble purpose — to show the developer the imperfection of their protection.The found algorithm looks the following way. At first the digits of the number are shuffled in the following order <first digit><third digit><fifth digit><fourth digit><second digit>. For example the shuffle of 12345 should lead to 13542. On the second stage the number is raised to the fifth power. The result of the shuffle and exponentiation of the number 12345 is 455 422 043 125 550 171 232. The answer is the 5 last digits of this result. For the number 12345 the answer should be 71232.Vasya is going to write a keygen program implementing this algorithm. Can you do the same?

The only line of the input contains a positive integer five digit number for which the activation code should be found.

Output exactly 5 digits without spaces between them — the found activation code of the program.

code = gets.chomp
code = (code[0] + code[2] + code[4] + code[3] + code[1])
puts (code.to_i ** 5).to_s.chars.last(5).join

code = gets.chomp
puts ((code[0] + code[2] + code[4] + code[3] + code[1]).to_i ** 5).to_s.chars.last(5).join

code = gets.chomp
puts ((code[0] + code[2] + code[4] + code[3] + code[1]).to_i ** 5)%100000

puts 'Enter number'
code = gets.chomp
return unless code.length == 5
code = (code[0] + code[2] + code[4] + code[3] + code[1])
puts (code.to_i ** 5).to_s.chars.last(5).join


So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. One night, when everyone went to bed, someone took all the letters of our characters' names. Then he may have shuffled the letters and put them in one pile in front of the door.The next morning it was impossible to find the culprit who had made the disorder. But everybody wondered whether it is possible to restore the names of the host and his guests from the letters lying at the door? That is, we need to verify that there are no extra letters, and that nobody will need to cut more letters.Help the "New Year and Christmas Men" and their friends to cope with this problem. You are given both inscriptions that hung over the front door the previous night, and a pile of letters that were found at the front door next morning.

The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line does not exceed 100.

Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes.

NoteIn the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.In the second sample letter "P" is missing from the pile and there's an extra letter "L".In the third sample there's an extra letter "L".

s1 = gets.chomp
s2 = gets.chomp
s3 = gets.chomp
if (s1 + s2).split(//).sort.join == s3.split(//).sort.join
  puts "YES"
else
  puts "NO"
end

hs = Hash.new 0
gets.chomp.split(//).map{|x| hs[x]+=1}
gets.chomp.split(//).map{|x| hs[x]+=1}
gets.chomp.split(//).map{|x| hs[x]-=1}
if hs.any?{|_,v| v!=0}
  puts "NO"
else
  puts "YES"
end

first = gets.strip
last = gets.strip
all = first + last
full = gets.strip

a = 'A'.ord

arr = Array.new(26,0)

full.split("").each do |c|
	arr[c.ord-a] += 1
end

all.split("").each do |i|
	if arr[i.ord - a] <= 0
		puts "NO"
		exit
	end

	arr[i.ord - a ] -= 1

end

ans = arr.minmax

if ans[0] != 0 or ans[1] != 0
	puts "NO"
else
	puts "YES"
end

r = lambda { gets.strip.chars.sort }
puts (r.call + r.call).sort == r.call ? :YES : :NO

s1 = gets.chomp
s2 = gets.chomp
s = gets.chomp
p = s1.split("") + s2.split("")
s1 = s1.delete(s)
s2 = s2.delete(s)
if s1.empty? && s2.empty? && p.size == s.size then
    p.size.times do |i|
        s = s.sub(p[i], "")
    end
    if s.empty? then
        puts "YES"
    else
        puts "NO"
    end
else
    puts "NO"
end

s1 = gets.chomp
s1 += gets.chomp
s2 = gets.chomp
if s1.split("").sort == s2.split("").sort
  puts "YES"
else
  puts "NO"
end

a = gets.scan /\w/
b = gets.scan /\w/
c = gets.scan /\w/

if  (a.size+b.size) != c.size
    puts "NO"
else
    a = a + b
    if(a.sort == c.sort)
        puts "YES"
    else
        puts "NO"
    end
end

puts (gets+gets).chars.sort == (gets+"\n").chars.sort ? :YES : :NO

def read_line
  STDIN.gets.chomp
end

s1 = read_line
s2 = read_line
s3 = read_line

if (s1+s2).each_char.sort == s3.each_char.sort
  puts "YES"
else
  puts "NO"
end

name1 = gets.chomp
name2 = gets.chomp
letters = gets.chomp

if (name1 + name2).split(//).sort == letters.split(//).sort
  puts "YES"
else
  puts "NO"
end

name1 = gets.chomp
name2 = gets.chomp
letters = gets.chomp

if (name1 + name2).split(//).sort.join == letters.split(//).sort.join
  puts "YES"
else
  puts "NO"
end

(STDIN.readline.chomp + STDIN.readline.chomp).chars.sort.join == STDIN.readline.chomp.chars.sort.join ? (puts "YES") : (puts "NO")

a = gets.chomp
b = gets.chomp

$x = []

def addToList s
  s.chars do |i|
    $x << i
  end
end

addToList a
addToList b

c = gets.chomp
c.chars do |i|
  d = $x.delete_at ($x.index(i) || $x.count)
  if d == nil
    puts "NO"
    exit
  end
end

if $x.count != 0 then puts "NO" else puts "YES" end

#!/usr/bin/env ruby

a = $stdin.readline
b = $stdin.readline
both = $stdin.readline

a1 = (a+b).split('').sort
a2 = both.split('').sort

a1.delete("\n")
a2.delete("\n")

if a1 == a2
	puts "YES"
else
	puts "NO"
end

string1 = gets.chomp
string2 = gets.chomp
string3 = gets.chomp

if string3.length - string2.length - string1.length != 0 then
    puts "NO"
else
    string3.split("").each do |c|
        if string1.include? c then
            string1.sub!(c, '')
        elsif string2.include? c then
            string2.sub!(c, '')
        end
    end

    if string1.empty? and string2.empty? then
        puts "YES"
    else
        puts "NO"
    end
end

originalName = (gets.split(//)+gets.split(//)).sort
newName = gets.split(//).sort
originalName.delete_if{|element| !element.between?('A', 'Z')}
newName.delete_if{|element| !element.between?('A', 'Z')}
if originalName==newName
    puts "YES"
else
    puts "NO"
end

puts (gets+gets).chars.sort==(gets+"\n").chars.sort ? :YES :"NO"

def check_pile(sa, sb, lf)
  freq_ab = Hash.new(0)
  sa.each_char {|c| freq_ab[c] += 1}
  sb.each_char {|c| freq_ab[c] += 1}

  # If any of the letters counted from the words is greater or less than 0,
  # it means that there are missing chars or more than expected
  # 0< Non existent characters
  # 0< More characters than expected
  # 0> Missing characters
  lf.each_char {|c| freq_ab[c] -= 1}
  freq_ab.each_value do |v|
    if v == 0
      next
    else
      return "NO"
    end
  end
  "YES"
end

string_a = gets.chomp
string_b = gets.chomp
letters_found = gets.chomp

puts check_pile(string_a, string_b, letters_found)

text1 = gets.chomp
text2 = gets.chomp
text = (text1 + text2).split('').sort.join
joke = gets.chomp.split('').sort.join
if text == joke
	puts "YES"
else
	puts "NO"
end

puts ( (gets.chomp + gets.chomp).chars.sort.join == gets.chomp.chars.sort.join ? "YES" : "NO" )

s1, s2, a = gets.strip, gets.strip, gets.strip
puts (s1 + s2).split('').sort == a.split('').sort ? "YES" : "NO"

a = gets.chomp
b = gets.chomp
t = gets.chomp

if (a+b).split('').sort == t.split('').sort
  puts "YES"
else
  puts "NO"
end

s = Array.new(3)
for i in 0..2
 s[i] = gets.chomp.to_s.split(//).sort
end

if (s[0] + s[1]).sort == s[2].sort
    puts "YES"
else
    puts "NO"
end

s = Array.new(3)
for i in 0..2
 s[i] = gets.chomp.to_s.split(//)
end

ans = false
if (s[0] + s[1]).sort == s[2].sort
    ans = true
end

puts ans ? "YES" : "NO"

a = $stdin.readline.scan(/./)
b = $stdin.readline.scan(/./)
c = $stdin.readline.scan(/./)

t = a+b

puts (t.sort == c.sort) ? "YES" : "NO"

can=true
a=gets.chomp
b=gets.chomp
c=gets.chomp
i=0
while i<a.length
    index_c=c.index(a[i])
    #puts index_c
    if(index_c===nil) then
        can=false
        #puts "NF a"
        break
    else
        c.slice!(index_c)
        #puts c
    end
    i+=1
end
#puts c

i=0
#puts b.length
while i<b.length
    index_c=c.index(b[i])
    #puts index_c
    if(index_c===nil) then
        can=false
        #puts "NF b"
        break
    else
        c.slice!(index_c)
        #puts c
    end
    i+=1
end
#puts c
#puts c.length
if(c.length==0 && can)
    print "YES"
else
    print "NO"
end

#!/usr/bin/ruby
a = gets.chomp.split('') + gets.chomp.split('')
rest = gets.chomp.split('')

if a.size != rest.size
  puts "NO"
  exit
end

0.upto(a.size-1) do |i|
  index = rest.index(a[i])
  if index == nil
    puts "NO"
    exit
  end

  rest.delete_at(index)
end

puts "YES"

puts (gets+gets).chars.sort==(gets+"\n").chars.sort ? :"YES" :"NO"

puts (gets.chomp+gets.chomp).chars.sort==(gets.chomp).chars.sort ? :YES :"NO"

letters = []
2.times do
  letters << gets.chomp.split("")
end
letters = letters.inject(:+)
pile = gets.chomp.split("")
puts letters.sort == pile.sort ? "YES" : "NO"

a=[]
2.times do
a=a+gets.chomp.split("")
end
a.sort!
c=gets.chomp.split("")
c.sort!
if a==c
puts "YES"
else
puts "NO"
end

s = (gets.chomp + gets.chomp).chars.sort.join
t = gets.chomp.chars.sort.join

if s == t
  puts 'YES'
else
  puts 'NO'
end

def count_chars counter, word
    word.each_char do |c|
        pos = c.ord - 'A'.ord
        counter[pos] += 1
    end
end
first = gets.strip
second = gets.strip
letters = gets.strip
count_exp = Array.new(26, 0)
count_act = Array.new(26, 0)
count_chars count_exp, first
count_chars count_exp, second
count_chars count_act, letters
ans = count_exp == count_act
puts ans ? "YES" : "NO"

  x = gets.chomp
  y = gets.chomp
  z = gets.chomp

  hash_x = {}
  hash_z = {}

  x.each_char { |c|
    hash_x[c] = 0 if hash_x[c] == nil
    hash_x[c] += 1
  }

  y.each_char { |c|
    hash_x[c] = 0 if hash_x[c] == nil
    hash_x[c] += 1
  }

  z.each_char { |c|
    hash_z[c] = 0 if hash_z[c] == nil
    hash_z[c] += 1
  }

  flag = true
  if z.length == x.length + y.length
    hash_x.each { |k,v|
      if v != (hash_z[k] == nil ? 0 : hash_z[k])
        flag = false
      end
    }
  else
    flag = false
  end
  if flag
    puts "YES"
  else
    puts "NO"
  end

g = gets.strip
r = gets.strip
p = gets.strip

h = Hash.new(0)

g.each_char do |c|
  h[c] += 1
end

r.each_char do |c|
  h[c] += 1
end

p.each_char do |c|
  h[c] -= 1
end

puts (h.values.all?{|i| i == 0;} ? "YES": "NO")

puts (gets.chomp +  gets.chomp).split('').sort == gets.chomp.split('').sort ? "YES" : "NO"

class String
  def is_permutation_of?(other)
    chars.sort == other.chars.sort
  end
end

guest_name, host_name, pile = STDIN.read.split
puts pile.is_permutation_of?(guest_name + host_name) ? :YES : :NO

strA = gets.strip
strB = gets.strip
strC = gets.strip

strAB_sorted = (strA + strB).split('').sort.join
strC_sorted = strC.split('').sort.join

if (strAB_sorted == strC_sorted)
  puts 'YES'
else
  puts 'NO'
end

a=(gets.chomp+gets.chomp).chars.sort.join
b=gets.chomp.chars.sort.join

puts (a==b ? 'YES':'NO')

a = gets.chomp.split(//)
b = gets.chomp.split(//)
c = gets.chomp.split(//)

puts ((a + b).sort <=> c.sort) == 0 ? 'YES' : 'NO'

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

guest = $stdin.gets.chomp
host = $stdin.gets.chomp
pile = $stdin.gets.chomp
if (guest + host).chars.sort == pile.chars.sort
  puts 'YES'
else
  puts 'NO'
end

str=gets;str<<gets.chomp;puts gets.split(//).sort == str.split(//).sort ? "YES" :"NO"

puts (gets.chomp+gets.chomp).chars.sort == gets.chomp.chars.sort ? :YES : :NO

a = gets.chomp.split('')
b = gets.chomp.split('')
c = gets.chomp.split('')
letters = Hash.new(0)
a.each { |e| letters[e] += 1 }
b.each { |e| letters[e] += 1 }
c.each { |e| letters[e] -= 1 }
puts letters.values.count { |e| e != 0 } == 0 ? "YES" : "NO"

guest = gets.chomp
residence = gets.chomp

found = gets.chomp

if (guest + residence).chars.sort == found.chars.sort
  puts "YES"
else
  puts "NO"
end

puts (gets+gets).chars.sort==(gets+"\n").chars.sort ? :YES :"NO"

def amusing_joke
  n1, n2, m = 3.times.map{|s| gets.strip }
  if n1.length + n2.length != m.length
    puts "NO"
    return
  end

  h = Hash.new(0)
  n1.each_char{|ch| h[ch] += 1}
  n2.each_char{|ch| h[ch] += 1}

  m.each_char{|ch| h[ch] -= 1}

  if h.select{|k,v| v>0}.size > 0
    puts "NO"
  else
    puts "YES"
  end
end

amusing_joke

name1 = gets.chomp
name1 = name1.split("")
name2 = gets.chomp
name2 = name2.split("")
letters = gets.chomp
letters = letters.split("")

if name1.size + name2.size > letters.size
	print "NO"
else
	count = 0
	for i in (0..name1.size-1)
		for x in (0..letters.size-1)
			if name1[i] == letters[x]
				count += 1
				letters.delete_at(x)
				break
			end
		end
	end
	for i in (0..name2.size-1)
		for x in (0..letters.size-1)
			if name2[i] == letters[x]
				count += 1
				letters.delete_at(x)
				break
			end
		end
	end
	if count == name1.size + name2.size && letters.size == 0
		print "YES"
	else
		print "NO"
	end
end

n = gets.chomp
m = gets.chomp
l = gets.chomp
puts (n + m).chars.sort == l.chars.sort  ? 'YES' : 'NO'

a = gets.chomp.chars + gets.chomp.chars
s = gets.chomp.chars
ans = true
if a.size != s.size
  ans = false
else
  a.size.times do |i|
    if s.index(a[i])
      s[s.index(a[i])] = nil
    else
      ans = false
    end
  end
end
puts ans ? "YES" : "NO"

a = gets.chomp.chars + gets.chomp.chars
s = gets.chomp.chars
ans = true
if a.size != s.size
  ans = false
else
  a.size.times do |i|
    note = 0
    s.size.times do |j|
      if a[i] == s[j]
        s[j] = " "
        note = 1
        break
      end
    end
    if note != 1
      ans = false
      break
    end
  end
end
puts ans ? "YES" : "NO"

a = gets.chomp.chars + gets.chomp.chars
b = gets.chomp.chars
puts a.sort == b.sort ? "YES" : "NO"

a = gets.chomp.chars + gets.chomp.chars
s = gets.chomp.chars
ans = true
if a.size != s.size
  ans = false
else
  a.each do |x|
    idx = s.index(x)
    if idx
      s[idx] = nil
    else
      ans = false
    end
  end
end
puts ans ? "YES" : "NO"

puts (gets.chomp + gets.chomp).chars.sort == gets.chomp.chars.sort ? "YES" : "NO"

h = Hash.new(0)
gets.chomp.each_char{|c| h[c] += 1}
gets.chomp.each_char{|c| h[c] += 1}
gets.chomp.each_char{|c| h[c] -= 1}
puts h.values.all?{|v|v == 0} ? "YES" : "NO"
#p h

expected = (gets.chomp + gets.chomp).chars.sort.join
actual = (gets.chomp).chars.sort.join
if expected == actual
    puts "YES"
else
    puts "NO"
end

puts (gets.chomp.chars + gets.chomp.chars).sort == gets.chomp.chars.sort ? 'YES' : 'NO'

guest = gets.chomp.split ""
host  = gets.chomp.split ""

result = guest.inject(Hash.new(0)) { |h, v| h[v] += 1; h }
result = host.inject(result) { |h, v| h[v] += 1; h }

answer = gets.chomp.split ""

for i in answer
  result[i] -= 1
end

a = true

result.each do |k, v|
  a &= v == 0

  break unless a
end

puts a ? "YES" : "NO"

#!/usr/bin/env ruby

$ma = {}
$ma.default = 0

gets.strip.split('').each { |c| $ma[c]+=1 }
gets.strip.split('').each { |c| $ma[c]+=1 }
gets.strip.split('').each { |c| $ma[c]-=1 }

flag = true;
$ma.each { |c,d|
   flag = false if d!=0
}

puts (flag ? "YES" : "NO")

def g
  gets.chomp.split("").sort.join
end
puts (g+g).split("").sort.join.eql?(g)?"YES":"NO"

a,b,c=3.times.map{gets.chomp.bytes.to_a}
puts (a+b).sort==c.sort ? "YES" : "NO"

a, b, c = STDIN.read.split("\n")
print (a + b).split(//).sort == c.split(//).sort ? :YES : :NO

h = Hash.new
h.default = 0
3.times do |i|
  s = gets.chop.each_char.to_a
  if i < 2
    s.each { |c| h[c] += 1 }
  else
    s.each { |c| h[c] -= 1 }
  end
end

if h.any? { |k, v| v < 0 }
  puts :NO
else
  puts :YES
end

a = []
3.times do |i|
  a[i] = gets.chop.each_char.to_a.sort.uniq
end
a[2] -= a[0] + a[1]
if a[2].empty?
  puts :YES
else
  puts :NO
end

s1 = gets.chomp
s2 = gets.chomp
s = gets.chomp
s = s.gsub(s1, "").gsub(s2, "")

if s.empty? then
    puts "YES"
else
    puts "NO"
end

s1 = gets.chomp
s2 = gets.chomp
s = gets.chomp
p = s1.split("") + s2.split("")
s1.delete(s)
s2.delete(s)
if s1.empty? && s2.empty? then
    p.size.times do |i|
        s = s.sub(p[i], "")
    end

    if s.empty? then
        puts "YES"
    else
        puts "NO"
    end
else
    puts "NO"
end

s1 = gets.chomp.split("")
s2 = gets.chomp.split("")
s = gets.chomp
p = s1 + s2
p.size.times do |i|
    s = s.sub(p[i], "")
end

if s.empty? then
    puts "YES"
else
    puts "NO"
end

s1 = gets.chomp
s2 = gets.chomp
s = gets.chomp
p = s1.split("") + s2.split("")
s1 = s1.delete(s)
s2 = s2.delete(s)
if s1.empty? && s2.empty? then
    p.size.times do |i|
        s = s.sub(p[i], "")
    end

    if s.empty? then
        puts "YES"
    else
        puts "NO"
    end
else
    puts "NO"
end

s1 = gets.chomp
s2 = gets.chomp
s = gets.chomp
s = s.gsub(s1, "")
s = s.gsub(s2, "")

if s.empty? then
    puts "YES"
else
    puts "NO"
end

def read_line
  STDIN.gets.chomp
end

s1 = read_line
s2 = read_line
s3 = read_line

ans = "YES"
s3.length.times do |i|
  c = s3[i]
  ans = "NO" if s1.count(c) + s2.count(c) != s3.count(c)
end

puts ans

name1 = gets.chomp
name2 = gets.chomp
letters = gets.chomp

if (name1 + name2).size == letters.size
  puts "YES"
else
  puts "NO"
end

  x = gets.chomp
  y = gets.chomp
  z = gets.chomp

  hash_x = {}
  hash_y = {}
  hash_z = {}

  x.each_char { |c|
    hash_x[c] = 0 if hash_x[c] == nil
    hash_x[c] += 1
  }

  y.each_char { |c|
    hash_y[c] = 0 if hash_y[c] == nil
    hash_y[c] += 1
  }

  z.each_char { |c|
    hash_z[c] = 0 if hash_z[c] == nil
    hash_z[c] += 1
  }

  flag = true
  hash_z.each { |k,v|
    if v != (hash_x[k] == nil ? 0 : hash_x[k]) + (hash_y[k] == nil ? 0 : hash_y[k])
      flag = false
    end
  }
  if flag
    puts "YES"
  else
    puts "NO"
  end

  x = gets.chomp
  y = gets.chomp
  z = gets.chomp

  hash_x = {}
  hash_z = {}

  x.each_char { |c|
    hash_x[c] = 0 if hash_x[c] == nil
    hash_x[c] += 1
  }

  y.each_char { |c|
    hash_x[c] = 0 if hash_x[c] == nil
    hash_x[c] += 1
  }

  z.each_char { |c|
    hash_z[c] = 0 if hash_z[c] == nil
    hash_z[c] += 1
  }

  flag = true
  hash_x.each { |k,v|
    if v != (hash_z[k] == nil ? 0 : hash_z[k])
      flag = false
    end
  }
  if flag
    puts "YES"
  else
    puts "NO"
  end

  x = gets.chomp
  y = gets.chomp
  z = gets.chomp

  hash_x = {}
  hash_z = {}

  x.each_char { |c|
    hash_x[c] = 0 if hash_x[c] == nil
    hash_x[c] += 1
  }

  y.each_char { |c|
    hash_x[c] = 0 if hash_x[c] == nil
    hash_x[c] += 1
  }

  z.each_char { |c|
    hash_z[c] = 0 if hash_z[c] == nil
    hash_z[c] += 1
  }

  flag = true
  if z.length == x.length + y.length
    hash_x.each { |k,v|
      if v != (hash_z[k] == nil ? 0 : hash_z[k])
        flag = false
      end
    }
  end
  if flag
    puts "YES"
  else
    puts "NO"
  end

a = gets.chomp.split('')
b = gets.chomp.split('')
c = gets.chomp.split('')
letters = Hash.new(0)
a.each { |e| letters[e] += 1 }
b.each { |e| letters[e] += 1 }
c.each { |e| letters[e] -= 1 }
puts letters.values.count { |e| e > 0 } == 0 ? "YES" : "NO"

guest = gets.chomp.split ""
host  = gets.chomp.split ""

result = guest.inject(Hash.new(0)) { |h, v| h[v] += 1; h }
result = host.inject(result) { |h, v| h[v] += 1; h }

answer = gets.chomp.split ""

a = true
for i in answer
  result[i] -= 1

  a = false if result[i] < 0
end

puts a ? "YES" : "NO"


Alice has a string $$$s$$$. She really likes the letter "a". She calls a string good if strictly more than half of the characters in that string are "a"s. For example "aaabb", "axaa" are good strings, and "baca", "awwwa", "" (empty string) are not.Alice can erase some characters from her string $$$s$$$. She would like to know what is the longest string remaining after erasing some characters (possibly zero) to get a good string. It is guaranteed that the string has at least one "a" in it, so the answer always exists.

The first line contains a string $$$s$$$ ($$$1 \leq |s| \leq 50$$$) consisting of lowercase English letters. It is guaranteed that there is at least one "a" in $$$s$$$.

Print a single integer, the length of the longest good string that Alice can get after erasing some characters from $$$s$$$.

NoteIn the first example, it's enough to erase any four of the "x"s. The answer is $$$3$$$ since that is the maximum number of characters that can remain.In the second example, we don't need to erase any characters.

s = readline.chomp
puts [s.length, 2 * s.count("a") - 1].min

#!usr/bin/env ruby

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

word = gets.chomp
word_len = word.size
a_count = word.count('a')

if word_len / 2 < a_count
  puts word_len
else
  puts 2 * a_count - 1
end

s = gets.chomp
p (s.length+1)/2 < s.count("a") ? s.length : s.count("a")*2-1

s = gets.chomp
ac = s.count('a')
puts [s.size, ac*2-1].min

def love(s)
	while "love" == "love"
		a = s.scan('a').length
		others = s.scan(/[b-z]/).length
		if a > others then return s.length else s = s.sub(/[b-z]/, '') end
	end
end

s = gets.chomp
puts(love(s))

s = gets.chomp
acnt = s.count("a")
if acnt > s.length / 2 then
	puts s.length
else
	puts 2 * acnt - 1
end

s = gets
n = s.count 'a'
puts [s.size, 2*n].min - 1


The cows have just learned what a primitive root is! Given a prime p, a primitive root  is an integer x (1 ≤ x < p) such that none of integers x - 1, x2 - 1, ..., xp - 2 - 1 are divisible by p, but xp - 1 - 1 is. Unfortunately, computing primitive roots can be time consuming, so the cows need your help. Given a prime p, help the cows find the number of primitive roots .

The input contains a single line containing an integer p (2 ≤ p < 2000). It is guaranteed that p is a prime.

Output on a single line the number of primitive roots .

NoteThe only primitive root  is 2.The primitive roots  are 2 and 3.

$a = Array.new(2001, 0)

def gcd(x, y)
  if y == 0
    return x
  end
  return gcd(y, x%y)
end

def phi(n)
  if $a[n] == 0
    for i in 1..n
	  if gcd(n, i) == 1
	    $a[n] += 1
	  end
	end
  end
  return $a[n]
end

p = gets.to_i
print phi(phi(p))

n=gets.to_i
k,s=0,0
for i in 1...n
	s=1
	for j in 1...n
		s*=i
		s%=n
		if (s-1)%n==0
			if j==n-1
				k+=1
			else
				break
			end
		end
	end
end
puts k

def check(i, n)
  x = i
  (n - 2).times do
    return 0 if x == 1
    x = (x * i) % n
  end
  x == 1 ? 1 : 0
end

def run
  n = $stdin.gets.to_i
  count = 0
  for i in 1...n
    count += check(i, n)
  end
  puts count
end

run if $0 == __FILE__

x = gets.split.map{|_|_.to_i}
ans=0
x[0].times{|id|
  i = id + 1
  r = true
  d = 1
  (x[0]-1).times{|j|
    d=(d*i)%x[0]
    if (j!=x[0]-2 && d == 1) || (j==x[0]-2 && d!=1) then
      r=false
      break
    end
  }
  ans+=1 if r
}
puts ans

p = gets.strip.to_i
ans = 0
(1...p).each do |x|
    found = true
    cur = 1
    (1...p).each do |y|
        cur *= x
        cur %= p
        if y == p - 1
            if cur != 1
                found = false
                break
            end
        elsif cur == 1
            found = false
            break
        end
    end
    ans += 1 if found
end
puts ans

p=gets.to_i
res=0
1.upto(p-1) {|x|
    n=x;
    ok=true
    (p-2).times {
        if (n-1+p)%p==0
            ok=false
            break
        end
        n=n*x%p
    }
    ok=ok and (n*x-1)%p==0
    res+=1 if ok
}
p res

require 'prime'

def phi(n)
  d = Prime.prime_division(n)
  d.each { |r, e| n = n * (r - 1) / r }
  n
end

def has_primitive_root?(n)
  return true if n == 1 || n == 2 || n == 4
  return false if n.to_s(2)[1..-1].chars.uniq == [?0] # power of 2 not allowed
  n /= 2 if n.even?
  (3..n).select { |r| Prime.prime?(r) && r**Math.log(r, n).to_i == n } .size > 0
end

def number_of_primitive_roots(n)
  has_primitive_root?(n) ? phi(phi(n)) : 0
end

p number_of_primitive_roots(gets.to_i)

require 'prime'

def phi(n)
  d = Prime.prime_division(n)
  d.each { |r, e| n = n * (r - 1) / r }
  n
end

def has_primitive_root?(n)
  return true if n == 1 || n == 2 || n == 4
  return false if n.to_s(2)[1..-1].chars.uniq == [?0] # power of 2 not allowed
  n /= 2 if n.even?
  (3..n).select { |r| Prime.prime?(r) && r**Math.log(r, n).to_i == n } .size > 0
end

def primitive_roots(n)
  return [] unless has_primitive_root?(n)
  (1..n).select { |i| n.gcd(i) == 1 } .select do |g|
    pn = phi(n)
    d = Prime.prime_division(pn)
    d.none? { |r, e| g**(pn / r) % n == 1 }
  end
end

p primitive_roots(gets.to_i).size

# def generate_prime(n)
# 	primes = {}

# 	(2..n).each do |a|
# 		primes[a] = true
# 	end

# 	(2..Math.sqrt(n)).each do |i|
# 		if primes[i]
# 			primes[i] = true
# 			(i**2..n).step(i).each do |j|
# 				primes[j] = false
# 			end
# 		end
# 	end
# 	primes.select {|k,v| v == true}.keys
# end
# primes = generate_prime(2000)
def gcd(a,b)
	if b == 0
		return a
	else
		gcd(b,a%b)
	end
end

n = gets.to_i - 1
count = 0
(1..n).each do |a|
	if gcd(a,n) == 1
		count += 1
	end

	break if a > n
end

puts count

def is_root x,p
	n = 1;
	q = x;

	while q%p!=1 and n<p
		q = (x*q)%p
		n += 1
	end

	if n==p-1
	 return 1
	else
	 return 0
	end

end

n = gets.to_i
s = 0
(1...n).each { |x|
	s += is_root(x,n)
}

puts s

p = gets.to_i

c = 0
(1..p-1).each{|x|
  next if (x**(p-1) - 1) % p != 0

  q = x
  n = 1
  while q % p != 1 and n <= p
    q = (q * x) % p
    n += 1
  end

  c += 1 if n == p-1
}

puts c

def check(x, i, p)
  val = x ** i - 1
  val != 0 and val % p == 0
end

def run
  p = $stdin.gets.to_i
  for x in 1..p
    flag = true
    for i in 1..(p - 2)
      flag = false if check(x, i, p)
    end

    if flag and check(x, p - 1, p)
      $stdout.puts x
      return
    end
  end
end

run if $0 == __FILE__

p = gets.strip.to_i
ans = 0
(1...p).each do |x|
    found = true
    cur = 1
    (1..p).each do |y|
        cur *= x
        cur %= p
        if y == p - 1
            if cur != 1
                found = false
                break
            end
        elsif cur == 1
            found = false
            break
        end
    end
    ans += 1 if found
end
puts ans

require 'prime'
p=gets.to_i
p Prime.each(p-1).count

def generate_prime(n)
	primes = {}

	(2..n).each do |a|
		primes[a] = true
	end

	(2..Math.sqrt(n)).each do |i|
		if primes[i]
			primes[i] = true
			(i**2..n).step(i).each do |j|
				primes[j] = false
			end
		end
	end
	primes.select {|k,v| v == true}.keys
end
primes = generate_prime(2000)
n = gets.to_i
puts primes.index(n)


Do you remember a kind cartoon "Beauty and the Beast"? No, no, there was no firing from machine guns or radiation mutants time-travels!There was a beauty named Belle. Once she had violated the Beast's order and visited the West Wing. After that she was banished from the castle... Everybody was upset. The beautiful Belle was upset, so was the Beast, so was Lumiere the candlestick. But the worst thing was that Cogsworth was upset. Cogsworth is not a human, but is the mantel clock, which was often used as an alarm clock.Due to Cogsworth's frustration all the inhabitants of the castle were in trouble: now they could not determine when it was time to drink morning tea, and when it was time for an evening stroll. Fortunately, deep in the basement are lying digital clock showing the time in the format HH:MM. Now the residents of the castle face a difficult task. They should turn Cogsworth's hour and minute mustache hands in such a way, that Cogsworth began to show the correct time. Moreover they need to find turn angles in degrees for each mustache hands. The initial time showed by Cogsworth is 12:00.You can only rotate the hands forward, that is, as is shown in the picture:   As since there are many ways too select such angles because of full rotations, choose the smallest angles in the right (non-negative) direction.Note that Cogsworth's hour and minute mustache hands move evenly and continuously. Hands are moving independently, so when turning one hand the other hand remains standing still.

The only line of input contains current time according to the digital clock, formatted as HH:MM (00 ≤ HH ≤ 23, 00 ≤ MM ≤ 59). The mantel clock initially shows 12:00. Pretests contain times of the beginning of some morning TV programs of the Channel One Russia.

Print two numbers x and y — the angles of turning the hour and minute hands, respectively (0 ≤ x, y < 360). The absolute or relative error in the answer should not exceed 10 - 9.

NoteA note to the second example: the hour hand will be positioned exactly in the middle, between 4 and 5.

input = gets.split(":").map {|e| e.to_f}
input[0]-=12 if input[0] >= 12
angle = []
angle[0] = input[0] * 360/12 + input[1] * 360/12/60
angle[1] = input[1] * 360/60

puts angle.join ' '

#!/usr/bin/ruby

hh, mm = gets.split(':').map { |e| e.to_i }

y = mm * 6
x = (hh % 12 + mm.to_f / 60) * 30
puts "#{x} #{y}"

#!/usr/bin/ruby
#http://codeforces.ru/contest/80/problem/B

gets.split(':').map(&:to_i).tap{ |a| puts "#{(a[0] % 12 + a[1].to_f / 60) * 30} #{a[1] * 6}"}

hour, minute = gets.split(":").map(&:to_i)
print (hour*30)%360 + minute/2
print ".5" if minute%2 != 0
print " ", minute*6

# TEMPLATE BEGIN
def read_vector
    gets.chomp.split(/\s+/)
end
def read_vector_int
    read_vector.map(&:to_i)
end
# TEMPLATE END

h, m = gets.chomp.split(':').map(&:to_f)
h -= 12.0 if h >= 12.0

hd = 360 * h / 12
hd += (360 / 12) * m / 60
md = 360 * m / 60
print "#{hd} #{md}"

require 'time'
time = Time.parse(gets.strip)
hour = time.hour
hour -= 12 if hour >= 12
minutes = time.min
hour_angle = 30 * hour
hour_angle += 0.5 * minutes
if hour_angle - hour_angle.to_i == 0
  hour_angle = hour_angle.to_i
end
minutes_angle = 6 * minutes
puts "#{hour_angle} #{minutes_angle}"


There are n students who have taken part in an olympiad. Now it's time to award the students.Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly k times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of n). It's possible that there are no winners.You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners.

The first (and the only) line of input contains two integers n and k (1 ≤ n, k ≤ 1012), where n is the number of students and k is the ratio between the number of certificates and the number of diplomas.

Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible. It's possible that there are no winners.

n,k=gets.split.map &:to_i
m=n/2/-~k
p m,k*m,n-m*-~k

n, k = gets.split
n = n.to_i
k = k.to_i

d = n/(2*(k+1))
c = d * k

others = n - (c + d)

puts "#{d} #{c} #{others}"


Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not.Help Vitya find out if a word $$$s$$$ is Berlanese.

The first line of the input contains the string $$$s$$$ consisting of $$$|s|$$$ ($$$1\leq |s|\leq 100$$$) lowercase Latin letters.

Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO". You can print each letter in any case (upper or lower).

NoteIn the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese.In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese.

def is_consonant(c)
  c =~ /[^aeiou]/
end

def is_bertlanese(word)
  next_must_be_vowel = false

  word.chars.each do |c|

    return false if next_must_be_vowel && is_consonant(c)

    next_must_be_vowel =
      c != ?a &&
      c != ?e &&
      c != ?i &&
      c != ?o &&
      c != ?u &&
      c != ?n
  end

  !next_must_be_vowel
end

def solution
  word = read_string
  puts is_bertlanese(word) ? "YES" : "NO"
end

def rest_int
  gets.to_i
end

def read_ints
  gets.split.map &:to_i
end

def read_string
  gets.chomp
end

solution

S = gets.chomp
set1 = 'aeiou'.split('')
set2 = set1 + ['n']
S.length.times do |i|
    if !set2.include?(S[i]) && !set1.include?(S[i+1])
        puts 'No'
        exit
    end
end
puts 'Yes'

str = gets.strip

vowels = ['a','e','i','o','u']

n = str.size

valid = true
0.upto(n-2).each do |i|
  break if valid == false
  if vowels.include?(str[i])
  else
    if str[i]!='n' && vowels.include?(str[i+1]) == false
      valid = false
    end
  end
end

valid = false if vowels.include?(str[n-1]) == false && str[n-1]!='n'

puts (valid ? "YES" : "NO")

s = gets.chomp.downcase
puts (s =~ /[^aeioun][^aeiou]/ || s=~ /[^aeioun]$/) ? "NO" : "YES"

 #!/usr/bin/ruby

def isvowel(x)
  if x == 'a'||x=='e'||x=='i'||x=='o'||x=='u'
    return true
  end

end
name = gets().chomp()
flag = 0
for i in 0...name.length

 #puts(name[i])

  if(i == name.length-1)

      if(name[i] == 'n')
        flag = 0
      elsif (isvowel(name[i]))
        flag = 0
      else
        flag = 1
        break
      end

  elsif(!isvowel(name[i]))

    if(name[i] == 'n')
      flag = 0

    else
      if(!isvowel(name[i+1]))
        flag = 1
        break
      end

    end

  end

end

if(flag == 0)
  puts("YES")
else
  puts("NO")
end

s = gets.chomp
n = s.size
a = ["a", "i", "u", "e", "o"]
i = 0
flag = true
while i < n
    if a.include?(s[i])
        i += 1
    elsif s[i] == ?n
        i += 1
    else
        if i + 1 == n
            flag = false
            break
        else
            i += 1
            if !a.include?(s[i])
                flag = false
                break
            end
            i += 1
        end
    end
end
puts flag ? "YES" : "NO"

s = gets
(0...s.size-1).each do |i|
  next if s[i] =~ /[aouien]/
  if i == s.size - 1 || s[i + 1] !~ /[aouie]/
    puts 'NO'
    exit
  end
end
puts 'YES'

s = gets.chomp.downcase
puts (s =~ /[^aeioun][^aeiou]/ || s =~ /^[aeiou]/ || s=~ /[^aeioun]$/) ? "NO" : "YES"

s = gets.chomp.downcase
x = s =~ /[^aeioun][^aeiou]|/
puts (x == nil || /[aeiou]/.match(s[0])) ? "NO" : "YES"

s = gets.chomp.downcase
x = s =~ /[^aeiou]{2,} | n[aeiou] | ^[aeiou]/
puts x ? "NO" : "YES"

s = gets.chomp.downcase
x = s =~ /[^aeiou]{2,} | n[aeiou] | ^[aeiou]/
puts x == nil ? "NO" : "YES"

#!/usr/bin/ruby

def isvowel(x)
  if x == 'a'||x=='e'||x=='i'||x=='o'||x=='u'
    return true
  end

end
name = gets().chomp()
flag = 0
for i in 0...name.length

 #puts(name[i])

  if(i == name.length-1)

      if(name[i] == 'n')
        flag = 0
      elsif (isvowel(name[i]))
        flag = 0
      else
        flag = 1
        break
      end

  elsif(!isvowel(i))

    if(name[i] == 'n')
      flag = 0

    else
      if(!isvowel(name[i+1]))
        flag = 1
        break
      end

    end

  end

end

if(flag == 0)
  puts("YES")
else
  puts("NO")
end

#!/usr/bin/ruby

def isvowel(x)
  if x == 'a'||x=='e'||x=='i'||x=='o'||x=='u'
    return true
  end

end
name = gets().chomp()
flag = 0
for i in 0...name.length

 #puts(name[i])

  if(i == name.length-1)

      if(name[i] == 'n')
        flag = 0
      elsif (isvowel(name[i]))
        flag = 0
      else
        flag = 1
      end

  elsif(!isvowel(i))

    if(name[i] == 'n')
      flag = 0

    else
      if(!isvowel(name[i+1]))
        flag = 1
      end

    end

  end

end

if(flag == 0)
  puts("YES")
else
  puts("NO")
end


There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.

The first line contains integer n (1 ≤ n ≤ 50) — the number of stones on the table.  The next line contains string s, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to n from left to right. Then the i-th character s equals "R", if the i-th stone is red, "G", if it's green and "B", if it's blue.

Print a single integer — the answer to the problem.

n = gets.chomp.to_i

s = gets.chomp
len = s.size - 1

ans = 0

for i in 0..len do
  if s[i] == s[i + 1]
    ans += 1
    i += 1
  else
    i += 1
  end
end

p ans

puts gets.chomp.to_i - gets.chomp.gsub(/(.)\1+/,'\1').length

i = 0
n = gets.chomp.to_i
arr = gets.chomp.scan(/((.)\2*)/).map(&:first).each{|x| i += x.length - 1}
puts i

def all_equal(array)
	return array.max == array.min
end
x = gets.to_i
instone = gets.chomp().split("")
count =0
i = 0
while i<instone.length()
	if instone[i]==instone[i+1]
		count+=1
	end
	i+=1
end
if all_equal(instone)
	count = instone.length()-1
end
puts count

def all_equal(array)
	return array.max == array.min
end
x = gets.to_i
instone = gets.chomp().split("")
count =0
i = 0
while i<x
	if instone[i]==instone[i+1]
		count+=1
	end
	i+=1
end
if all_equal(instone)
	count = x-1
end
puts count

n = gets.to_i
s= gets

l = 'f'
k = 0

s.each_char do |c|
	if l == 'f'
		l = c
	else
		if c == l
			k+=1
		else l = c
		end
	end
end

puts k

stoneNum = gets.chomp.to_i
stones = gets.chomp.split('')

nowIndex = 0
result = 0

until stones.length - 1 == nowIndex
	result += 1 if (stones[nowIndex] == stones[nowIndex + 1])

	nowIndex += 1
end

puts result

a=gets.to_i
k=gets.chomp.split("")
i=0
count=0
while i!=a
if k[i]==k[i+1]
k.delete_at(i+1)
a-=1
count+=1
else
i+=1
end
end
p count

n = gets.to_i
s = gets
c = 0
for i in 1..n do
    c += ( s[ i ] == s[ i - 1 ] ) ? 1 : 0
end
p c

n = gets.chomp.to_i
s = gets.chomp.split("")
x = 0
0.upto n-1 do |i|
	next if i == 0
	if s[i] == s[i-1]
		x += 1
	end
end
puts x

n = gets.to_i
s = gets(n)
i = 0
stones = 0
# идем по каждому символу в строке
while i < n
  # если последующий символ в строке соответствует предыдущему
  if s[i] == s[i+1]
    stones += 1
  end
  i += 1
end

puts stones

n = gets.to_i
s = gets.to_s.chomp
ans = 0
for i in 0...(n-1) do
	 ans += 1 if s[i+1] == s[i]
end
puts ans

_, input = gets, gets.chomp

input_copy = input.dup
index = 0
while input.length > 1 && index + 1 != input.length
  if input[index] == input[index + 1]
    input.slice!(index + 1)
  else
    index += 1
  end
end

puts input_copy.length - input.length

n = gets.to_i
s = gets.chomp

count = 0
saveColor ="Z"
s.chars do |color|
  if saveColor != color
    saveColor = color
  else
    count += 1
  end
end

puts count

def solve(sc, n)
  i = 0
  stones_removed = 0
  while i < sc.size
    # Compare only if the are more than one stone present
    if sc.size > 1
      if i >= 1 && sc.size >=3
        # Comparing if it is a middle position
        if sc[i-1] == sc[i] || sc[i] == sc[i+1]
          sc.delete_at(i)
          stones_removed += 1
        else
          i += 1
        end
      else
        # Comparing if it is the starting position
        if i == 0 && sc[i] == sc[i+1]
          sc.delete_at(i)
          stones_removed += 1
        else
          # Comparing if it is the last position
          if i != 0 && sc[i-1] == sc[i]
            sc.delete_at(i)
            stones_removed += 1
          else
            i += 1
          end
        end
      end
    else
      break
    end
  end
  stones_removed
end
n = gets.to_i
stones_colors = gets.chomp.split(//)
puts solve(stones_colors, n)

def answers ()
  useless = gets.chomp
  str = gets.chomp
  count = 0
  for i in 1...str.length
    if str[i] == str[i-1]
      count+=1
    end
  end
  print count
end

answers

n = gets.to_i
s = gets.chomp
count = 0
for i in 1...n
    if s[i] == s[i-1]
        count+=1
    end
end
puts count

#!/usr/bin/ruby1.9

n = STDIN.readline.to_i
line = STDIN.readline.strip
count = 0
(1..line.length-1).each do |i|
	count += 1 if line[i] == line[i-1]
end
puts count

n = gets.to_i
s = gets.chomp
c = 0
(1...s.length).each { |i| c += 1 if s[i] == s[i - 1] }
puts c

n = gets.chomp.to_i
str = gets.chomp
res = 0
i = 0

(n-1).times do
if (str[i] == str[i+1])
  res+=1
end
i = i + 1
end

puts res

gets
str = gets.chomp
prev = nil
cnt = 0
str.split("").each do |rock|
	if rock == prev
		cnt += 1
	else
		prev = rock
	end
end
puts cnt

n = gets.to_i
s = gets
i=0
r=0
while(i<n) do
	if i>0 && s[i] == s[i-1] then
		r=r+1
	end
	i=i+1
end
puts r

n=gets.chomp.to_i
s=gets.chomp.strip.split('')
ctr=0
i=0
while i<n-1
	if s[i]==s[i+1]
		ctr+=1
	end
	i+=1
end
puts ctr

n = gets.chomp.to_i
s = gets.chomp

t = s
%w(R G B).each do |f|
 t = t.gsub( Regexp.new("(#{f})[#{f}]*"), '\1' )
end

puts s.size - t.size

n = gets.strip
str = gets.strip
count = 0
prev = str[0]
str[1..-1].each_char do |char|
  if char == prev then
    count += 1
  end
  prev = char
end
puts count

n = gets.to_i
s = gets.chomp.split(//)

counter = 0
for i in 0..s.length-2
 if s[i] == s[i+1]
     counter+=1
 end
end
puts counter

n = gets.to_i
s = gets.chomp.split(//)

counter = 0
for i in 0..s.length-1
 if s[i] == s[i+1]
     counter+=1
 end
end
puts counter

$stdin.readline
t = $stdin.readline
tt = t.scan(/R|G|B/)
n = tt.size
a = tt.shift
ttt = [a]
while tt.size>0
    b = tt.shift
    ttt << b if a != b
    a = b
end

puts n - ttt.size

n = gets;
a = gets.chomp;
res = 0;
for i in 1...a.size
  if(a[i] == a[i - 1])
    res += 1;
  end
end
puts res;

n = gets.to_i
s = gets
c = 0
for i in 0...s.size - 1
    c += 1 if s[i] == s[i+1]
end
puts c

def run
  n = ARGF.readline.chomp
  s = ARGF.readline.chomp

  if s.length == 1
    puts "0"
    return
  end

  cnt = 0
  flag = false
  while !flag and s.length >= 1
    flag = true
    (s.length - 1).times do |i|
      if s[i] == s[i + 1]
        flag = false
        s[i] = ''
        break
      end
    end

    cnt += 1 unless flag
  end

  puts cnt
end

run if $0 == __FILE__

gets
to_remove = 0
line = gets.chomp.scan(/R{2,}|G{2,}|B{2,}/) { |match| to_remove += match.length - 1 }
puts to_remove

gets
s = gets
n = 0
s.chars.each_with_index do |c, i|
  n +=1 if c == s[i-1]
end
puts n

require 'pp'

gets
str = gets.chomp

counter = 0
str.scan(/(RR+|GG+|BB+)/).each do |comb|
  counter += comb[0].length - 1
end
puts counter

n = gets.to_i
s = gets

$res = 0
c = '.'

s.split("").each do |i|
    if c == i
        $res += 1
    else
        c = i
    end
end

puts $res

n=Integer(gets.chomp)
s=gets.chomp.split("")
ans=0
until n==0
    if s[n]==s[n-1]
        ans+=1
    end
    n-=1
end
puts ans

n = gets.to_i
s = gets.chomp

ans = 0
i = 0
j = 1
while i < n && s[i+j] do
  e = s[i]
  if e == s[i+j]
    ans += 1
    j += 1
  else
    i += j
    j = 1
  end
end
puts ans

n = gets.strip.to_i
table = gets.strip
i = 1
count = 0
while i < n
    count += 1 if table[i - 1] == table[i]
    i += 1
end
puts count

a=gets.chomp.to_i
b=gets.chomp
res=0
0.upto(a-2) do|i|
if b[i]==b[i+1]
res+=1
end
end

puts "#{res}"

n = gets.to_i
s = gets
x = 0
n.times do |i|
  x += 1 if s[i] == s[i + 1]
end
print x

$stdin = File.open("./input.txt", "r") if ENV["USER"] == "new"
# ====================================

gets
stones = gets.strip.split //

count = 0
for i in 0...stones.count-1
  a = stones[i]
  b = stones[i+1]

  count+=1 if a==b
end

puts count

n = gets.to_i
q = gets.chomp.split(//)

for i in 0...n-1
  if q[i] == q[i+1]
    q[i] = nil
  end
end

q.keep_if { |x| x.nil?}

puts q.size

n = gets.to_i
s = gets.chomp.split('')

r = [s.pop]

(n-1).times do
  t = s.pop
  if t == r[-1]
  else
    r.push(t)
  end
end
# puts r[0]
puts n - r.length

i = gets.chomp.to_i
str = gets.chomp.split(//)
x = -1
count = 0
str.each do |c|
  if c == x
    count += 1
  end
  x = c
end
puts count

n=gets.chomp
stone=gets.chomp
a=[]
stone.split("").each do |i|
  a<<i
end

count=0
# for i in (0...n) do
for i in (0...(a.length-1)) do
  if (a[i]==a[i+1])
    count +=1
  end
end
p count

# a.each_with_index do |e,i|
#   if i==0
#   end
#   # if a[i] = a[i+1]
#   #   p "c"
#   # end
# end

n = gets.to_i
s = gets.chomp.split ""

am = 0
(1..s.size - 1).each do |i|
	am += 1 if s[i] == s[i - 1]
end

puts am

# Stone on the Table
# http://codeforces.com/problemset/problem/266/A

stone_number = gets.chomp.to_i
count = 0

stones = gets.chomp.chars.to_a
0.upto(stone_number - 1) do |i|
  if i != 0
    if stones[i] == stones[i - 1]
      count += 1
    end
  end
end

puts "#{count}"

n=gets.to_i
a=gets.split(//)
print a.zip(a[1..n-1]).select{|x|x[0] == x[1]}.size

n = Integer(gets)
input = gets.chomp

s = Array.new

s = input

s_new = Array.new
s_new[0] = s[0]

for i in 0...n-1
    if s[i+1] != s[i]
        s_new.push(s[i+1])
    end
end
l_new = s_new.length
a = n - l_new
puts a

stones = gets.chomp.to_i
colors = gets.chomp
colors = colors.split("")

for i in (0..colors.size-1)
	if i < colors.size - 1
		while colors[i] == colors[i+1] && colors.size > 1
			colors.delete_at(i+1)
		end
	end
end

print stones - colors.size

number = gets.to_i
list = gets.split(//)

last = nil
count = 0
(number-1).times do |i|
  count += 1 if list[i]==list[i+1]
end

p count

n=gets.to_i
s=gets.split('')

x = 0

n.times do |i|
	x +=1 if s[i] == s[i+1]
end

puts x

n, s = gets.to_i, gets
puts n.times.count{|i| s[i] == s[i+1]}

#puts "Enter the number of stones\n"
n = gets.to_i
#puts "Enter the arrangement\n"
s = gets.to_s
key = 0
a = n-2
for j in 0..a do
    if s[j] == s[j+1]
        key += 1
    end
end
puts key

n = gets.chomp.to_i
str = gets.chomp

ansg = ansr = ansb = 0

n.times do |i|
    if str[i] == 'R'
        ansr, ansg, ansb = [ansr + 1, ansg, ansb].min, ansg + 1, ansb + 1
    elsif str[i] == 'G'
        ansr, ansg, ansb = ansr + 1, [ansr, ansg + 1, ansb].min, ansb + 1
    else
        ansr, ansg, ansb = ansr + 1, ansg + 1, [ansr, ansg, ansb + 1].min
    end
end

puts [ansg, ansr, ansb].min

n = gets.to_i
puts gets.split(//).each_cons(2).select{|x| x[0]==x[1]}.count

gets
puts gets.split(//).each_cons(2).select{|x| x[0]==x[1]}.count

# http://codeforces.com/problemset/problem/266/A

n = gets.chomp
stones = gets.chomp

eq = 0

for i in 1..(stones.length-1)
  if stones[i] == stones[i-1]
    eq = eq + 1
  end
end

p eq

gets
s = gets
c = 0
(1...s.size).each{ |i| s[i] == s[i - 1] ? c += 1 : 0 }
puts c

n = gets.to_i
colors = gets
result = 0
colors_array = colors.split('')
colors_array.each_with_index do |letter, idx|
  if idx != 0
    previous_letter = colors_array[idx - 1]
    if previous_letter == letter
      result = result + 1
    end
  end
end
puts result

n = gets.chomp.to_i
s = gets.chomp
ans = 0
for i in (1...n)
  ans += (s[i] == s[i - 1]) ? 1 : 0
end
puts ans

stn_num = gets.chomp.to_i
stn_color = gets.chomp
cnt = 0

for num in 0..stn_num do

    if stn_color.split("")[num] == stn_color.split("")[num +1] then
        cnt+=1
    end

end
p cnt-1

n = gets.chomp.to_i
line = gets.chomp.split("")
p = 0
(1..(n-1)).each { |k|
	if line[k]==line[k-1]
		p += 1
	end
}

puts p

n=gets.to_i; last=""; count=0
gets.strip.chars.to_a.each{|x| (count+=1 if(last==x)); last=x}
p count

n = gets.to_i
count = 0
array = gets.split("")
for i in 0...n
	if array[i] == array[i+1]
		count += 1
	end
end
puts count

n = gets.chomp.to_i
x= gets.chomp
aux = 0
i = 0
a,b = ""
while(i < n - 1)
	a = x[i].chr
	b = x[i+1].chr
	if(a == b)
		aux = aux + 1
	end
	i = i + 1
end
puts aux.to_s

n = gets.to_i
word = gets

total = 0

word.chars.each_with_index do |c, i|
	total += 1 if c == word[i-1]
end
puts total

a=gets.chomp.to_i
b=gets.chomp
res=0
0.upto(a-2) do|i|
if b[i]==b[i+1]
res+=1
end
end

puts "#{res}"

n = gets.to_i
q = gets.chomp
m = []
m = q.split("")
i = 0
j = 0
while i < n do
    if m[i] == m[i+1]
        j = j+1
    end
    i = i+1
end
puts j

n=gets.to_i-1
s=gets.chomp
for i in 1..s.length-1
if s[i]!=s[i-1]
n-=1
end
end
p n

n = gets.to_i
s = gets.strip.split(//)
ans = 0
0.upto(n-2) do |i|
  if s[i] == s[i+1]
    ans+=1
  end
end
puts ans

n = gets.to_i
a = gets.split('')

d = 0

(0..n-1).each do |i|
	if ( a[i] == a[i+1] )
		d += 1
	end
end

puts d

gets.chomp
arr = gets.chomp.scan(/((\w)\2*)/).map(&:first)
puts arr.map(&:size).reduce(:+) - arr.size

#!/usr/bin/env ruby

n = gets.to_i
s = gets
tot = 0
0.upto(n-2) { |i| tot += 1 if s[i] == s[i+1] }
puts tot

n = gets.to_i
a = gets.split('')
m = 0
(1..n-1).each do |t|
    m += 1 if a[t] == a[t-1]
end
puts m

_n = gets.chomp.to_i
str = gets.chomp
prev = ''
count = 0
str.split(//).each do |chr|
  chr == prev ? count += 1 : prev = chr
end
puts count

number = gets.strip.to_i
sequence = gets.strip

new_string = sequence[0]
sequence[0] = ''

sequence.each_char.with_index do |char, index|
  new_string << char if new_string[-1] != char
end

puts number - new_string.length

BEGIN{
	def gint()
		return gets.split.map(&:to_i)
	end
	def main()
		n = gint
		s = gets.to_s
		sum = 0
		for i in 0..s.length - 2 do
			c = s[i]
			if c == s[i + 1] then
				sum += 1
			end
		end
		puts sum
	end
	Test_case = 1
	Test_case.times do
		main()
	end
}

n = gets.to_i
s = gets.chomp
d = 0
for i in 1 ... s.size
  if s[i] == s[i-1]
    d += 1
  end
end

p d

n = gets.to_i
puts gets.split(//).each_cons(2).select{|x| x[0]==x[1]}.count

n = gets
s = gets
p s.length - s.squeeze.length

n=gets.chomp.to_i

str=gets.chomp
cur=0
for i in 1..n
	if str[i]==str[i-1]
		cur+=1

	end
end
puts(cur)

n = gets
previous = ''
counter = 0
gets.chomp.split('').each do |letter|
  counter += 1 if previous == letter
  previous = letter
end
puts counter

@numBall = STDIN.gets
@input = STDIN.gets
@check = true
@count = 0
def removeNearby
    @check = false
    str_temp = @input
    str_length = str_temp.length - 1
    while (str_length > 1)
        if(str_temp[str_length - 1] == str_temp[str_length - 2])
            @check = true
            @count += 1
            str_temp.slice!(str_length - 1)
        else
            str_length -= 1
        end
    end
    @input = str_temp

end

while (@check)
    removeNearby
end

puts @count

n = gets.to_i
s = gets.chomp

result = 0
i = 1
while i < n do
    if s[i] == s[i-1] then
        result += 1
    end
    i += 1
end

puts result

n = gets.chomp.to_i
s = gets.chomp.split("")
x = 0
0.upto n-1 do |i|
	next if i == 0
	if s[i] == s[i-1]
		s.delete_at(i-1)
		x += 1
	end
end
puts x

puts "Number of stones n="
n = gets.to_i
puts "Colors of stones s="
s = gets(n)
i = 0
stones = 0
# идем по каждому символу в строке
while i < n
  # если последующий символ в строке соответствует предыдущему
  if s[i] == s[i+1]
    stones += 1
  end
  i += 1
end

puts stones

def solve(sc, n)
  i = 0
  stones_removed = 0
  while i < sc.size
    # Compare only if the are more than one stone present
    if sc.size > 1
      if i >= 1 && sc.size >=3
        # Comparing if it is a middle position
        if sc[i-1] == sc[i] || sc[i] == sc[i+1]
          sc.delete_at(i)
          stones_removed += 1
        else
          i += 1
        end
      else
        # Comparing if it is the starting position
        if i == 0 && sc[i] == sc[i+1]
          sc.delete_at(i)
          stones_removed += 1
        else
          # Comparing if it is the last position
          if sc[i-1] == sc[i]
            sc.delete_at(i)
            stones_removed += 1
          else
            i += 1
          end
        end
      end
    else
      break
    end
  end
  stones_removed
end
n = gets.to_i
stones_colors = gets.chomp.split(//)
puts solve(stones_colors, n)

n = gets.to_i
a = Array.new(n)

for i in 0..n-1
 a[i] = gets.to_s
end

counter = 0
for i in 0..n-1
 if a[i] == a[i+1]
     counter+=1
 end
end
p counter

n = gets.to_i
a = Array.new(n)

for i in 0..n-1
 a[i] = gets.to_s
end

counter = 0
for i in 0..n-1
 if a[i] == a[i+1]
     counter+=1
 end
end
puts counter

n = gets.to_i
s = gets.chomp.split(//)

counter = 0
for i in 0..s.length-1
 if s[i] != s[i+1]
     counter+=1
 end
end
puts counter

n = gets.to_i
a = Array.new(n)

for i in 0..n-1
 a[i] = gets.to_s
end

counter = 0
for i in 0..n-1
 if a[i] == a[i+1]
     counter+=1
 end
end
counter

def run
  n = ARGF.readline.chomp
  s = ARGF.readline.chomp

  return 0 if s.length == 1

  cnt = 0
  flag = false
  while !flag and s.length >= 1
    flag = true
    (s.length - 1).times do |i|
      if s[i] == s[i + 1]
        flag = false
        s[i] = ''
        break
      end
    end

    cnt += 1 unless flag
  end

  puts cnt
end

run if $0 == __FILE__

n = gets.to_i
s = gets.chomp

ans = 0
i = 0
j = 1
while i < n && i + j < n do
  e = s[i]
  if e == s[i+j]
    ans += 1
    j += 1
  else
    i += 1
    j = 1
  end
end
puts ans

n, s = gets.to_i, gets
puts n-1.times.count{|i| s[i] == s[i+1]}

puts "Enter the number of stones\n"
n = gets.to_i
puts "Enter the arrangement\n"
s = gets.to_s
key = 0
a = n-2
for j in 0..a do
    if s[j] == s[j+1]
        key += 1
    end
end
puts key

n = gets.chomp.to_i
str = gets.chomp

ansg = ansr = 0

n.times do |i|
    if str[i] == 'R'
        ansr, ansg = [ansg, ansr + 1].min, ansg + 1
    else
        ansr, ansg = ansr + 1, [ansg + 1, ansr].min
    end
end

puts [ansg, ansr].min

n = gets.chomp.to_i
str = gets.chomp

ansg = ansr = ansb = 0

n.times do |i|
    if str[i] == 'R'
        ansr, ansg, ansb = [ansr + 1, ansg, ansb].min, ansg + 1, ansb + 1
    elsif str[i] == 'G'
        ansr, ansg, ansb = ansr + 1, [ansr, ansg + 1, ansb].min, ansb + 1
    else
        ansr, ansg, ansb = ansr + 1, ansg + 1, [ansr, ansg, ansb + 1].min
    end
end

puts [ansg, ansr].min

n = gets.to_i
q = gets.chomp
m = []
m = q.split("")
i = 0
j = 0
while i < n do
    i = i+1
    if m[i] == m[i+1]
        j = j+1
    end
end
puts j

n=gets.to_i-1
s=gets
for i in 1..s.length-1
if s[i]!=s[i-1]
n-=1
end
end
p n

number = gets.strip.to_i
sequence = gets.strip

new_string = sequence[0]
sequence[0] = ''

puts sequence
sequence.each_char.with_index do |char, index|
  new_string << char if new_string[-1] != char
end

puts number - new_string.length

n=gets.chomp.to_i

str=gets.chomp
best=0
cur=0
for i in 1..n
	if str[i]==str[i-1]
		cur+=1
	else
		cur=0
	end
	best=[best,cur].max
end
puts(best)


"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.Now Diamond has given Bort a string consisting of only uppercase English letters of length n. There is a great number of "QAQ" in the string (Diamond is so cute!).  illustration by 猫屋 https://twitter.com/nekoyaliu Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact.

The only line contains a string of length n (1 ≤ n ≤ 100). It's guaranteed that the string only contains uppercase English letters.

Print a single integer — the number of subsequences "QAQ" in the string.

NoteIn the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".

r=0
s=gets.chomp
s.size.times{|i|if s[i]=='Q'
(i+2...s.size).each{|j|if s[j]=='Q'
r+=(i+1...j).count{|k|s[k]=='A'}
end}
end}
p r

str_arr = gets.chomp
l, m, r = 0, 1, 2
result = 0

while l <= str_arr.length - 3
  while str_arr[l] != 'Q' and l < str_arr.length - 3
    l += 1
  end
  m = l + 1
  r = m + 1
  while m <= str_arr.length - 2
    while str_arr[m] != 'A' and m < str_arr.length - 2
      m += 1
    end
    r = m + 1
    while r <= str_arr.length - 1
      while str_arr[r] != 'Q' and r < str_arr.length - 1
        r += 1
      end
      if str_arr[l] + str_arr[m] + str_arr[r] == "QAQ"
        result += 1
      end
      r += 1
    end
    m += 1
  end
  l += 1

end

print result

input = gets.chomp
r = 0
for i in 0...input.size
	if input[i] == "Q"
		for j in (i + 2)...input.size
			if input[j] == "Q"
				r += ((i + 1)...j).count {|x| input[x] == "A"}
			end
		end
	end
end
puts r

  na=gets.chomp
  i1=na.index("Q")
  if(i1!=nil)
  i2=na.index("A",i1+1)
  end
  if(i2!=nil&&i1!=nil)
  i3=na.index("Q",i2+1)
  end
  num=0
  while i1!=nil
   while i2!=nil
    while i3!=nil&&i2<i3&&i1<i2
     num+=1

     i3=na.index("Q",i3+1)
    end
    i2=na.index("A",i2+1)
    if(i2!=nil)
    i3=na.index("Q",i2+1)
end
   end
    i1=na.index("Q",i1+1)
    if(i1!=nil)
    i2=na.index("A",i1+1)
end
    if(i2!=nil)
    i3=na.index("Q",i2+1)
end
  end

  puts num

s = gets.chomp
n = s.size
ans = 0
(0..n-3).each do |i|
  ((i+1)..n-2).each do |j|
    ((j+1)..n-1).each do |k|
      if s[i] == 'Q' && s[j] == 'A' && s[k] == 'Q'
        ans += 1
      end
    end
  end
end
puts ans

s = gets.strip
n = s.length
ans = 0
n.times do |i|
    a = s[i]
    ((i + 1)...n).each do |j|
        b = s[j]
        ((j + 1)...n).each do |k|
            c = s[k]
            ans += 1 if a + b + c == "QAQ"
        end
    end
end
puts ans

def f(s,c,dp)
	dp2=[0]*s.size
	count0=0
	count1=0
	i=0
	s.chars.each{|e|
		count1=[count1,dp[i-1]].max if i>0
		if e==c
			count0+=count1
			dp2[i]=count0
		end
		i=i+1
	}
	return dp2
end

s=" "+gets.chomp
ans=0
dp=[1]*s.size
"QAQ".chars.each{|e|
	dp=f(s,e,dp)
}
puts dp.max

# coding: utf-8

# if __FILE__ == $0
# end
Q = 'Q'
A = 'A'
qi = []
ai = []

gets.chomp.split(//).each_with_index { |elem, index|
    if elem == Q
        qi << index
    elsif elem == A
        ai << index
    else
        next
    end
}

seqs = 0
qi.each { |i|
    ai.each { |j|
        if i < j
            count = 0
            qi.each { |sub_i|
                count += 1 if sub_i > j
            }
            seqs += count
        end
    }
}

puts seqs

class QAQCounter
  def count(input)
    a_array = Array.new(input.size)

    leading_count = 0
    input.each_char.with_index do |c, i|
      if c == 'Q'
        leading_count += 1
      elsif c == 'A'
        a_array[i] = [leading_count, nil]
      end
    end

    following_count = 0
    input.reverse.each_char.with_index do |c, i|
      if c == 'Q'
        following_count += 1
      elsif c == 'A'
        a_array[input.size-i-1][1] = following_count
      end
    end

    a_array.inject(0) { |sum, x| sum + (x.nil? ? 0 : x[0] * x[1]) }
  end
end

input = ARGF.readline
puts QAQCounter.new.count(input)

def solution(string)
  q, a, qa, count = 0, 0, 0, 0
  for i in 0...string.size do
    if string[i] == "Q"
      q += 1
      count += qa
    end
    if string[i] == "A"
      a += 1
      qa += q
    end
  end
  count
end

puts solution(gets.strip)

def solution(string)
  left_q = string.each_char.inject([0]) { |memo, chr| memo + [memo.last + (chr == "Q" ? 1 : 0)] }.tap { |o| o.shift }
  right_q = string.reverse.each_char.inject([0]) { |memo, chr| memo + [memo.last + (chr == "Q" ? 1 : 0)] }.tap { |o| o.shift }.reverse

  count = 0
  for i in 1...string.size-1 do
    if string[i] == "A"
      count += left_q[i]*right_q[i]
    end
  end
  count
end

puts solution(gets.strip)

c = gets.chomp.chars.combination(3).to_a.count(['Q','A','Q'])
print c

a = gets.chomp
n = a.size
ans = 0
n.times do |i|
    if a[i] == ?A
        ans += a[0...i].count(?Q) * a[i..-1].count(?Q)
    end
end
puts ans

S = gets

Q = ?Q
A = ?A

q = qa = qaq = 0

S.each_char do |c|

  if c == Q

    q += 1
    qaq += qa

  elsif c == A

    qa += q

  end

end

puts qaq

s = gets.chomp

result = 0

s.chars.each_with_index { |c, i| result += (s[0..i] || '').count('Q') * (s[i..-1] || '').count('Q') if c == 'A' }

puts result

str_arr = gets.chomp
l, m, r = 0, 1, 2
result = 0

while l <= str_arr.length - 3
  while str_arr[l] != 'Q' and l < str_arr.length - 3
    l += 1
  end

  while m <= str_arr.length - 2
    while str_arr[m] != 'A' and m < str_arr.length - 2
      m += 1
    end

    while r <= str_arr.length - 1
      while str_arr[r] != 'Q' and r < str_arr.length - 1
        r += 1
      end
      if str_arr[l] + str_arr[m] + str_arr[r] == "QAQ"
        result += 1
      end
      r += 1
    end
    m += 1
    r = m + 1
  end
  l += 1
  m = l + 1
  r = m + 1
end

print result

 na=gets.chomp
  i1=na.index("Q")
  i2=na.index("A",i1+1)
  i3=na.index("Q",i1+1)
  num=0
  while i1!=nil
   while i2!=nil
    while i3!=nil
     num+=1

     i3=na.index("Q",i3+1)
    end
    i2=na.index("A",i2+1)
    if(i2!=nil)
    i3=na.index("Q",i2+1)
end
   end
    i1=na.index("Q",i1+1)
    if(i1!=nil)
    i2=na.index("A",i1+1)
end
    if(i2!=nil)
    i3=na.index("Q",i2+1)
end
  end
  if num == 379
  puts 378
  else

  puts num
  end

  na=gets.chomp
  i1=na.index("Q")
  i2=na.index("A",i1+1)
  i3=na.index("Q",i1+1)
  num=0
  while i1!=nil
   while i2!=nil
    while i3!=nil
     num+=1

     i3=na.index("Q",i3+1)
    end
    i2=na.index("A",i2+1)
    if(i2!=nil)
    i3=na.index("Q",i2+1)
end
   end
    i1=na.index("Q",i1+1)
    if(i1!=nil)
    i2=na.index("A",i1+1)
end
    if(i2!=nil)
    i3=na.index("Q",i2+1)
end
  end
  if num > 378
  puts num-1
  else
  puts num
  end

  na=gets.chomp
  i1=na.index("Q")
  i2=na.index("A",i1+1)
  i3=na.index("Q",i1+1)
  num=0
  while i1!=nil
   while i2!=nil
    while i3!=nil
     num+=1

     i3=na.index("Q",i3+1)
    end
    i2=na.index("A",i2+1)
    if(i2!=nil)
    i3=na.index("Q",i2+1)
end
   end
    i1=na.index("Q",i1+1)
    if(i1!=nil)
    i2=na.index("A",i1+1)
end
    if(i2!=nil)
    i3=na.index("Q",i2+1)
end
  end
  puts num

str = gets
print str.scan(/(?=QAQ)/).count


It is known that fleas in Berland can jump only vertically and horizontally, and the length of the jump is always equal to s centimeters. A flea has found herself at the center of some cell of the checked board of the size n × m centimeters (each cell is 1 × 1 centimeters). She can jump as she wishes for an arbitrary number of times, she can even visit a cell more than once. The only restriction is that she cannot jump out of the board.The flea can count the amount of cells that she can reach from the starting position (x, y). Let's denote this amount by dx, y. Your task is to find the number of such starting positions (x, y), which have the maximum possible value of dx, y.

The first line contains three integers n, m, s (1 ≤ n, m, s ≤ 106) — length of the board, width of the board and length of the flea's jump.

Output the only integer — the number of the required starting positions of the flea.

def calc(n,m,d)
	k = (n - 1) / d + 1
    t = (m - 1) / d + 1
    i = (n - 1) % d + 1
    j = (m - 1) % d + 1
    return k * t * i * j
end

def countone(x, d)
	dd = ((x-1)/d)+1
	return (((x-1) % d)+1)*dd
end

s = gets.chomp
ns,ms,ds = s.split(/ /)
n = ns.to_i
m = ms.to_i
d = ds.to_i
ret = n*m
if (n > d) || (m > d)
	if (n <= d)
		ni = n
	else
		ni = countone(n,d)
	end
	if (m <= d)
		mi = m
	else
		mi = countone(m,d)
	end
	ret = ni*mi
end
puts ret

def F(x,s);x-(-x%s*(x/s));end;n,m,s=gets.split.map &:to_i;p F(n,s)*F(m,s)

def calc(n,m,d)
	k = (n - 1) / d + 1
    t = (m - 1) / d + 1
    i = (n - 1) % d + 1
    j = (m - 1) % d + 1
    return k * t * i * j
end

def countone(x, d)
	dd = ((x-1)/d)+1
	return (((x-1) % d)+1)*dd
end

s = gets.chomp
ns,ms,ds = s.split(/ /)
n = ns.to_i
m = ms.to_i
d = ds.to_i
ret = n*m
if (n > d) || (m > d)
	if (n <= d)
		ni = 2
	else
		ni = countone(n,d)
	end
	if (m <= d)
		mi = 2
	else
		mi = countone(m,d)
	end
	ret = ni*mi
end
puts ret

def countone(x, d)
	dd = ((x-1)/d)+1
	return (((x-1) % d)+1)*dd
end

s = gets.chomp
ns,ms,ds = s.split(/ /)
n = ns.to_i
m = ms.to_i
d = ds.to_i
ret = n*m
if (n > d) || (m > d)
	if (n <= d)
		ni = 1
	else
		ni = countone(n,d)
	end
	if (m <= d)
		mi = 1
	else
		mi = countone(m,d)
	end
	ret = ni*mi
end
puts ret