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

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
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

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.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)


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

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

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)

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

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

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

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

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

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


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


require 'prime'

l, r, x, y = gets.strip.split.map(&:to_i)

x_factors = Prime.prime_division(x)
y_factors = Prime.prime_division(y)
all_factors = {}
x_factors.each do |fp|
  all_factors[fp[0]] = [fp[1]]
end
y_factors.each do |fp|
  if all_factors[fp[0]]
    all_factors[fp[0]] << fp[1]
  else
    all_factors[fp[0]] = [0, fp[1]]
  end
end

if all_factors.values.map(&:size).uniq != [2]
  puts 0
  exit
end

all_factors_ary = all_factors.keys.sort
bl = all_factors_ary.size
n = 1<<bl
# puts all_factors_ary.inspect
# puts all_factors.inspect

pairs = []
0.upto(n).each do |bm|
  a = 1
  b = 1
  0.upto(bl-1).each do |s|
    f = all_factors_ary[s]
    # puts f
    if (bm & (1<<s)) > 0
      b *= (f ** all_factors[f][1])
      a *= (f ** all_factors[f][0])
    else
      a *= (f ** all_factors[f][1])
      b *= (f ** all_factors[f][0])
    end
  end
  # puts "(#{a},#{b})"
  if l<=a && a<=r && l<=b && b<=r
    pairs << [a,b]
  end
end
puts pairs.uniq.size

L, R, X, Y = gets.split.map(&:to_i)
if Y % X != 0
    puts 0
    exit
end

div = Y/X
sq = Math.sqrt(div).ceil
ans = 0
(1..sq).each do |i|
    next if div%i != 0
    j = div/i
    next if i > j
    next if i.gcd(j) != 1
    if (i*X).between?(L, R) && (j*X).between?(L, R)
        ans += i==j ? 1 : 2
    end
end
puts ans


hint = gets
temp = hint
arr = Array.new()
num = 10
res = 1
if hint[0] == '?'
  res *= 9
elsif hint[0] > '9'
  res *= 9
  hint = hint[0] + temp.gsub(hint[0],'')
  num = num - 1
end
hint[0] = ''
hint.each_char {|c|
  if c == '?'
    res *= 10
  elsif c > '9' && !(arr.include?(c))
    res *= num
    arr << c
    num = num - 1
  end
}

puts res

#!/usr/bin/ruby
h={}
f=10
x=1
gets.chomp.each_char.with_index{|c,i|
	if i==0&&!('0'..'9').include?(c)
		f=9
	end
	if c=='?'
		x*=10
	elsif ('A'..'J').include?(c)
		h[c]=1
	end
}
p x*(11-h.size..10).reduce(1,:*)*f/10

s = gets
ret = 1
hash = {}
for i in 0...s.size
  adjust = i == 0 ? 1 : 0
  ret *= 10 - adjust if s[i] == '?'
  if s[i] >= 'A' && s[i] <= 'J'
    ret *= 10 - hash.size - adjust unless hash[s[i]]
    hash[s[i]] = true
  end
end
puts ret

t = STDIN.gets
def ppp(start,lcounter)
  return start if lcounter == 1
  return 1 if lcounter < 1
  start*ppp(start-1, lcounter -1)
end
h = []
k = []
qcounter = 0

t.size.times do |i|
  if t[i] =~ /[A-J]/
    h << t[i] if not h.include? t[i]
  end
  if '0123456789'.include? t[i]
    k << t[i] if not k.include? t[i]
  end
  qcounter = qcounter + 1 if t[i] == '?'
end

p = h.count
p = 0 if p < 0
pp = 10

res = ((t[0] =~ /[A-J]/) ? ppp(pp-1, p-1)*(pp-1) : ppp(pp, p))* ((t[0] == '?') ? (10)**(qcounter - 1)*9 : (10)**qcounter)
puts res

#!/usr/bin/ruby
h={}
f=10
x=0
gets.chomp.each_char.with_index{|c,i|
	if i==0&&!('0'..'9').include?(c)
		f=9
	end
	if c=='?'
		x+=1
	elsif ('A'..'J').include?(c)
		h[c]=1
	end
}
r=(11-h.size..10).reduce(1,:*)
if x>0
	r*=10
	x-=1
end
r=r*f/10
puts r.to_s+'0'*x

def f(n)
  return 1 if n == 1
  return n * f(n-1)
end
s = gets
ret = 1
q = s.count('?')
c = 10
for i in 'A'..'J'
  if s.index(i)
    ret *= c
    c -= 1
  end
end
ret *= (10 ** q)
if s[0] == '?' || (s[0] >= 'A' && s[0] <= 'J')
  ret = ret / 10 * 9
end
puts ret

#!/usr/bin/ruby
h={}
f=10
x=1
gets.chomp.each_char.with_index{|c,i|
	if i==0&&!('0'..'9').include?(c)
		f=9
	end
	if c=='?'
		x*=10
	elsif ('A'..'J').include?(c)
		h[c]=1
	end
}
p x*(11-h.size..10).reduce(1,:*)/10*f


n=gets.to_i
x=Math.sqrt(n).round-200
for y in 1..400 do
	sum=0
	str=x.to_s
	for i in 0..str.size do
		sum+=str[i].to_i end;
	if x*(x+sum)==n and x>0
		puts x
		break
	end
	x+=1
	print -1 if y==400
	end

EPS=1e-9
def s(x)
	ret=0
	while x>0
		ret+=x%10
		x/=10
	end
	ret
end

def is_int?(_x)
	x=_x.round
	(x-EPS<=_x)&&(_x<=x+EPS)
end

n=gets.to_i
ans=100.times.map{|s|
	_x=(-s+(s*s+4*n)**0.5)/2.0
	if is_int?(_x)
		x=_x.round
		if x*x+s(x)*x-n==0
			x
		else
			nil
		end
	else
		nil
	end
}

p ans.any? ? ans.compact.min : -1

def s(x)
  res = 0
  until x == 0
    res += x%10
    x /= 10
  end
  return res
end

n = gets.to_i
x = Math.sqrt(n).floor
notfound = true
for i in [x-100000, 1].max..x
  if i**2 + s(i)*i - n == 0
    print i
    notfound = false
    break
  end
end

print -1 if notfound

#!/usr/bin/ruby2.0

n = STDIN.readline.to_i

candidates = []

(1..162).each do |b|
	x = (-b + (b*b + 4*n)**0.5) / 2
	x = x.round
	next if x*x + b*x != n
	t, sum = x, 0
	while t != 0
		sum += t%10
		t /= 10
	end
	next if sum != b
	candidates.push(x)
end

if candidates.length == 0
	puts -1
else
	puts candidates.sort[0]
end

#!/usr/bin/ruby2.0

n = STDIN.readline.to_i

candidates = []

(1..162).each do |c|
	low, high = 1, n
	while high-low > 1e-6
		mid = (low+high)/2.0
		if n/mid - mid > c
			low = mid
		else
			high = mid
		end
	end
	x = mid.round
	next if n != c*x + x*x
	t = x
	total = 0
	while t != 0
		total += t%10
		t /= 10
	end
	if total == c
		candidates.push(x)
	end
end

if candidates.length == 0
	puts -1
else
	puts candidates.sort[0]
end

n=gets.chomp.to_i
x=Math.sqrt(n).round
x-=200
for y in 1..400 do
	sum=0
	str=x.to_s
	for i in 0..str.size do
		sum+=str[i].to_i end;
	if x>0 and x*(x+sum)==n
		puts x
		break
	end
	x+=1
	print -1 if y==400
end

n = gets.to_i
x = Math.sqrt(n).round - 200
0.upto(400) do
  sum = 0
  str = x.to_s
  0.upto(str.size) do |i|
    sum += str[i].to_i
  end
  if x * (x + sum) == n and x > 0
    puts str
    exit
  end
  x += 1
end
puts -1

n = gets.to_i

def s(x)
  sum = 0
  x.to_s.each_byte { |c| sum += c - 48 }
  sum
end

def sqrt(y)
  lo, hi = 1, y
  while lo <= hi do
    mid = (lo + hi) / 2
    return mid if mid * mid == y
    lo = mid + 1 if mid * mid < y
    hi = mid - 1 if mid * mid > y
  end
  return -1
end

ans = []

for i in 1..81 do
  t = sqrt(i * i + 4 * n)
  if t != -1 then
    if t - i > 0 && (t - i) % 2 == 0 then
      ans << (t - i) / 2 if s((t - i) / 2) == i
    end
  end
end

if ans.size == 0 then
  puts "-1"
else
  puts ans.min
end

n = gets.to_i

# while l <= r
# 	x  = l + (r-l)/2
# 	s = x.to_s.split("").map(&:to_i).inject(0,:+)
# 	puts x
# 	if ((x * x) + (s * x) - n) == 0
# 		ans = x
# 		break
# 	else
# 		r = x - 1
# 	end
# end

# puts x
ans = false
min = n
(1..90).each do |s|
	a = 1
	b = s
	c = -n
	d = (b ** 2) - (4 * a * c)
	if d >=0
		r1 = (-b + Math.sqrt(d))/(2 * a)
		r2 = (-b - Math.sqrt(d))/(2 * a)
	elsif d == 0
		r1 = r2 = (-b)/(2 * a)
	end
	# puts "sum #{s} roots  #{r1} #{r2}"
	if r1 && r2
		arr = []
		sum = r1.to_i.to_s.split("").map(&:to_i).inject(0,:+)
		arr << r1 if r1 % 1 == 0 && r1 > 0 && s == sum
		sum = r2.to_i.to_s.split("").map(&:to_i).inject(0,:+)
		arr << r2 if  r2 % 1 == 0 && r2 > 0 && s == sum
		unless arr.empty?
		# puts "s #{s} ar #{r1} #{r2}"
			val = arr.min
			min = val if val && val < min
			# puts "#{val}"
			ans = true
		end
	end
end
if ans
	if min == 999959999
		puts -1
	else
	puts min.to_i
	end
else
	puts "-1"
end

def s(x)
  sum = 0
  while x>0
    sum+= x%10
    x /= 10
  end
  sum
end

n = gets.to_i
x = Math.sqrt(n).round - 160;

321.times do |i|
  if x*(x+s(x))==n && x > 0
    puts x
    exit
  end
  x+=1
end
puts -1

n=gets.to_i
x=n**0.5.round-200
for y in 1..400 do
	sum=0
	str=x.to_s
	for i in 0..str.size do
		sum+=str[i].to_i end;
	if x*(x+sum)==n
		puts x
		break
	end
	x+=1
	print -1 if y==400
	end

#!/usr/bin/ruby2.0

n = STDIN.readline.to_i

candidates = []

(1..162).each do |c|
	low, high = 1, n
	while high-low > 1e-6
		mid = (low+high)/2.0
		if n/mid - mid > c
			low = mid
		else
			high = mid
		end
	end
	x = mid.round
	t = x
	total = 0
	while t != 0
		total += t%10
		t /= 10
	end
	if total == c
		candidates.push(x)
	end
end

if candidates.length == 0
	puts -1
else
	puts candidates.sort[0]
end

n = gets.to_i

# while l <= r
# 	x  = l + (r-l)/2
# 	s = x.to_s.split("").map(&:to_i).inject(0,:+)
# 	puts x
# 	if ((x * x) + (s * x) - n) == 0
# 		ans = x
# 		break
# 	else
# 		r = x - 1
# 	end
# end

# puts x
ans = false
min = n
(1..90).each do |s|
	a = 1
	b = s
	c = -n
	d = (b ** 2) - (4 * a * c)
	if d >=0
		r1 = (-b + Math.sqrt(d))/(2 * a)
		r2 = (-b - Math.sqrt(d))/(2 * a)
	elsif d == 0
		r1 = r2 = (-b)/(2 * a)
	end
	# puts "sum #{s} roots  #{r1} #{r2}"
	if r1 && r2
		arr = []
		sum = r1.to_i.to_s.split("").map(&:to_i).inject(0,:+)
		arr << r1 if r1 % 1 == 0 && s == sum
		sum = r2.to_i.to_s.split("").map(&:to_i).inject(0,:+)
		arr << r2 if  r2 % 1 == 0 && s == sum
		# puts "sum #{s} #{arr}"
		val = arr.min
		min = val if val && val > 0 && val < min
		ans = true
	end
end
if ans
puts min.to_i
else
	puts "-1"
end

n = gets.to_i

# while l <= r
# 	x  = l + (r-l)/2
# 	s = x.to_s.split("").map(&:to_i).inject(0,:+)
# 	puts x
# 	if ((x * x) + (s * x) - n) == 0
# 		ans = x
# 		break
# 	else
# 		r = x - 1
# 	end
# end

# puts x
ans = false
min = n
(1..90).each do |s|
	a = 1
	b = s
	c = -n
	d = (b ** 2) - (4 * a * c)
	if d >=0
		r1 = (-b + Math.sqrt(d))/(2 * a)
		r2 = (-b - Math.sqrt(d))/(2 * a)
	elsif d == 0
		r1 = r2 = (-b)/(2 * a)
	end
	# puts "sum #{s} roots  #{r1} #{r2}"
	if r1 && r2
		arr = []
		sum = r1.to_i.to_s.split("").map(&:to_i).inject(0,:+)
		arr << r1 if r1 % 1 == 0 && r1 > 0 && s == sum
		sum = r2.to_i.to_s.split("").map(&:to_i).inject(0,:+)
		arr << r2 if  r2 % 1 == 0 && r2 > 0 && s == sum
		unless arr.empty?
		# puts "ar #{arr}"
			val = arr.min
			min = val if val && val < min
			# puts "#{val}"
			ans = true
		end
	end
end
if ans
	puts min.to_i
else
	puts "-1"
end

n = gets.to_i

# while l <= r
# 	x  = l + (r-l)/2
# 	s = x.to_s.split("").map(&:to_i).inject(0,:+)
# 	puts x
# 	if ((x * x) + (s * x) - n) == 0
# 		ans = x
# 		break
# 	else
# 		r = x - 1
# 	end
# end

# puts x
ans = false
min = n
(1..90).each do |s|
	a = 1
	b = s
	c = -n
	d = (b ** 2) - (4 * a * c)
	if d >=0
		r1 = (-b + Math.sqrt(d))/(2 * a)
		r2 = (-b - Math.sqrt(d))/(2 * a)
	elsif d == 0
		r1 = r2 = (-b)/(2 * a)
	end
	# puts "sum #{s} roots  #{r1} #{r2}"
	if r1 && r2
		arr = []
		sum = r1.to_i.to_s.split("").map(&:to_i).inject(0,:+)
		arr << r1 if r1 % 1 == 0 && s == sum
		sum = r2.to_i.to_s.split("").map(&:to_i).inject(0,:+)
		arr << r2 if  r2 % 1 == 0 && s == sum
		unless arr.empty?
			val = arr.min
			min = val if val && val > 0 && val < min
			ans = true
		end
	end
end
if ans
	puts min.to_i
else
	puts "-1"
end

n = gets.to_i

# while l <= r
# 	x  = l + (r-l)/2
# 	s = x.to_s.split("").map(&:to_i).inject(0,:+)
# 	puts x
# 	if ((x * x) + (s * x) - n) == 0
# 		ans = x
# 		break
# 	else
# 		r = x - 1
# 	end
# end

# puts x
ans = false
min = n
(1..90).each do |s|
	a = 1
	b = s
	c = -n
	d = (b ** 2) - (4 * a * c)
	if d >=0
		r1 = (-b + Math.sqrt(d))/(2 * a)
		r2 = (-b - Math.sqrt(d))/(2 * a)
	elsif d == 0
		r1 = r2 = (-b)/(2 * a)
	end
	# puts "sum #{s} roots  #{r1} #{r2}"
	if r1 && r2
		arr = []
		sum = r1.to_i.to_s.split("").map(&:to_i).inject(0,:+)
		arr << r1 if r1 % 1 == 0 && r1 > 0 && s == sum
		sum = r2.to_i.to_s.split("").map(&:to_i).inject(0,:+)
		arr << r2 if  r2 % 1 == 0 && r2 > 0 && s == sum
		unless arr.empty?
		puts "s #{s} ar #{r1} #{r2}"
			val = arr.min
			min = val if val && val < min
			# puts "#{val}"
			ans = true
		end
	end
end
if ans
	if min == 999959999
		puts -1
	else
	puts min.to_i
	end
else
	puts "-1"
end

def s(x)
  sum = 0
  while x>0
    sum+= x%10
    x /= 10
  end
  sum
end

n = gets.to_i
x = Math.sqrt(n).round-1
while x*x <= n
  if x*(x+s(x))==n
    puts x
    exit
  end
  x+=1
end
puts -1

def s(x)
  sum = 0
  while x>0
    sum+= x%10
    x /= 10
  end
  sum
end

n = gets.to_i
x = Math.sqrt(n).round - 160;

321.times do |i|
  if x*(x+s(x))==n
    puts x
    exit
  end
  x+=1
end
puts -1

def s(x)
  sum = 0
  while x>0
    sum+= x%10
    x /= 10
  end
  sum
end

n = gets.to_i
x = Math.sqrt(n).round-s(Math.sqrt(n).round)-1
while x*x <= n+s(x)
  if x*(x+s(x))==n
    puts x
    exit
  end
  x+=1
end
puts -1

def s(x)
  sum = 0
  while x>0
    sum+= x%10
    x /= 10
  end
  sum
end

n = gets.to_i
x =  Math.sqrt(n).round

while x*x <= n
   if x*(x+s(x))==n
     puts x
     exit
   end
  x+=1
end
puts -1

def s(x)
	ret=0
	while x>0
		ret+=x%10
		x/=10
	end
	ret
end

def is_int?(_x)
	x=_x.round
	(x-1e-9<_x)&&(_x<x+1e-9)
end

n=gets.to_i
ans=1.upto(162).map{|s|
	_x=(-s+(s*s+4*n)**0.5)/2.0
	if is_int?(_x)
		x=_x.round
		if x*x+s(x)*x-n==0
			x
		else
			nil
		end
	else
		nil
	end
}

p ans.any? ? ans.compact.min : -1

def s(x)
	ret=0
	while x>0
		ret+=x%10
		x/=10
	end
	ret
end

def is_int?(_x)
	x=_x.round
	(x-1e-9<_x)&&(_x<x+1e-9)
end

n=gets.to_i
ans=100.times.map{|s|
	_x=(-s+(s*s+4*n)**0.5)/2.0
	if is_int?(_x)
		x=_x.round
		if x*x+s(x)*x-n==0
			x
		else
			nil
		end
	else
		nil
	end
}

p ans.any? ? ans.compact.min : -1

def s(x)
	ret=0
	while x>0
		ret+=x%10
		x/=10
	end
	ret
end

def is_int?(_x)
	x=_x.round
	(x-1e-19<_x)&&(_x<x+1e-19)
end

n=gets.to_i
ans=1.upto(162).map{|s|
	_x=(-s+(s*s+4*n)**0.5)/2.0
	if is_int?(_x)
		x=_x.round
		if x*x+s(x)*x-n==0
			x
		else
			nil
		end
	else
		nil
	end
}

p ans.any? ? ans.compact.min : -1


/(?<a>[\d]+) (?<b>[\d]+)/ =~ gets.chomp
a = a.to_i
b = b.to_i

def bite(size, mults=[2, 3, 5])	# => [b*2, b*3, b*5, leftovers || 1]
	bitesizes = []
	mults.each do |mult|
		bite = 0
		bite, size = (bite+1), (size/mult) while (size%mult)==0
		bitesizes << bite
	end
	bitesizes << size
	return bitesizes
end

*bitesA, leftA = bite(a)
*bitesB, leftB = bite(b)

if (leftA != leftB)
	puts -1
else
	p (bitesA.zip(bitesB).map{ |bA, bB|
		(bA-bB).abs
	}.reduce(&:+))
end

a,b=gets.chomp.split(' ').map(&:to_i)
tmp=a.gcd(b)
a/=tmp
b/=tmp
ctr=0
while a%2==0
	a/=2
	ctr+=1
end
while b%2==0
	b/=2
	ctr+=1
end
while a%3==0
	a/=3
	ctr+=1
end
while b%3==0
	b/=3
	ctr+=1
end
while a%5==0
	a/=5
	ctr+=1
end
while b%5==0
	b/=5
	ctr+=1
end
if a+b > 2
	puts "-1"
else
	puts ctr
end


s=gets.chomp
c=s.count(?o)
puts c>0&&s.size%c>0?:No: :Yes

s=gets.chomp

li=s.count('-')
pe=s.count('o')

if pe==0
  puts 'YES'
else
  if li%pe==0
    puts 'YES'
  else
    puts 'NO'
  end
end

PEARL = 'o'
LINK = '-'

necklace = STDIN.gets.chomp

def adjustable?(necklace)
  pearl_count = necklace.count(PEARL)
  return true if pearl_count == 0
  link_count = necklace.count(LINK)

  link_count % pearl_count == 0
end

if adjustable?(necklace)
  puts 'YES'
else
  puts 'NO'
end

s=gets.chomp
c=s.count(?o)
puts c==0||s.size%c>0?:No: :Yes

s=gets.chomp
c=s.count(?o)
puts c>0||s.size%c>0?:No: :Yes

PEARL = 'o'
LINK = '-'

necklace = STDIN.gets.chomp

def adjustable?(necklace)
  pearl_count = necklace.count(PEARL)
  if pearl_count == 1
    true
  else
    link_count = necklace.count(LINK)
    link_count % (pearl_count - 1) == 0
  end
end

if adjustable?(necklace)
  puts 'YES'
else
  puts 'NO'
end


n=gets.to_i
a=gets.split.map{|e| e.to_i}
b=a.index(1)
c=a.index(n)
b1=[b,c].min
c1=[b,c].max
n-=1
if b1==0 || c1==n then
	puts n
else
	puts [c1,n-b1].max
end

n=gets.to_i;a=gets.split.map(&:to_i);puts [a.index(n), n-a.index(n)-1, a.index(1), n-a.index(1)-1].max

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

if n <= 3
  puts n - 1
else
  i = as.index(1)
  j = as.index(n)
  ans = (i - j).abs
  ans = [ans, n - 1 - [i, j].min].max
  ans = [ans, [i, j].max].max
  puts ans
end

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

for i in 0...n
	biggest = i + 1 if n == nums[i]
	smallest = i + 1 if 1 == nums[i]
end

puts [n - [smallest, biggest].min, [smallest, biggest].max - 1].max

=begin
7
1
6
5
3
4
7
2

6
6
5
4
3
2
1

3
2 3 1

=end

n = 0
nums = Array.new

biggest = 0
smallest = 100

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

#p nums
#puts n
#puts nums.last

for i in 0..n
	#nums.push($stdin.read.chomp.to_i)
	#thing = gets.chomp.split('|')[1].scan(/\d+/).map{|n| n.to_i}
	if n == nums[i]
		biggest = i + 1
	end
	if 1 == nums[i]
		smallest = i + 1
	end
end

#puts "Biggest: #{biggest}, smallest: #{smallest}\n\n"

puts [n - [smallest, biggest].min, [smallest, biggest].max - 1].max

=begin
7
1
6
5
3
4
7
2

6
6
5
4
3
2
1

3
2 3 1

=end

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

p (d.index(1)-d.index(n)).abs + [[d.index(1),d.index(n)].min,n-1-[d.index(1),d.index(n)].max].max

n = gets.to_i
a = gets.split.map(&:to_i)
b = [a.index(1), a.index(n)].sort
puts [n - 1 - b[0], b[1]].max

size_of_permutation = gets.chomp.to_i
integers_array = gets.chomp.split.map(&:to_i)

def max_distance(size, list)
  min_index = nil
  max_index = nil

  for i in 0..(list.length - 1)
    min_index = i if list[i] == 1
    max_index = i if list[i] == size

    if min_index && max_index
      break
    end
  end

  potential_distance = [min_index, max_index, size - 1 - min_index, size - 1 - max_index]
  max_distance = potential_distance[0]
  for i in potential_distance
    if i > max_distance
      max_distance = i
    end
  end
  max_distance
end

puts max_distance(size_of_permutation, integers_array)

size_of_permutation = gets.chomp.to_i
integers_array = gets.chomp.split.map(&:to_i)

def max_distance(size, list)
  min, max = list[0], list[0]
  min_index = 0
  max_index = 0

  for i in 0..(list.length - 1)
    if list[i] < min
      min = list[i]
      min_index = i
    end

    if list[i] > max
      max = list[i]
      max_index = i
    end
  end

  potential_distance = [min_index, max_index, size - 1 - min_index, size - 1 - max_index]
  max_distance = potential_distance[0]
  for i in potential_distance
    if i > max_distance
      max_distance = i
    end
  end
  max_distance
end

puts max_distance(size_of_permutation, integers_array)

arrLen = gets.chomp.to_i
arr = gets.chomp.split(' ').map { |i| i.to_i }

minIdx = arr.index { |i| i == arr.min}
maxIdx = arr.index { |i| i == arr.max}

biggerIdx = minIdx > maxIdx ? minIdx : maxIdx
nonBiggerIdx = minIdx < maxIdx ? minIdx : maxIdx

candidate_1 = (arrLen - 1) - nonBiggerIdx
candidate_2 = (arrLen - 1) - biggerIdx
candidate_3 = nonBiggerIdx - 0
candidate_4 = biggerIdx - 0

ans = Array.new
ans << candidate_1
ans << candidate_2
ans << candidate_3
ans << candidate_4

puts ans.max

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

first = arr.index(1)
last = arr.index(n)
if first == 0 and last == n - 1
    p (n - 1)
else
    p [first, last, n - 1 - first, n - 1 - last].max
end

n=gets.to_i
a,b=gets.split.map(&:to_i).each_with_index.select{|e,i|e==1||e==n}.map(&:last)
p [n-1-a,n-1-b,a,b].max

def checks(n, arrays)
  arrays = arrays.split.map(&:to_i)
  n = n.to_i

  for i in (0..n - 1)
    if arrays[i] == 1
      pos1 = i
    end

    if arrays[i] == n
      posn = i
    end
  end

  puts [posn, n - 1 - posn, pos1, n - 1 - pos1].max
end

checks(gets, gets)

def max (a,b)
    a > b ? a : b
end

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

pos = []
arr.each_with_index do |value, index|
    if 1 == value
        pos.push index
    elsif n == value
        pos.push index
    end
end

puts max(pos[1], n - pos[0] - 1)

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

pos = []
arr.each_with_index do |value, index|
    if 1 == value
        pos.push index
    elsif n == value
        pos.push index
    end
end

p [pos[1], n - pos[0] - 1].max

class Array
  def swap(a, b)
    clone = self.dup
    clone[a], clone[b] = clone[b], clone[a]

    clone
  end
  def max_distance
    (self.index(self.min) - self.index(self.max)).abs
  end
end

n = gets.chomp.to_i
arr = gets.chomp.split.map(&:to_i)
results = []

(0...n).each do |i|
  (0...n).each do |j|
    next if i == j
    results << arr.swap(i, j).max_distance
  end
end
puts results.max

n = readline.to_i
arr = readline.split(' ').collect(&:to_i)
i, j = arr.index(1), arr.index(n)
puts [[i, n - i - 1].max, [j, n - j - 1].max].max

n = gets.chomp.to_i
a = gets.chomp.split(/ /).map(&:to_i)
min_element = a.min
max_element = a.max
pos_min = a.index min_element
pos_max = a.index max_element
start_min_dist = pos_min
start_max_dist = pos_max
end_min_dist = n - pos_min - 1
end_max_dist = n - pos_max - 1
puts [start_min_dist, start_max_dist, end_min_dist, end_max_dist].max

n = gets.to_i

numbers = gets

res = numbers.split(' ')

p_max = -1
p_min = -1

res.each_with_index do |r,i|
    if (r.to_i == 1)
        p_min = i + 1
    end
    if (r.to_i == n)
        p_max = i + 1
    end
end

if (p_max < p_min)
    t = p_max
    p_max = p_min
    p_min = t
end
puts (n-p_min>p_max-1)? n-p_min : p_max - 1

n=gets.to_i;a=gets.split.map(&:to_i);(amax,amin)=[a.find_index(a.max),a.find_index(a.min)];puts [amax, n-amax-1, amin, n-amin-1].max

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

first = arr.index(1)
p first
last = arr.index(n)
if first == 0 and last == n - 1
    p (n - 1)
else
    p [first, last, n - 1 - first, n - 1 - last].max
end

n = gets.chomp.to_i
a = gets.chomp.split(/ /).map(&:to_i)
min_element = a.min
max_element = a.max
pos_min = a.index min_element
pos_max = a.index max_element
if pos_min > pos_max
    pos_min = n - 1
elsif pos_max > pos_min
    pos_max = n - 1
end
dist = (pos_min - pos_max).abs
puts dist

n = gets.to_i

numbers = gets

res = numbers.split(' ')

p_max = -1
p_min = -1

res.each_with_index do |r,i|
    if (r.to_i == 1)
        p_min = i + 1
    end
    if (r.to_i == n)
        p_max = i + 1
    end
end

if (p_max < p_min)
    t = p_max
    p_max = p_min
    p_min = t
end
puts (n-p_min>p_max)? n-p_min : p_max

n = 0
nums = Array.new

biggest = 0
smallest = 100

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

#p nums
#puts n
#puts nums.last

for i in 0..n
	#nums.push($stdin.read.chomp.to_i)
	#thing = gets.chomp.split('|')[1].scan(/\d+/).map{|n| n.to_i}
	if n == nums[i]
		biggest = i + 1
	end
	if 1 == nums[i]
		smallest = i + 1
	end
end

#puts "Biggest: #{biggest}, smallest: #{smallest}\n\n"

puts [n - [smallest, biggest].min, [smallest, biggest].min - 1].max

=begin
7
1
6
5
3
4
7
2

6
6
5
4
3
2
1

=end

n = gets.to_i
a = gets.split.map(&:to_i)
b = [a.index(1), a.index(n)].sort
puts [n - b[0], b[1]].max - 1

size_of_permutation = gets.chomp.to_i
integers_array = gets.chomp.split.map(&:to_i)

def max_distance(size, list)
  min, max = list[0], list[0]
  min_index = 0
  max_index = 0

  for i in 0..(list.length - 1)
    if list[i] < min
      min = list[i]
      min_index = i
    end

    if list[i] > max
      max = list[i]
      max_index = i
    end
  end

  if min_index == 0 || max_index == 0 || min_index == size - 1 || max_index == size - 1
    return size - 1
  end

  min_index < max_index ? size - 1 - min_index : size - 1 - max_index
end

puts max_distance(size_of_permutation, integers_array)

size_of_permutation = gets.chomp.to_i
integers_array = gets.chomp.split.map(&:to_i)

def max_distance(size, list)
  min, max = list[0], list[0]
  min_index = 0
  max_index = 0

  for i in 0..(list.length - 1)
    if list[i] < min
      min = list[i]
      min_index = i
    end

    if list[i] > max
      max = list[i]
      max_index = i
    end
  end

  max_distance = min_index < max_index ? size - 1 - min_index : size - 1 - max_index
end

puts max_distance(size_of_permutation, integers_array)

arrLen = gets.chomp.to_i
arr = gets.chomp.split(' ').map { |i| i.to_i }

minIdx = arr.index { |i| i == arr.min}
maxIdx = arr.index { |i| i == arr.max}

biggerIdx = minIdx > maxIdx ? minIdx : maxIdx
nonBiggerIdx = minIdx < maxIdx ? minIdx : maxIdx

ans = if (arrLen - biggerIdx) > (nonBiggerIdx - 0)
	arrLen - nonBiggerIdx
else
	biggerIdx - 0
end

puts ans - 1


str = gets.strip!
re_pattern = /^\w{1,16}@(\w{1,16}(\.\w{1,16})*)(\/\w{1,16})?$/
if str.match(re_pattern) && $1.size <= 32
	puts 'YES'
else
	puts 'NO'
end

str = gets.strip!
re_pattern = /^\w{1,16}@\w{1,16}(\.\w{1,16})*(\/\w{1,16})?$/
if str.match(re_pattern)
	puts 'YES'
else
	puts 'NO'
end

def valid_word?(s)
    s =~ /^[_a-zA-Z0-9_]{1,16}$/
end

def solve(s)

    words = (s + '.a').split(/[.@\/]/)
    words.pop
    return false unless words.all? { |w| valid_word? w }

    wr = '[_a-zA-Z0-9_]{1,16}' # word regex
    rr = '[_a-zA-Z0-9_.]{1,32}' # resource regex

    return s =~ Regexp.new("^#{wr}@#{wr}(\\.#{wr})*(\\/#{wr})?") &&
           s =~ Regexp.new("^#{wr}@#{rr}(\\/#{wr})?")

end

s = gets.chomp
#s = 'mike@codeforces.com'
#s = 'john.smith@codeforces.ru/contest.icpc/12'
#s = '007@en.codeforces.com/contest'
puts solve(s) ? 'YES' : 'NO'

s = gets.strip
unless s =~ %r{^([0-9a-zA-Z_]{1,16})@([0-9a-zA-Z_]{1,16}(\.[0-9a-zA-Z_]{1,16})*)((/[0-9a-zA-Z_]{1,16})?)$}
  puts "NO"
  exit 0
end
#puts $1, $2, $3, $4
username, hostname, resource = $1, $2, $4

if hostname.length >= 1 && hostname.length <= 32
  puts "YES"
else
  puts "NO"
end

def user_ok(s)
  s.length >= 1 && s.length <= 16 && s =~ /^[0-9a-zA-Z_]*$/
end

def host_ok(s)
#  puts s
  if s.length < 1 || s.length > 32
    return false
  end
  if s[0] == "." || s[-1] == "."
    return false
  end
  for st in s.split(".") do
#    puts st
    unless user_ok(st)
      return false
    end
  end
  true
end

s = gets.strip
ok = true
unless s =~ %r{^([^@]+)@([^/]+)((/[0-9a-zA-Z_]*)?)$}
  puts "NO"
  exit 0
end
username, hostname, resource = $1, $2, $3
unless user_ok(username) && host_ok(hostname)
  ok = false
end

if resource.length == 1 || resource.length > 17
  ok = false
end

if ok
  puts "YES"
else
  puts "NO"
end

def del(s)
    return s.delete("abcdefghijklmnopqrstuvwxyz_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")
end

s = gets.chomp
result = "YES"
if (k = s.index("@")) then
    if s[0...k].size < 1 then
        result = "NO"
    end
    user = del(s[0...k])
    if user.size > 0 then
        result = "NO"
    end
    if (n = s.index("/")) then
        host = s[k+1...n]
        resource = s[n+1..-1]
    else
        host = s[k+1..-1]
        resource = nil
    end
    if host.size < 1 then
        result = "NO"
    end
    k = -1
    while (m = host.index(".", k+1)) do
        if m-k > 17 || m-k < 2 then
            result = "NO"
        end
        k = m
    end
    host = del(host).delete(".")
    if host.size > 0 then
        result = "NO"
    end

    if resource then
        if s[n-1] == "." then
            result = "NO"
        end
        if resource.size > 16 || resource.size < 1 then
            result = "NO"
        else
            resource = del(resource)
            if resource.size > 0 then
                result = "NO"
            end
        end
    else
        if s[-1] == "." then
            result = "NO"
        end
    end
else
    result = "NO"
end

puts result

def del(s)
    return s.delete("abcdefghijklmnopqrstuvwxyz_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")
end

s = gets.chomp
result = "YES"
if (k = s.index("@")) then
    if s[0...k].size < 1 then
        result = "NO"
    end
    user = del(s[0...k])
    if user.size > 0 then
        result = "NO"
    end
    if (n = s.index("/")) then
        host = s[k+1...n]
        resource = s[n+1..-1]
    else
        host = s[k+1..-1]
        resource = nil
    end
    if host.size < 1 then
        result = "NO"
    end
    k = -1
    while (m = host.index(".", k+1)) do
        if m-k > 16 then
            result = "NO"
        end
        k = m
    end
    host = del(host).delete(".")
    if host.size > 0 then
        result = "NO"
    end

    if resource then
        if s[n] == "." then
            result = "NO"
        end
        if resource.size > 16 then
            result = "NO"
        else
            resource = del(resource)
            if resource.size > 0 then
                result = "NO"
            end
        end
    else
        if s[-1] == "." then
            result = "NO"
        end
    end
else
    result = "NO"
end

puts result

def del(s)
    return s.delete("abcdefghijklmnopqrstuvwxyz_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")
end

s = gets.chomp
result = "YES"
if (k = s.index("@")) then
    if s[0...k].size < 1 then
        result = "NO"
    end
    user = del(s[0...k])
    if user.size > 0 then
        result = "NO"
    end
    if (n = s.index("/")) then
        host = s[k+1...n]
        resource = s[n+1..-1]
    else
        host = s[k+1..-1]
        resource = nil
    end
    if host.size < 1 then
        result = "NO"
    end
    k = -1
    while (m = host.index(".", k+1)) do
        if m-k > 16 then
            result = "NO"
        end
        k = m
    end
    host = del(host).delete(".")
    if host.size > 0 then
        result = "NO"
    end

    if resource then
        if resource.size > 16 then
            result = "NO"
        else
            resource = del(resource)
            if resource.size > 0 then
                result = "NO"
            end
        end
    end
else
    result = "NO"
end

puts result

def del(s)
    return s.delete("abcdefghijklmnopqrstuvwxyz_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")
end

s = gets.chomp
result = "YES"
if (k = s.index("@")) then
    if s[0...k].size < 1 then
        result = "NO"
    end
    user = del(s[0...k])
    if user.size > 0 then
        result = "NO"
    end
    if (n = s.index("/")) then
        host = s[k+1...n]
        resource = s[n+1..-1]
    else
        host = s[k+1..-1]
        resource = nil
    end
    if host.size < 1 then
        result = "NO"
    end
    k = -1
    while (m = host.index(".", k+1)) do
        if m-k > 17 || m-k < 2 then
            result = "NO"
        end
        k = m
    end
    host = del(host).delete(".")
    if host.size > 0 then
        result = "NO"
    end

    if resource then
        if s[n] == "." then
            result = "NO"
        end
        if resource.size > 16 then
            result = "NO"
        else
            resource = del(resource)
            if resource.size > 0 then
                result = "NO"
            end
        end
    else
        if s[-1] == "." then
            result = "NO"
        end
    end
else
    result = "NO"
end

puts result

def valid_word?(s)
    s =~ /^[_a-zA-Z0-9_]{1,16}$/
end

def solve(s)
    a = s.split('@')
    return false unless a.size == 2
    return false unless valid_word? a.shift
    a = a.first
    return false if a[-1..-1] == '/'
    a = a.split('/')
    return false if a.size > 2
    return false if a.size == 2 && !valid_word?(a[1])
    a = a[0]
    return false unless a.size <= 32
    return false if a[-1..-1] == '.'
    a = a.split('.')
    return a.all? { |w| valid_word? w }
end

s = gets.chomp
#s = 'mike@codeforces.com'
#s = 'john.smith@codeforces.ru/contest.icpc/12'
#s = '007@en.codeforces.com/contest'
puts solve(s) ? 'YES' : 'NO'

s = gets.strip
unless s =~ %r{([0-9a-zA-Z_]{1,16})@([0-9a-zA-Z_]{1,16}(\.[0-9a-zA-Z_]{1,16})*)((/[0-9a-zA-Z_]{1,16})?)$}
  puts "NO"
  exit 0
end
#puts $1, $2, $3, $4
username, hostname, resource = $1, $2, $4

if hostname.length >= 1 && hostname.length <= 32
  puts "YES"
else
  puts "NO"
end

def del(s)
    return s.delete("abcdefghijklmnopqrstuvwxyz_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")
end

s = gets.chomp
result = "YES"
k = s.index("@")
user = del(s[0...k])
if user.size > 0 then
    result = "NO"
end
if (n = s.index("/")) then
    host = s[k+1...n]
    resource = s[n+1..-1]
else
    host = s[k+1..-1]
    resource = nil
end
k = -1
while (m = host.index(".", k+1)) do
    if m-k > 16 then
        result = "NO"
    end
    k = m
end
host = del(host).delete(".")
if host.size > 0 then
    result = "NO"
end

if resource then
    if resource.size > 16 then
        result = "NO"
    else
        resource = del(resource)
        if resource.size > 0 then
            result = "NO"
        end
    end
end

puts result

def del(s)
    return s.delete("abcdefghijklmnopqrstuvwxyz_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")
end

s = gets.chomp
result = "YES"
if (k = s.index("@")) then
    if s[0...k].size < 1 then
        result = "NO"
    end
    user = del(s[0...k])
    if user.size > 0 then
        result = "NO"
    end
    if (n = s.index("/")) then
        host = s[k+1...n]
        resource = s[n+1..-1]
    else
        host = s[k+1..-1]
        resource = nil
    end
    if host.size < 1 then
        result = "NO"
    end
    k = -1
    while (m = host.index(".", k+1)) do
        if m-k > 17 || m-k < 2 then
            result = "NO"
        end
        k = m
    end
    host = del(host).delete(".")
    if host.size > 0 then
        result = "NO"
    end

    if resource then
        if s[n-1] == "." then
            result = "NO"
        end
        if resource.size > 16 then
            result = "NO"
        else
            resource = del(resource)
            if resource.size > 0 then
                result = "NO"
            end
        end
    else
        if s[-1] == "." then
            result = "NO"
        end
    end
else
    result = "NO"
end

puts result


d,l,v,w=gets.split.map &:to_f
puts "%.20f" % ((l - d) / (v + w))

d,l,v1,v2 = gets.chomp.split(' ').map(&:to_i)
puts((l-d).to_f/(v1+v2))

d, l, v1, v2 = gets.split(' ').map &:to_i

puts (l - d).to_f/(v1 + v2)

d, L, v1, v2 = gets.chomp.split(' ').map(&:to_f)

res = (L - d) / (v1 + v2)
p res

class Solver
	def main
		d, l, v1, v2 = gets.split.map { |x| x.to_i }
		puts format("%.8f", (l - d).to_f / (v1 + v2).to_f)
	end
end
Solver.new.main

d,l,v1,v2=gets.split.map{|e| e.to_f}
puts (l-d)/(v1+v2)

d, l, v1, v2 = gets.chomp.split.map(&:to_i)

puts (l - d) / (v1 + v2).to_f


require 'set'

$set=Set.new
$n=gets.to_i

def dfs num,x,y
  if (1..$n)===num
    $set<<num
    dfs(num*10+x,x,y)
    dfs(num*10+y,x,y)
  end
end

count=0

(0..9).each {|x|
  (0..9).each {|y|
    dfs(x,x,y)
  }
}

puts $set.size

require 'set'

$set=Set.new
$n=gets.to_i

def dfs num,x,y
  if (1..$n)===num
    $set<<num
    dfs(num*10+x,x,y)
    dfs(num*10+y,x,y)
  end
end

count=0

(0..9).each {|x|
  (0..9).each {|y|
    dfs(x,x,y)
    dfs(y,x,y)
  }
}

puts $set.size

# # n = gets.to_i
# # l = n.to_s.length

# # if l > 2
# # 	list = [9,90]
# # 	x = 81
# # 	(l - 2).times do |i|
# # 		x *= 2
# # 	end
# # 	x +=  9
# # else
# # 	puts n
# # end

# # def dfs(num) #// run it as dfs(0)
# #   @ans += 1 if (num > 0 && num <= @n)
# #   return if (num >= 10**8)
# #   (0..9).each do |a|
# #   	number = num*10+a
# #     if number >0
# #       if number.to_s.split("").uniq.length <= 2
# #         dfs(number)
# #       end
# #     end
# #   end
# # end
# # require 'Set'
# def dfs(num) #// run it as dfs(0)
#   (1..@n).each do |a|
# 	  return if (a >= 10**8)
# 	  if @n > 100000
# 	  	@ans += 1
# 	  else
# 	      if a.to_s.chars.to_a.uniq.length <= 2
# 	      	@ans += 1
# 	      end
#   	  end
#   end
# end

# @n = gets.to_i
# @ans = 0
# dfs(0)
# puts @ans

require 'Set'

def dfs(x,y,num,cnt=false)
	return if num > @n  || (num == 0 && !cnt)
	@s << num if num > 0
	dfs(x,y,num * 10 + x)
	dfs(x,y,num * 10 + y)
end

@n = gets.to_i
@s = Set.new
(0..9).each do |i|
	((i+1)..9).each do |j|
		dfs(i,j,0,true)
	end
end
puts @s.length


# t = gets.to_i
# t.times do
n, m = gets.split.map(&:to_i)
count = 0
(1..n).each do |x|
	y1 = 5 - x % 5
	k = ((m - y1)/5).to_i
	# y2 = y1 + 5* k
	count += k+1
end
puts count

n, m = gets.chomp.split(' ').map(&:to_i)
x = 1
ans = 0
until x > n
	ans += ((m + x) / 5) - (x / 5)
	x += 1
end

puts ans

n, m = gets.strip.split.map(&:to_i)
count = Array.new(1e6 + 1, 0)
ans = 0
(1..n).each do |i|
    count[i % 5] += 1
end
(1..m).each do |i|
    ans += count[(5 - i % 5) % 5]
end
puts ans

x,y=gets.split.map{|e| e.to_i}
x,y=[x,y].min,[x,y].max
z=x+y
ans=0
4.step(z,5){|i|
	if i>y then
		ans+=(x-(i-y))
	else
		ans+=[x,i].min
	end
}
puts ans

n, m = gets.split(' ').map(&:to_i)
n_full, n_rest = n.divmod 5
m_full, m_rest = m.divmod 5

puts (1..4).map { |i| (n_full + (n_rest >= i ? 1 : 0)) * (m_full + (m_rest >= (5-i) ? 1 : 0)) }.reduce(:+) + n_full * m_full

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

ans = 0
for i in 0..4
  x = n / 5
  x += 1 if 0 < i && i <= n % 5
  y = m / 5
  y += 1 if i < 5 && 5 - i <= m % 5
  ans += x * y
end

puts ans

n=gets.chomp.to_s.split(" ")
n,m=n[0].to_s.to_i,n[1].to_s.to_i
res=0
1.upto(n) do |x|   # 5-0
                   # 4-1 3-2 2-3 1-4
  res+=(m+x%5)/5

end
print res


class Solver
  def solve(*a)
    p = a[0]
    t = a[1]

    moves = []
    while p != t && moves.size < 8
      #puts "#{p} -> #{t}"

      moves << navigate(p,t)
    end
    moves
  end

  def navigate(p,t)
    dx = dir(t[0].ord - p[0].ord)
    dy = dir(t[1].ord - p[1].ord)

    p[0] = (p[0].ord + dx).chr
    p[1] = (p[1].ord + dy).chr

    ['L','','R'][dx+1] + ['D','','U'][dy+1]
  end

  def dir(d)
    return 0 if d == 0
    return 1 if d > 0
    return -1
  end
end

if __FILE__==$0
  a = gets.chomp
  b = gets.chomp
  s = Solver.new
  sol = s.solve(a,b)
  puts sol.count
  sol.each do |s|
    puts s
  end
end

s = gets
t = gets
sx = s[0..0].ord
sy = s[1..1].to_i
tx = t[0..0].ord
ty = t[1..1].to_i
dx = sx-tx
dy = sy-ty
step = [dx.abs,dy.abs].max
puts step
step.times do
  if dx<0
    print "R"
    dx += 1
  elsif dx>0
    print "L"
    dx -= 1
  end
  if dy<0
    print "U"
    dy += 1
  elsif dy>0
    print "D"
    dy -= 1
  end
  puts
end

input = gets
king = [input[0].ord - 96, input[1].ord - 48]
input = gets
target = [input[0].ord - 96, input[1].ord - 48]

path = Array.new

while king != target
  s = String.new
  if king[0] < target[0]
    s << "R"
    king[0] += 1
  elsif king[0] > target[0]
    s << "L"
    king[0] -= 1
  end
  if king[1] < target[1]
    s << "U"
    king[1] += 1
  elsif king[1] > target[1]
    s << "D"
    king[1] -= 1
  end
  path.concat([s])
end

puts path.count
path.each {|x| puts x}

s, t = gets.to_s, gets.to_s
row = t[0].ord - s[0].ord
col = t[1].ord - s[1].ord
if row.abs > col.abs
	puts row.abs
	rc = 1
	diff = (row.abs - col.abs).to_i
	sqr = row.abs - diff
else
	puts col.abs
	rc = 0
	diff = (col.abs - row.abs).to_i
	sqr = col.abs - diff
end
if row >= 0 and col >= 0
	sqr.times{
		puts "RU"
	}
	if rc == 1
		diff.times{
			puts "R"
		}
	else
		diff.times{
			puts "U"
		}
	end
elsif row <= 0 and col >= 0
	sqr.times{
		puts "LU"
	}
	if rc == 1
		diff.times{
			puts "L"
		}
	else
		diff.times{
			puts "U"
		}
	end
elsif row <= 0 and col <= 0
	sqr.times{
		puts "LD"
	}
	if rc == 1
		diff.times{
			puts "L"
		}
	else
		diff.times{
			puts "D"
		}
	end
else
	sqr.times{
		puts "RD"
	}
	if rc == 1
		diff.times{
			puts "R"
		}
	else
		diff.times{
			puts "D"
		}
	end
end

class King
  def initialize(s, t)
    @start = s
    @end = t
  end

  def get_path
    return 0 if @start == @end
    result = []
    horizontal = (@start[0] == @end[0])
    vertical = (@start[1] == @end[1])

    current = @start
    steps = 0
    until horizontal || vertical
      current = move_diag(current)
      horizontal = (current[0] == @end[0])
      vertical = (current[1] == @end[1])
      result << direction.join
      steps += 1
    end

    if vertical
      current_steps = (current[0].ord.to_i - @end[0].ord.to_i).abs
      result += [direction.first]*current_steps
      steps += current_steps
    elsif horizontal
      current_steps = (current[1].to_i - @end[1].to_i).abs
      result += [direction.last]*current_steps
      steps += current_steps
    end
    result.unshift(steps)

    # if @start == @end
    #   result << 0
    # elsif horizontal
    #   result = [steps_x.abs] + [direction.last]*steps_x.abs
    # elsif vertical
    #   result = [steps_y.abs] + [direction.first]*steps_y.abs
    # else
      # current = @start
      # steps = 0
      # until horizontal || vertical
      #   current = move_diag(current)
      #   horizontal = (current[0] == @end[0])
      #   vertical = (current[1] == @end[1])
      #   result << direction.join
      #   steps += 1
      # end
    # end
    result
  end

  def move_diag(position)
    x_inc = steps_x == 0 ? 0 : steps_x/steps_x.abs
    y_inc = steps_y == 0 ? 0 : steps_y/steps_y.abs
    [(position[0].ord - y_inc).chr, (position[1].to_i - x_inc)].join
  end

  def direction
    [direction_y, direction_x]
  end

  def direction_x
    steps_x > 0 ? 'D' : 'U'
  end

  def direction_y
    steps_y > 0 ? 'L' : 'R'
  end

  def steps_x
    @start[1].to_i - @end[1].to_i
  end

  def steps_y
    @start[0].ord.to_i - @end[0].ord.to_i
  end
end

s, t = [gets.chomp, gets.chomp]
game = King.new(s, t)
puts game.get_path

a = gets.chomp
b = gets.chomp
x, y = a[0].ord-b[0].ord, a[1].to_i-b[1].to_i
puts [x.abs, y.abs].max
s = ""
if x.abs > y.abs
    s = (x>0 ? "L" : "R")
else
    s = (y>0 ? "D" : "U")
end
print (s+"\n")*(x.abs-y.abs).abs
if x > 0
    s = (y > 0 ? "LD" : "LU")
else
    s = (y > 0 ? "RD" : "RU")
end
print (s+"\n")*[x.abs, y.abs].min

s=gets

t=gets

r=t[0].ord-s[0].ord

c=t[1].hex-s[1].hex

a=[""]*9

f=lambda{|r,c|r.times{|i|a[i]+=c}}

f.call(r,"R")

f.call(-r,"L")

f.call(c,"U")

f.call(-c,"D")

a.select!{|i|i!=""}

p a.size

puts a

include Math
a=0
"a".each_byte do |n|
  a=n
end
memo=gets.chomp!.scan(/./)
sx=0
memo[0].each_byte do |n|
  sx=n-a+1
end
sy=memo[1].to_i
ex=0
memo=gets.chomp!.scan(/./)
memo[0].each_byte do |n|
  ex=n-a+1
end
ey=memo[1].to_i
xx=ex-sx
yy=ey-sy
hosu=[xx<0 ? -xx : xx,yy<0 ? -yy :yy].max
puts hosu
if xx >=0 && yy>=0
  if xx>=yy
    yy.times do
      puts "RU"
    end
    (xx-yy).times do
      puts "R"
    end
  else
    xx.times do
      puts "RU"
    end
    (yy-xx).times do
      puts "U"
    end
  end
end
if xx >=0 && yy<0
  yy=-yy
  if xx>=yy
    yy.times do
      puts "RD"
    end
    (xx-yy).times do
      puts "R"
    end
  else
    xx.times do
      puts "RD"
    end
    (yy-xx).times do
      puts "D"
    end
  end
end
if xx < 0 && yy >=0
  xx=-xx
  if xx>=yy
    yy.times do
      puts "LU"
    end
    (xx-yy).times do
      puts "L"
    end
  else
    xx.times do
      puts "LU"
    end
    (yy-xx).times do
      puts "U"
    end
  end
end
if xx <0 && yy<0
  xx=-xx
  yy=-yy
  if xx>=yy
    yy.times do
      puts "LD"
    end
    (xx-yy).times do
      puts "L"
    end
  else
    xx.times do
      puts "LD"
    end
    (yy-xx).times do
      puts "D"
    end
  end
end

s=gets.chomp.split("")
t=gets.chomp.split("")
valu=1..8
alph=('a' .. 'h')
valu=[*valu]
alph=[*alph]
valu_hash={}
i=0
loop do
	break if i==8
	valu_hash[alph[i]]=valu[i]
	i+=1
 end
dir_arry=[]
if valu_hash[s[0]]< valu_hash[t[0]]
   dir_arry[0]="R"
elsif valu_hash[s[0]]> valu_hash[t[0]]
   dir_arry[0]="L"
else
   dir_arry[0]=0
end

if s[1].to_i< t[1].to_i
   dir_arry[1]="U"
elsif s[1].to_i> t[1].to_i
   dir_arry[1]="D"
else
   dir_arry[1]=0
end

hmove=valu_hash[s[0]] - valu_hash[t[0]]
if hmove<0
hmove=hmove*(-1)
end
vmove=s[1].to_i-t[1].to_i
if vmove<0
vmove=vmove*(-1)
end

if hmove==0
	puts vmove
	vmove.times{puts dir_arry[1]}
elsif vmove==0
	puts hmove
	hmove.times{puts dir_arry[0] }
elsif vmove==hmove
	puts hmove
    hmove.times{puts dir_arry[0]+dir_arry[1] }
elsif hmove>vmove
	puts hmove
	vmove.times{puts dir_arry[0]+dir_arry[1] }
	(hmove-vmove).times {puts dir_arry[0]}
elsif vmove>hmove
	puts vmove
	hmove.times{puts dir_arry[0]+dir_arry[1] }
	(vmove-hmove).times{puts dir_arry[1]}
end

s1 = gets
s2 = gets
dst1 = s2[0].ord - s1[0].ord
dst2 = s2[1].to_i - s1[1].to_i

puts [dst2.abs, dst1.abs].max
while dst2 != 0 or dst1 != 0 do
    if dst1 > 0 then
        printf "R"
        dst1 -= 1
    end
    if dst1 < 0 then
        printf "L"
        dst1 += 1
    end

    if dst2 > 0 then
        printf "U"
        dst2 -= 1
    end
    if dst2 < 0 then
        printf "D"
        dst2 += 1
    end
    puts
end

def get_path(src, dest)
  s_x, s_y = src.chars
  d_x, d_y = dest.chars
  path = []
  while s_x != d_x || s_y != d_y
    move = ''
    if (s_x > d_x)
      s_x = (s_x.ord - 1).chr
      move += 'L'
    elsif (s_x < d_x)
      s_x.next!
      move += 'R'
    end

    if (s_y > d_y)
      s_y = (s_y.ord - 1).chr
      move += 'D'
    elsif (s_y < d_y)
      s_y.next!
      move += 'U'
    end

    path << move
  end
  path
end

if __FILE__ == $0
  path = get_path(gets, gets)
  puts path.size
  path.each { |m| puts m }
end

start_point = gets.chomp
end_point = gets.chomp

character_start_point = start_point[0]
number_start_point = start_point[1].to_i

character_end_point = end_point[0]
number_end_point = end_point[1].to_i

vertical_moves_count = (number_start_point-number_end_point).abs
vertical_moves_character = number_start_point > number_end_point ? 'D' : 'U'

horizontal_moves_count = (character_start_point.ord - character_end_point.ord).abs
horizontal_moves_character = character_start_point.ord < character_end_point.ord ? 'R' : 'L'

max_steps = vertical_moves_count > horizontal_moves_count ? vertical_moves_count : horizontal_moves_count

puts max_steps

while max_steps > 0
  print horizontal_moves_character if horizontal_moves_count > 0
  print vertical_moves_character if vertical_moves_count > 0
  puts
  horizontal_moves_count -= 1
  vertical_moves_count -= 1
  max_steps -= 1
end

def f(x,y,gx,gy)
	if x==gx && y==gy then
		return ""
	else
		res=""
		x1=x
		y1=y
		if x<gx then
			x1=x+1
			res+="R"
		elsif x>gx
			x1=x-1
			res+="L"
		end
		if y<gy then
			y1=y+1
			res+="U"
		elsif y>gy then
			y1=y-1
			res+="D"
		end
		return res+"\n"+f(x1,y1,gx,gy)
	end

end

h=	Hash["a",1,"b",2,"c",3,"d",4,
		 "e",5,"f",6,"g",7,"h",8]

s1=gets.chomp
s2=gets.chomp
if s1==s2 then
	puts "0\n"
else
	x=f(h[s1[0]],s1[1].to_i,h[s2[0]],s2[1].to_i).split()
	puts x.size
	puts x*"\n"
end

start = gets().chomp!
finish =  gets().chomp!
LETTERS = ["a", "b", "c", "d", "e", "f", "g", "h"]
h_distance, v_distance = [LETTERS.index(finish[0,1]) - LETTERS.index(start[0,1]), finish[1,1].to_i - start[1,1].to_i]
moves = Array.new(7){""}
h_distance.abs().times {
|i|
  h_distance > 0 ? moves[i] << "R" : moves[i] << "L"
}
v_distance.abs().times {
|i|
  v_distance > 0 ? moves[i] << "U" : moves[i] << "D"
}
moves = moves.select(){|elem| elem != ""}
puts moves.length, moves

start = gets().chomp!
finish =  gets().chomp!
LETTERS = ["a", "b", "c", "d", "e", "f", "g", "h"]
h_distance = LETTERS.index(finish[0,1]) - LETTERS.index(start[0,1])
v_distance = finish[1,1].to_i - start[1,1].to_i
moves = Array.new(7){""}
h_distance.abs().times {
|i|
  h_distance > 0 ? moves[i] << "R" : moves[i] << "L"
}
v_distance.abs().times {
|i|
  v_distance > 0 ? moves[i] << "U" : moves[i] << "D"
}
moves = moves.select(){|elem| elem != ""}
puts moves.length, moves

def num(x)
    if x == "a"
        return 1
    elsif x == "b"
        return 2
    elsif x == "c"
        return 3
    elsif x == "d"
        return 4
    elsif x == "e"
        return 5
    elsif x == "f"
        return 6
    elsif x == "g"
        return 7
    else
        return 8
    end
end

def simple(h,v)
    step = []
    if h > 0 then
        step += ["R"]*h
    elsif h < 0 then
        step += ["L"]*h.abs
    elsif v > 0
        step += ["U"]*v
    elsif v < 0
        step += ["D"]*v.abs
    end
    return step
end

k = gets.chomp
t = gets.chomp

step = []

h = num(t[0]) - num(k[0])
v = t[1].to_i - k[1].to_i

d = (0-v).abs < (0-h).abs ? v : h

if d != 0 then
    if h == d then
        if h > 0 && v > 0 then
            step += ["RU"]*h
        elsif h > 0 && v < 0 then
            step += ["RD"]*h
        elsif h < 0 && v > 0 then
            step += ["LU"]*h.abs
        else
            step += ["LD"]*h.abs
        end
        if v > 0 then
            v -= h.abs
        else
            v += h.abs
        end
        h = 0
    else
        if h > 0 && v > 0 then
            step += ["RU"]*v
        elsif h > 0 && v < 0 then
            step += ["RD"]*v.abs
        elsif h < 0 && v > 0 then
            step += ["LU"]*v
        else
            step += ["LD"]*v.abs
        end
        if h > 0 then
            h -= v.abs
        else
            h += v.abs
        end
        v = 0
    end
end

step += simple(h,v)

puts step.size
step.size.times do |i|
    puts step[i]
end

s,t = readlines.join.split
sx,sy = s[0].ord - 'a'.ord, s[1].to_i-1
gx,gy = t[0].ord - 'a'.ord, t[1].to_i-1
a=[""]*9
f = lambda{|r,c| r.times{|i| a[i] += c}}
f.call(gx-sx,'R')
f.call(sx-gx,'L')
f.call(sy-gy,'D')
f.call(gy-sy,'U')
a.select!{|i| i != ""}
puts a.size
puts a

# require 'pry-byebug'
file = File.exist?('in.in') ? File.new('in.in','r') : STDIN

DX = [0, 1, 0, -1, 1, -1, 1, -1]
DY = [1, 0, -1, 0, 1, -1, -1, 1]
MOV = ["R", "D", "L", "U", "RD", "LU", "LD", "RU"]

def inside?(i, j, grid)
  i>=0 && i<= grid.size-1 && j>=0 && j <=grid[0].size-1
end

map = {"a"=> 0, "b"=> 1, "c"=> 2, "d"=> 3, "e"=> 4,"f"=> 5, "g"=> 6, "h" => 7}

s2,s1 = file.gets.chomp.split('')
t2,t1 = file.gets.chomp.split('')

s1 = (s1.to_i-1-7).abs
s2 = map[s2]
t1 = (t1.to_i-1-7).abs
t2 = map[t2]

# puts "#{s1}#{s2}"
# puts "#{t1}#{t2}"

grid = Array.new(8) { Array.new(8) }
dist = Array.new(8) { Array.new(8, 100) }
queue = [[s1, s2]]
dist[s1][s2]=0
grid[s1][s2]=[]

while(queue.size != 0)
  x, y  = queue.shift
  8.times do |i|
    new_x = x+DX[i]
    new_y = y+DY[i]
    if inside?(new_x, new_y, grid) && dist[new_x][new_y]==100

      if dist[x][y]+1 < dist[new_x][new_y]
        dist[new_x][new_y]  = dist[x][y]+1
        grid[new_x][new_y] = grid[x][y] + [MOV[i]]
      end

      # dist[new_x][new_y] = [dist[new_x][new_y],dist[x][y]+1].min
      break if new_x == t1 && new_y == t2
      # binding.pry if dist[new_x][new_y] == 7
      queue << [new_x, new_y]
    end
  end
end
puts dist[t1][t2]
grid[t1][t2].each do |e|
  puts e
end

s,t = readlines.join.split
sx,sy = s[0].ord - 'a'.ord, s[1].to_i-1
gx,gy = t[0].ord - 'a'.ord, t[1].to_i-1

dx    = (sx-gx).abs
dy    = (sy-gy).abs
xchar = sx < gx ? 'R' : 'L'
ychar = sy < gy ? 'U' : 'D'

ans = []
cnt = 0
while dx > 0 && dy > 0
  ans << (xchar+ychar)
  dx -= 1
  dy -= 1
end

while dx > 0
  ans << xchar
  dx -= 1
end

while dy > 0
  ans << ychar
  dy -= 1
end

puts ans.size
puts ans

start = gets
start_x = start[0].ord - 97
start_y = start[1].to_i - 1

finish = gets
finish_x = finish[0].ord - 97
finish_y = finish[1].to_i - 1

result = []

if start_x < finish_x
	# go right
	(finish_x - start_x).times do
		result << ["R"]
	end
else
	# go left
	(start_x - finish_x).times do
		result << ["L"]
	end
end

if start_y < finish_y
	# go up
	(finish_y - start_y).times do |index|
		if result[index].nil?
			result << ["U"]
		else
			result[index][0]<< "U"
		end
	end
else
	# go down
	(start_y - finish_y).times do |index|
		if result[index].nil?
			result << ["D"]
		else
			result[index][0]<< "D"
		end
	end
end

puts result.length
puts result

source = gets.chomp!
destination = gets.chomp!
h = []
v = []
while true
	if source[0] < destination[0]
		h << 'R'
		source[0] = (source[0].ord + 1).chr
	elsif source[0] > destination[0]
		h << 'L'
		source[0] = (source[0].ord - 1).chr
	else
		h << ''
	end

	if source[1] < destination[1]
		v << 'U'
		source[1] = (source[1].to_i + 1).to_s
	elsif source[1] > destination[1]
		v << 'D'
		source[1] = (source[1].to_i - 1).to_s
	else
		v << ''
	end

	break if source == destination

end
if h.size == 1 && v.size == 1 && h[0] == '' && v[0] == ''
	puts 0
else
	puts h.size
	h.each_index {|index| puts h[index] + v[index]}
end

#!usr/bin/env ruby

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

start = gets.chomp
finish = gets.chomp
x1 = start[0]
x2 = finish[0]

y1 = start[1]
y2 = finish[1]

count = 0
moves = []

while !(x1 == x2 && y1 == y2) do
 move = ""

 if x1 < x2
  move += "R"
  x1 = x1.next
 elsif x1 > x2
  move += "L"
  x1 = (x1.ord - 1).chr
 end

 if y1 < y2
  move += "U"
  y1 = y1.next
 elsif y1 > y2
  move += "D"
  y1 = (y1.ord - 1).chr
 end
 count += 1
 moves << move
 end

puts count
moves.each { |mv| puts mv }

s = STDIN.readline
t = STDIN.readline

print [(s[0].ord-t[0].ord).abs,(s[1].ord-t[1].ord).abs].max
print ?\n

while s != t ;
	if s[0] < t[0] ;
		print ?R
		s[0] = (s[0].ord+1).chr
	elsif s[0] > t[0] ;
		print ?L
		s[0] = (s[0].ord-1).chr
	end
	if s[1] < t[1] ;
		print ?U
		s[1] = (s[1].ord+1).chr
	elsif s[1] > t[1] ;
		print ?D
		s[1] = (s[1].ord-1).chr
	end
	print ?\n
end

s=gets.split[0].bytes.to_a
t=gets.split[0].bytes.to_a
sx=s[0]-97
sy=56-s[1]
tx=t[0]-97
ty=56-t[1]
puts [(sx-tx).abs,(sy-ty).abs].max
loop do
        if sx==tx && sy==ty then
                break
        end
        if sx<tx then
                print "R"
                sx+=1
        elsif sx>tx then
                print "L"
                sx-=1
        end
        if sy<ty then
                print "D"
                sy+=1
        elsif sy>ty then
                sy-=1
                print "U"
        end
        puts
end

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

class Node
  attr_accessor :distance, :visited, :prev, :x, :y, :cost

  def initialize(x=0, y=0, cost=1)
    @distance = Float::INFINITY
    @visited = false
    @prev = nil
    @x = x
    @y = y
    @cost = cost
  end
end

def make_graph(x, y)
  (0...x).map { |x| (0...y).map { |y| Node.new(x, y) } }
end

def find_unvisited(graph)
  graph.flatten { |y| y.visited == false }
end

def min(unvisited, graph)
  min = unvisited.map { |node| node.distance }.each_with_index.min
  unvisited[min[1]]
end

def in_range(x, y, graph)
  x >= 0 && y >= 0 && x < graph.size && y < graph[0].size && !graph[x][y].visited
end

def get_neighbors(x, y, graph)
  l = [x-1, y]
  r = [x+1, y]
  t = [x, y+1]
  b = [x, y-1]
  lt = [x-1, y+1]
  rt = [x+1, y+1]
  rb = [x+1, y-1]
  lb = [x-1, y-1]

  [l,r,t,b,lt,rt,rb,lb].select { |neighbor| in_range(neighbor[0], neighbor[1], graph) }
end

def visit(node, graph)
  neighbors = get_neighbors(node.x, node.y, graph)
  neighbors.each do |n|
    neighbor = graph[n[0]][n[1]]
    neighbor.visited = true
    dist = node.distance + neighbor.cost
    if dist < neighbor.distance
      neighbor.distance = dist
      neighbor.prev = node
    end
  end
end

def dijkstra(graph, source, target)
  graph[source[0]][source[1]].distance = 0
  unvisited = find_unvisited(graph)

  while unvisited.any?
    current_node = min(unvisited, graph)
    return current_node if current_node.x == target[0] && current_node.y == target[1]
    unvisited.delete(current_node)
    visit(current_node, graph)
  end
end

def convert_source(coord)
  [coord[0].ord - 96 - 1, Integer(coord[1]) -1]
end

def to_directions(from, to)
  return if to == nil
  str = ""
  if to.x > from.x
    str << "R"
  end
  if to.x < from.x
    str << "L"
  end
  if to.y > from.y
    str << "U"
  end
  if to.y < from.y
    str << "D"
  end
  str
end

def get_answer_nodes(root)
  nodes = []
  current_node = root
  while !current_node.nil?
    nodes << current_node
    current_node = current_node.prev
  end
  nodes.reverse
end

def format_answer(answer)
  nodes = get_answer_nodes(answer)
  directions = [nodes.size-1]
  nodes.each_with_index do |node, i|
    directions << to_directions(nodes[i], nodes[i+1])
  end
  directions
end

def solve
  graph = make_graph(8, 8)
  source = gets
  target = gets
  answer = dijkstra(graph, convert_source(source.chomp), convert_source(target.chomp))
  puts format_answer(answer).join("\n")
end

solve()

s,t = gets.strip.bytes.to_a, gets.strip.bytes.to_a
moves = []
while s != t
  move = ""
  if s[0] < t[0]
    s[0] += 1
    move += "R"
  elsif s[0] > t[0]
    s[0] -= 1
    move += "L"
  end
  if s[1] < t[1]
    s[1] += 1
    move += "U"
  elsif s[1] > t[1]
    s[1] -= 1
    move += "D"
  end
  moves << move
end

puts moves.size
for s in moves do
  puts s
end

coord_src = gets
coord_dest = gets

coord_src_x = 1 + coord_src[0].ord - 'a'.ord
coord_src_y = coord_src[1].to_i
coord_dest_x = 1 + coord_dest[0].ord - 'a'.ord
coord_dest_y = coord_dest[1].to_i

#puts coord_src_x.to_s + " " + coord_src_y.to_s
#puts coord_dest_x.to_s + " " + coord_dest_y.to_s

moves = []

# Firstly, move diagonally in the correct direction.
while (coord_src_x != coord_dest_x && coord_src_y != coord_dest_y) do
  if coord_src_x > coord_dest_x
    coord_src_x -= 1
    if coord_src_y > coord_dest_y
      moves.push("LD")
      coord_src_y -= 1
    else
      moves.push("LU")
      coord_src_y += 1
    end
  else
   coord_src_x += 1
    if coord_src_y > coord_dest_y
      moves.push("RD")
      coord_src_y -= 1
    else
      moves.push("RU")
      coord_src_y += 1
    end
  end
end

# Now it is just a straightaway
if(coord_src_x > coord_dest_x)
  (coord_src_x - coord_dest_x).times { moves.push("L") }
elsif (coord_src_x < coord_dest_x)
  (coord_dest_x - coord_src_x).times { moves.push("R") }

elsif(coord_src_y > coord_dest_y)
  (coord_src_y - coord_dest_y).times { moves.push("D") }
elsif (coord_src_y < coord_dest_y)
  (coord_dest_y - coord_src_y).times { moves.push("U") }
end

puts moves.size
moves.each { |move| puts move }

input = STDIN.read.split("\n")
a, b = input[0].split(''), input[1].split('')
a[1], b[1] = a[1].to_i, b[1].to_i

if a == b
	STDOUT.print 0
	exit
end

if a[0] > b[0]
	x_dir = "L"
elsif a[0] < b[0]
	x_dir = "R"
end

if a[1] > b[1]
	y_dir = "D"
elsif a[1] < b[1]
	y_dir = "U"
end

str = ""
count = 0

while true do

	if a[0] != b[0]
		a[0].next! if x_dir == "R"
		a[0] = (a[0].ord - 1).chr if x_dir == "L"
		str << x_dir
	end

	if a[1] != b[1]
		a[1] += 1 if y_dir == "U"
		a[1] -= 1 if y_dir == "D"
		str << y_dir
	end

	count += 1
	str << "\n"

	break if a == b

end

STDOUT.print count, "\n", str

input = STDIN.read.split("\n")
a, b = input[0].split(''), input[1].split('')
a[0], b[0], a[1], b[1] = a[0].ord, b[0].ord, a[1].to_i, b[1].to_i

if a == b
	STDOUT.print 0
	exit
end

x_dir = a[0] > b[0] ? "L" : "R"
y_dir = a[1] > b[1] ? "D" : "U"

str, count = '', 0

loop do

	if a[0] != b[0]
		x_dir == "R" ? a[0] += 1 : a[0] -= 1
		str << x_dir
	end

	if a[1] != b[1]
		y_dir == "U" ? a[1] += 1 : a[1] -= 1
		str << y_dir
	end

	count += 1
	str << "\n"

	break if a == b

end

STDOUT.print count, "\n", str

input = STDIN.read.split("\n")
a, b = input[0].split(''), input[1].split('')
a[1], b[1] = a[1].to_i, b[1].to_i

if a == b
	STDOUT.print 0
	exit
end

x_dir = a[0] > b[0] ? "L" : "R"
y_dir = a[1] > b[1] ? "D" : "U"

str, count = '', 0

while true do

	if a[0] != b[0]
		a[0] = x_dir == "R" ? a[0].next : (a[0].ord - 1).chr
		str << x_dir
	end

	if a[1] != b[1]
		y_dir == "U" ? a[1] += 1 : a[1] -= 1
		str << y_dir
	end

	count += 1
	str << "\n"

	break if a == b

end

STDOUT.print count, "\n", str

# require 'pry-byebug'
file = File.exist?('in.in') ? File.new('in.in','r') : STDIN

DX = [0, 1, 0, -1, 1, -1, 1, -1]
DY = [1, 0, -1, 0, 1, -1, -1, 1]
MOV = ["R", "D", "L", "U", "RD", "LU", "LD", "RU"]

def inside?(i, j, grid)
  i>=0 && i<= grid.size-1 && j>=0 && j <=grid[0].size-1
end

map = {"a"=> 0, "b"=> 1, "c"=> 2, "d"=> 3, "e"=> 4,"f"=> 5, "g"=> 6, "h" => 7}

s1,s2 = file.gets.chomp.split('')
t1,t2 = file.gets.chomp.split('')

return puts 0 if s1==t1 && s2==t2

s1 = map[s1]
s2 = (s2.to_i-1-7).abs
t1 = map[t1]
t2 = (t2.to_i-1-7).abs

# puts "#{s1}#{s2}"
# puts "#{t1}#{t2}"

grid = Array.new(8) { Array.new(8) }
dist = Array.new(8) { Array.new(8, 100) }
queue = [[s1, s2]]
dist[s1][s2]=0
grid[s1][s2]=[]

while(queue.size != 0)
  x, y  = queue.shift
  8.times do |i|
    new_x = x+DX[i]
    new_y = y+DY[i]
    if inside?(new_x, new_y, grid) && dist[new_x][new_y]==100

      if dist[x][y]+1 < dist[new_x][new_y]
        dist[new_x][new_y]  = dist[x][y]+1
        grid[new_x][new_y] = grid[x][y] + [MOV[i]]
      end

      # dist[new_x][new_y] = [dist[new_x][new_y],dist[x][y]+1].min
      break if new_x == t1 && new_y == t2
      # binding.pry if dist[new_x][new_y] == 7
      queue << [new_x, new_y]
    end
  end
end
puts dist[t1][t2]
grid[t1][t2].each do |e|
  puts e
end

#!usr/bin/env ruby

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

start = gets.chomp
finish = gets.chomp

while ! start.eql? finish do
 move = ""

 if start[0] < finish[0]
  move += "U"
  start[0] = start[0].next
 elsif start[0] > finish[0]
  move += "D"
  start[0] = (start[0].ord - 1).chr
 end

 if start[1] < finish[1]
  move += "R"
  start[1] = start[1].next
 elsif start[1] > finish[1]
  move += "L"
  start[1] = (start[1].ord - 1).chr
 end

 puts move
end

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

class Node
  attr_accessor :distance, :visited, :prev, :x, :y, :cost

  def initialize(x=0, y=0, cost=1)
    @distance = Float::INFINITY
    @visited = false
    @prev = nil
    @x = x
    @y = y
    @cost = cost
  end
end

def make_graph(x, y)
  (0...x).map { |x| (0...y).map { |y| Node.new(x, y) } }
end

def find_unvisited(graph)
  graph.flatten { |y| y.visited == false }
end

def min(unvisited, graph)
  min = unvisited.map { |node| node.distance }.each_with_index.min
  unvisited[min[1]]
end

def in_range(x, y, graph)
  x >= 0 && y >= 0 && x < graph.size && y < graph[0].size && !graph[x][y].visited
end

def get_neighbors(x, y, graph)
  l = [x-1, y]
  r = [x+1, y]
  t = [x, y+1]
  b = [x, y-1]
  lt = [x-1, y+1]
  rt = [x+1, y+1]
  rb = [x+1, y-1]
  lb = [x-1, y-1]

  [l,r,t,b,lt,rt,rb,lb].select { |neighbor| in_range(neighbor[0], neighbor[1], graph) }
end

def visit(node, graph)
  neighbors = get_neighbors(node.x, node.y, graph)
  neighbors.each do |n|
    neighbor = graph[n[0]][n[1]]
    neighbor.visited = true
    dist = node.distance + neighbor.cost
    if dist < neighbor.distance
      neighbor.distance = dist
      neighbor.prev = node
    end
  end
end

def dijkstra(graph, source, target)
  graph[source[0]][source[1]].distance = 0
  unvisited = find_unvisited(graph)

  while unvisited.any?
    current_node = min(unvisited, graph)
    return current_node if current_node.x == target[0] && current_node.y == target[1]
    unvisited.delete(current_node)
    visit(current_node, graph)
  end
end

def convert_source(coord)
  [coord[0].ord - 96 - 1, Integer(coord[1]) -1]
end

def to_directions(from, to)
  return if to == nil
  str = ""
  if to.x > from.x
    str << "R"
  end
  if to.y > from.y
    str << "U"
  end
  if to.y < from.y
    str << "D"
  end
  if to.x < from.x
    str << "L"
  end
  str
end

def get_answer_nodes(root)
  nodes = []
  current_node = root
  while !current_node.nil?
    nodes << current_node
    current_node = current_node.prev
  end
  nodes.reverse
end

def format_answer(answer)
  nodes = get_answer_nodes(answer)
  directions = [nodes.size-1]
  nodes.each_with_index do |node, i|
    directions << to_directions(nodes[i], nodes[i+1])
  end
  directions
end

def solve
  graph = make_graph(8, 8)
  source = gets
  target = gets
  answer = dijkstra(graph, convert_source(source.chomp), convert_source(target.chomp))
  puts format_answer(answer).join("\n")
end

solve()

s = gets
t = gets
sx = s[0..0].ord
sy = s[1..1].to_i
tx = t[0..0].ord
ty = t[1..1].to_i
dx = sx-tx
dy = sy-ty
step = [dx.abs,dy.abs].max
puts step
step.times do
  if dx<0
    print "R"
    dx += 1
  elsif dx>0
    print "L"
    dx -= 1
  end
  if dy<0
    print "U"
    dy += 1
  elsif dy>0
    print "D"
    dy += 1
  end
  puts
end

class King
  def initialize(s, t)
    @start = s
    @end = t
  end

  def get_path
    result = []
    horizontal = (@start[0] == @end[0])
    vertical = (@start[1] == @end[1])
    if @start == @end
      result << 0
    elsif horizontal
      result = [steps_x.abs] + [direction.last]*steps_x.abs
    elsif vertical
      result = [steps_y.abs] + [direction.first]*steps_y.abs
    else
      current = @start
      steps = 0
      until horizontal || vertical
        current = move_diag(current)
        horizontal = (current[0] == @end[0])
        vertical = (current[1] == @end[1])
        result << direction.join
        steps += 1
      end
      if vertical
        current_steps = (current[0].ord.to_i - @end[0].ord.to_i).abs
        result += [direction.last]*current_steps
        steps += current_steps
      elsif horizontal
        current_steps = (current[1].to_i - @end[1].to_i).abs
        result += [direction.first]*current_steps
        steps += current_steps
      end
      result.unshift(steps)
    end
    result
  end

  def move_diag(position)
    x_inc = steps_x == 0 ? 0 : steps_x/steps_x.abs
    y_inc = steps_y == 0 ? 0 : steps_y/steps_y.abs
    [(position[0].ord+x_inc).chr, (position[1].to_i + y_inc)].join
  end

  def direction
    [direction_y, direction_x]
  end

  def direction_x
    steps_x > 0 ? 'D' : 'U'
  end

  def direction_y
    steps_y > 0 ? 'L' : 'R'
  end

  def steps_x
    @start[1].to_i - @end[1].to_i
  end

  def steps_y
    @start[0].ord.to_i - @end[0].ord.to_i
  end
end

s, t = [gets.chomp, gets.chomp]
game = King.new(s, t)
puts game.get_path

class King
  def initialize(s, t)
    @start = s
    @end = t
  end

  def get_path
    result = []
    horizontal = (@start[0] == @end[0])
    vertical = (@start[1] == @end[1])
    if @start == @end
      result << 0
    elsif horizontal
      result = [steps_x] + [direction.last]*steps_x.abs
    elsif vertical
      result = [steps_y] + [direction.first]*steps_y.abs
    else
      current = @start
      steps = 0
      until horizontal || vertical
        current = move_diag(current)
        horizontal = (current[0] == @end[0])
        vertical = (current[1] == @end[1])
        result << direction.join
        steps += 1
      end
      if vertical
        current_steps = (current[0].ord.to_i - @end[0].ord.to_i).abs
        result += [direction.last]*current_steps
        steps += current_steps
      elsif horizontal
        current_steps = (current[1].to_i - @end[1].to_i).abs
        result += [direction.first]*current_steps
        steps += current_steps
      end
      result.unshift(steps)
    end
    result
  end

  def move_diag(position)
    x_inc = steps_x == 0 ? 0 : steps_x/steps_x.abs
    y_inc = steps_y == 0 ? 0 : steps_y/steps_y.abs
    [(position[0].ord+x_inc).chr, (position[1].to_i + y_inc)].join
  end

  def direction
    [direction_y, direction_x]
  end

  def direction_x
    steps_x > 0 ? 'D' : 'U'
  end

  def direction_y
    steps_y > 0 ? 'L' : 'R'
  end

  def steps_x
    @start[1].to_i - @end[1].to_i
  end

  def steps_y
    @start[0].ord.to_i - @end[0].ord.to_i
  end
end

s, t = [gets.chomp, gets.chomp]
game = King.new(s, t)
puts game.get_path

class King
  def initialize(s, t)
    @start = s
    @end = t
  end

  def get_path
    result = []
    horizontal = (@start[0] == @end[0])
    vertical = (@start[1] == @end[1])
    if @start == @end
      result << 0
    elsif horizontal
      result = [steps_x] + [direction.first]*steps_x.abs
    elsif vertical
      result = [steps_y] + [direction.last]*steps_y.abs
    else
      current = @start
      steps = 0
      until horizontal || vertical
        current = move_diag(current)
        horizontal = (current[0] == @end[0])
        vertical = (current[1] == @end[1])
        result << direction.join
        steps += 1
      end
      if vertical
        current_steps = (current[0].ord.to_i - @end[0].ord.to_i).abs
        result += [direction.last]*current_steps
        steps += current_steps
      elsif horizontal
        current_steps = (current[1].to_i - @end[1].to_i).abs
        result += [direction.first]*current_steps
        steps += current_steps
      end
      result.unshift(steps)
    end
    result
  end

  def move_diag(position)
    x_inc = steps_x == 0 ? 0 : steps_x/steps_x.abs
    y_inc = steps_y == 0 ? 0 : steps_y/steps_y.abs
    [(position[0].ord+x_inc).chr, (position[1].to_i + y_inc)].join
  end

  def direction
    [direction_y, direction_x]
  end

  def direction_x
    steps_x > 0 ? 'D' : 'U'
  end

  def direction_y
    steps_y > 0 ? 'L' : 'R'
  end

  def steps_x
    @start[1].to_i - @end[1].to_i
  end

  def steps_y
    @start[0].ord.to_i - @end[0].ord.to_i
  end
end

s, t = [gets.chomp, gets.chomp]
game = King.new(s, t)
puts game.get_path

s1 = gets
s2 = gets
dst1 = s2[0].ord - s1[0].ord
dst2 = s2[1].to_i - s1[1].to_i

puts [dst2.abs, dst1.abs].max
while dst2 != 0 and dst1 != 0 do
    if dst1 > 0 then
        printf "R"
        dst1 -= 1
    end
    if dst1 < 0 then
        printf "L"
        dst1 += 1
    end

    if dst2 > 0 then
        printf "U"
        dst2 -= 1
    end
    if dst2 < 0 then
        printf "D"
        dst2 += 1
    end
    puts
end

start = gets().chomp!
finish =  gets().chomp!
LETTERS = ["a", "b", "c", "d", "e", "f", "g", "h"]
h_distance, v_distance = [LETTERS.index(finish[0,1]) - LETTERS.index(start[0,1]), finish[1,1].to_i - start[1,1].to_i]
moves = Array.new(7){""}
h_distance.abs().times {
|i|
  h_distance > 0 ? moves[i] << "R" : moves[i] << "L"
}
v_distance.abs().times {
|i|
  v_distance > 0 ? moves[i] << "U" : moves[i] << "D"
}
moves.select(){|elem| elem != ""}
puts moves.length, moves

s,t = readlines.join.split
sx,sy = s[0].ord - 'a'.ord, s[1].to_i-1
gx,gy = t[0].ord - 'a'.ord, t[1].to_i-1
a=[""]*9
f = lambda{|r,c| r.times{|i| a[i] += c}}
f.call(sx-gx,'R')
f.call(gx-sx,'L')
f.call(sy-gy,'D')
f.call(gy-sy,'U')
a.select!{|i| i != ""}
puts a.size
puts a

a, b = gets.chop.split(''), gets.chop.split('')
a[1], b[1] = a[1].to_i, b[1].to_i

if a[0] > b[0]
	x_dir = "L"
elsif a[0] < b[0]
	x_dir = "R"
end

if a[1] > b[1]
	y_dir = "D"
elsif a[1] < b[1]
	y_dir = "U"
end

str = ""
count = 0

while true do

	if a[0] != b[0]
		a[0].next! if x_dir == "R"
		a[0].prev! if x_dir == "L"
		str << x_dir
	end

	if a[1] != b[1]
		a[1] += 1 if y_dir == "U"
		a[1] -= 1 if y_dir == "D"
		str << y_dir
	end

	count += 1
	str << "\n"

	break if a == b

end

STDOUT.print count, "\n", str


#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

hx = {}
hy = {}
a = inp
b = inp
c = inp
x = [a[0],a[2],b[0],b[2],c[0],c[2]].sort
y = [a[1],a[3],b[1],b[3],c[1],c[3]].sort
x.each.with_index do |d,i|
  hx[d] = i
end
y.each.with_index do |d,i|
  hy[d] = i
end
t = na2(x.size,y.size,false)
(hx[a[0]]...hx[a[2]]).each do |x|
  (hy[a[1]]...hy[a[3]]).each do |y|
    t[x][y] = true
  end
end
(hx[b[0]]...hx[b[2]]).each do |x|
  (hy[b[1]]...hy[b[3]]).each do |y|
    t[x][y] = false
  end
end
(hx[c[0]]...hx[c[2]]).each do |x|
  (hy[c[1]]...hy[c[3]]).each do |y|
    t[x][y] = false
  end
end

puts (t.flatten.include?(true))? "YES" : "NO"

MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

#def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end
def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
x1,y1,x2,y2=gsmi
x3,y3,x4,y4=gsmi
x5,y5,x6,y6=gsmi

# full cover
if (x3<=x1&&y3<=y1&&x4>=x2&&y4>=y2)||(x5<=x1&&y5<=y1&&x6>=x2&&y6>=y2)
  putsend('NO')
end
# half cover
# たて
if (y3<=y1&&y4>=y2 &&y5<=y1&&y6>=y2) && ((x5<=x2&&x6>=x2&&x3<=x1&&x4>=x1&&x4>=x5)||(x3<=x2&&x4>=x2&&x5<=x1&&x6>=x1&&x6>=x3))
  putsend('NO')
end
# よこ
if (x3<=x1&&x4>=x2 &&x5<=x1&&x6>=x2) && ((y5<=y2&&y6>=y2&&y3<=y1&&y4>=y1&&y4>=y5)||(y3<=y2&&y4>=y2&&y5<=y1&&y6>=y1&&y6>=y3))
  putsend('NO')
end

putsend('YES')

MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

#def bs(ar,eq,n) en=(eq==1 ? :>= : :>); ar.bsearch_index{|x|x.send(en,n)} end
def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
x1,y1,x2,y2=gsmi
x3,y3,x4,y4=gsmi
x5,y5,x6,y6=gsmi

# full cover
if (x3<=x1&&y3<=y1&&x4>=x2&&y4>=y2)||(x5<=x1&&y5<=y1&&x6>=x2&&y6>=y2)
  putsend('NO')
end
# half cover
# たて
if (y3<=y1&&y4>=y2 &&y5<=y1&&y6>=y2) && ((x5<=x2&&x6>=x2&&x3<=x1&&x4>=x1&&x4>=x5)||(x3<=x2&&x4>=x2&&x5<=x1&&x6>=x1&&x6>=x4))
  putsend('NO')
end
# よこ
if (x3<=x1&&x4>=x2 &&x5<=x1&&x6>=x2) && ((y5<=y2&&y6>=y2&&y3<=y1&&y4>=y1&&y4>=y5)||(y3<=y2&&y4>=y2&&y5<=y1&&y6>=y1&&y6>=y4))
  putsend('NO')
end

putsend('YES')


n, k = gets.strip.split.map(&:to_i)
remainder = n / k
ans = k * remainder + k
puts ans

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

x = (n/k).to_i

puts (x+1)*k

n,k = gets.split(' ').map(&:to_i)
puts ((n/k) * k) + k

# cook your code here

a1,b1=gets.chomp.split

n = a1.to_i
k = b1.to_i

n = n + k - n%k

puts n

n, k = gets.strip.split.map(&:to_i)
mod = n % k
remainder = 0
remainder = n / k if mod != 0
remainder = mod if mod ==
ans = n + remainder
ans += k if remainder == 0
puts ans

n, k = gets.strip.split.map(&:to_i)
mod = n % k
remainder = mod
remainder = n / k if mod != 0
ans = n + remainder
ans += k if remainder == 0
puts ans