n, k = gets.split.map(&:to_i)
s = gets.chomp
l = 0;
r = 0;

for i in 0..(n-1)
  c = 0;
  j = i;
  while j < n && s[j] == 'N' do
   c = c + 1;
   j = j + 1;
  end
  if (l < c)
  	l = c;
  end
end

for i in 0..(n-1)
  c = 0;
  j = i;
  while j < n && s[j] != 'Y' do
   c = c + 1;
   j = j + 1;
  end
  if (r < c)
  	r = c;
  end
end

if (l <= k && k <= r)
	puts "YES"
else
	puts "NO"
end


#!/usr/bin/env ruby

remix = gets

wubWord = "WUB"

if remix != remix.upcase || remix.length > 200
	abort("Incorrent input string")
end

while remix.include? wubWord
	#remix[wubWord] = " "
	remix = remix.sub("WUB", " ")
end

splitted = remix.split(" ")
original = splitted.join(" ")

puts original


n,k,*a=$<.read.split.map &to_i
p a.count{|e|e<=k}


n,k,*a=$<.read.split.map &:to_i
p a.all?{|e|e<=k}?n:a.index{|e|e>k}+(n-a.rindex{|e|e>k})


m, n = STDIN.read.split.map &:to_i

if n.odd?
  c  = (m * (n - 1)) / 2
  c += (m - 1) / 2
else
  c  = m * n / 2
end

print c


def adjust_number(number)
    if(number % 3 == 0)
        find_number(number)
    elsif
        find_number(number + 1)
    else
        find_number(number + 2)
    end
end
def find_number(number)
    loop do
        if (sum_of_digit(number) % 4 == 0)
            puts number
            break
        end
        number += 3
    end
end
def sum_of_digit(number)
    @sum = 0
    while number > 0
        @sum += (number)%10
        number /= 10
    end
    return @sum
end
number = gets.chomp.to_i
adjust_number(number)


n,m,k,*a=$<.read.split.map(&:to_i)
b=a.map.with_index{|e,i|0<e&&e<=k ? i : nil}.compact
p 10*b.map{|i|(i-m).abs}.min


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

class Grid
  def initialize(gridStr)
    @numX = gridStr.count('X')
    @num0 = gridStr.count('0')
    @numP = gridStr.count('.')
    split = gridStr.split("\n")
    @lines = split.map { |line| line.split("") }
    @num_winning_rows = how_many_in_a_row?
  end

  def analyze
    return "illegal" if is_illegal?
    return "draw" if is_draw?
    return "the second player won" if second_won?
    return "the first player won" if first_won?
    return "second" if second_turn?
    return "first" if first_turn?
  end

  def is_illegal?
    return true if @num0 > @numX
    return true if @numX > @num0 + 1
    return true unless @numX + @num0 + @numP == 9
    return true if too_many_wins?
  end

  def is_draw?
    return false if @num_winning_rows > 0
    return true if @numX + @num0 == 9
  end

  def second_won?
    return false if too_many_wins?
    return @ohWins
  end

  def first_won?
    return false if too_many_wins?
    return @xWins
  end

  def second_turn?
    @numX == @num0 + 1
  end

  def first_turn?
    @numX == @num0
  end

  def how_many_in_a_row?
    num = 0
    (0..2).each { |col| num += 1 if horizontal_win(col) }
    (0..2).each { |row| num += 1 if vertical_win(row) }
    num += 1 if left_right_win
    num += 1 if right_left_win
    num
  end

  def horizontal_win(xPos)
    return false unless @lines[xPos][0] == "X" || @lines[xPos][0] == "0"
    if @lines[xPos][0] == @lines[xPos][1] && @lines[xPos][1] == @lines[xPos][2]
      set_winner(@lines[xPos][0])
      @horizontal_winner = true
      return true
    end
  end

  def vertical_win(yPos)
    return false unless @lines[0][yPos] == "X" || @lines[0][yPos] == "0"
    if @lines[0][yPos] == @lines[1][yPos] && @lines[1][yPos] == @lines[2][yPos]
      set_winner(@lines[0][yPos])
      @vertical_winner = true
      return true
    end
  end

  def left_right_win
    return false unless @lines[0][0] == "X" || @lines[0][0] == "0"
    if @lines[0][0] == @lines[1][1] && @lines[1][1] == @lines[2][2]
      set_winner(@lines[0][0])
      @diag_winner = true
      return true
    end
  end

  def right_left_win
    return false unless @lines[2][0] == "X" || @lines[2][0] == "0"
    if @lines[2][0] == @lines[1][1] && @lines[1][1] == @lines[0][2]
      set_winner(@lines[2][0])
      @diag_winner = true
      return true
    end
  end

  def set_winner(player)
    @xWins = true if player == "X"
    @ohWins = true if player == "0"
  end

  def too_many_wins?
    return false if @num_winning_rows == 1 || @num_winning_rows == 0
    return true if @num_winning_rows > 2
    winner = @xWins ? "X" : "0"
    return true if @horizontal_winner && !@diag_winner && !@vertical_winner
    return true if @vertical_winner && !@diag_winner && !@horizontal_winner
    return false
  end
end

def solve
  l1 = gets.chomp
  l2 = gets.chomp
  l3 = gets.chomp
  grid = Grid.new([l1, l2, l3].join("\n"))
  puts grid.analyze()
end

solve()


board = Array.new
3.times do
  board << gets.split(//)
end
fl = false
sl = false
fc = 0
sc = 0
0.upto(2) do |i|
  0.upto(2) do |j|
    if board[i][j]=="X"
      fc+=1
    elsif board[i][j]=="0"
      sc+=1
    end
  end
  if board[i][0]==board[i][1] and board[i][1]==board[i][2]
    if board[i][0]=="X"
      fl = true
    elsif board[i][0]=="0"
      sl = true
    end
  end
  if board[0][i]==board[1][i] and board[1][i]==board[2][i]
    if board[0][i]=="X"
      fl = true
    elsif board[0][i]=="0"
      sl = true
    end
  end
end
if board[0][0]==board[1][1] and board[1][1]==board[2][2]
  if board[0][0]=="X"
    fl = true
  elsif board[0][0]=="0"
    sl = true
  end
end
if fc==sc
  if fl
    puts "illegal"
  elsif sl
    puts "the second player won"
  else
    puts "first"
  end
elsif fc==sc+1
  if sl
    puts "illegal"
  elsif fl
    puts "the first player won"
  else
    if fc+sc==9
      puts "draw"
    else
      puts "second"
    end
  end
else
  puts "illegal"
end


#!/usr/bin/ruby
a=0;b=0
$<.read.split(')').each{|e|
	x,y=e.split('(')
	x.scan(/[A-Za-z]+/).each{|f|a=[a,f.size].max}
	b+=(y||'').scan(/[A-Za-z]+/).size
}
puts [a,b]*' '


def main
  n = gets
  words = gets
  in_brackets = /\([^)]+\)/
  out_brackets = /(?:\A|\))[^\(]+\(/
  word_gex = /[A-Za-z]+/
  inner_brackets = words.scan(in_brackets)
  outer_brackets = words.scan(out_brackets)
  inner_words = inner_brackets.map{|s| s.scan(word_gex)}.flatten
  outer_words = outer_brackets.map{|s| s.scan(word_gex)}.flatten
  l = (outer_words.map(&:length).max) || 0
  i = (inner_words.length)
  puts("#{l} #{i}")
end

main


def main
	num = gets.chomp
	hash = {1=>'one',
		2=> 'two',
		3=>'three',
		4=> 'four',
		5=> 'five',
		6=> 'six',
		7=> 'seven',
		8=> 'eight',
		9=> 'nine',
		10=> 'ten',
		11=> 'eleven',
		12=> 'twelve',
		13=> 'thirteen',
		20=> 'twenty',
		30=> 'thirty',
		40=> 'fourty',
		50=> 'fifty',
		60=> 'sixty',
		70=> 'seventy',
		80=> 'eigthty',
		90=> 'ninety'
		}
	if num.to_i == 0
		return 'zero'
	elsif num.to_i == 15
		return 'fifteen'
	elsif num.to_i < 14 || hash.include?(num.to_i)
		return hash[num.to_i]
	elsif num.to_i > 13 && num.to_i < 20
		return hash[num[1].to_i].to_s+'teen'
	elsif num.to_i > 90
		return hash[90] +'-'+hash[num[1].to_i].to_s
	elsif num.to_i > 80
		return hash[80] +'-'+hash[num[1].to_i].to_s
	elsif num.to_i > 70
		return hash[70] +'-'+hash[num[1].to_i].to_s
	elsif num.to_i > 60
		return hash[60] +'-'+hash[num[1].to_i].to_s
	elsif num.to_i > 50
		return hash[50] +'-'+hash[num[1].to_i].to_s
	elsif num.to_i > 40
		return hash[40] +'-'+hash[num[1].to_i].to_s
	elsif num.to_i > 30
		return hash[30] +'-'+hash[num[1].to_i].to_s
	elsif num.to_i > 20
		return hash[20] +'-'+hash[num[1].to_i].to_s
	end
end
main


arraynum1 = ["zero", "one","two","three","four","five","six","seven","eight","nine"]
arraynum2 = [nil , nil ,"twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"]
arraynumtens = ["ten","eleven","twelve","thirteen","fourteen","fifteen","seventeen","eighteen","nineteen"]
numero = gets.chomp
array = numero.split(//)
if numero.to_i >=10 && numero.to_i <20
    print "#{arraynumtens[array[1].to_i]}"

elsif array.length == 2
    if array[1].to_i == 0
        print "#{arraynum2[array[0].to_i]}"
    else
        print "#{arraynum2[array[0].to_i]}-"+"#{arraynum1[array[1].to_i]}"
    end
elsif array.length == 1
    print "#{arraynum1[array[0].to_i]}"
end


n=gets.to_i
a=["zero", "one", "two", "three", "for", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"]
a[20]="twenty"
a[30]="thirty"
a[40]="forty"
a[50]="fifty"
a[60]="sixty"
a[70]="seventy"
a[80]="eighty"
a[90]="ninety"
if n>=0 && n<=20 || n==30 || n==40 || n==50 || n==60 || n==70 || n==80 || n==90
puts a[n]
else
puts a[n-n%10]+'-'+a[n%10]
end


names = ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]
value =gets.chomp
word = gets.chomp
k=0
i=0
p=0
result_word=''
names.each do |name|
  if value.to_i == name.length

    while (i<name.length)
      if (word[i] == name[i])
        k+=1
      end
      i+=1
    end
    i=0
    if k>p
      result_word = name
      p=k
    end
    k=0
  end
end
puts result_word


n = gets.chomp.to_i
name = gets.chomp

letters = name.split("")
check = name.delete '.'

pokemons = ["vaporeon", "jolteon", "flareon", "espeon", "umbreon",
					"leafeon", "glaceon", "sylveon"]

if name.size == n

	pokemons.each do |pokemon|

		p = pokemon.split("")
		c = 0

		(0...p.size).each do |l|
			#puts "#{letters[l]} - #{p[l]} - #{(letters[l] == p[l])}"
			c += (letters[l] == p[l])? 1 : 0
		end

		puts pokemon if c == check.size

	end
else
	puts "Size #{n} doesnt match word '#{name}' (#{name.size})."
end


line = gets
n = line.split(' ')[0].to_i
x = line.split(' ')[1].to_i
y = line.split(' ')[2].to_i
a = (n * y * 1.0 / 100).ceil
puts a - x


I = ->{gets.split.map(&:to_i)}
n, a, b = I[]
c = I[].sort
p c[b] - c[b - 1]


arr = gets.chomp.split(" ")
n = arr[0].to_i
x = arr[1].to_i
y = arr[2].to_i

p = 0

if x > n then
    k = x - n
end
if (x+p)*100 <= y*n and n*y%100 == 0  then
    p = n*y/100 - x + k
elsif (x+p)*100 != y*n
    p = n*y/100 - x + 1 + k
end

puts p


input = ARGV ? $< : File(ARGV[0])

n, x, y = input.gets.split(' ').map &:to_i

needTotal = n * y / 100.0
a = needTotal.ceil - x

puts a


ar = gets.chomp
hs = ar.split(//).group_by{|x| x=~/[[:upper:]]/}
if hs[0].length > hs[nil].length
  puts ar.upcase
else
  puts ar.downcase
end


word = gets

i = 0
up = 0
low = 0

while i < word.length ;
	if word[i] <= 90
		up++
	else
		low++

if up > low
	word.upcase
else
	word.lowcase

return word


word = gets

i = 0
up = 0
low = 0

while i < word.length ;
	if word[i] <= 90
		up += 1
	else
		low += 1
	end
	i += 1
end

puts up
puts low

if up > low
	print word.upcase
else
	print word.downcase
end


n, a, b = gets.split.map(&:to_i)
ans, k = 0, 2
until (a-1)/k == (b-1)/k do
  k *= 2
  ans += 1
end
puts k == n ? "Final!" : ans


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

if p-k > 1 ;
	print ?<, ?<, ' '
end

(p-k).upto(p+k) do |i|
	if i == p ;
		print ?(, i, ?), ' '
	elsif i >= 1 && i <= n ;
		print i, ' '
	end
end

if p-k < n ;
	print ?>, ?>, ' '
end

print ?\n


n = gets.chomp.to_i

puts (n / 2250).to_i


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

m=10**9+7

def pow(a,n,m)
  return 1 if n==0
  d=n%2
  r=pow(a,n/2,m)**2
  r*=a if d==1
  r%=m
end

def fact(n,m)
  f=[1.0]
  for i in 1..n do
    f[i] = f[i-1]*i%m
  end
  f
end

f = fact(n,m)

def good? (x,a,b)
  while x > 0
    d=x%10
    return false if d!=a && d!=b
    x/=10
  end
  true
end

def inv(a,m)
  pow(a.to_i,m-2,m)
end

r=0
for i in 0..n do
  if good?(a*i+(n-i)*b,a,b)
    r+=f[n]*inv(f[n-i]*f[i],m)
    r%=m
  end
end

puts r.to_i


a,b,n=gets.split.map(&:to_i)
m=10**9+7
def pow a,n,m
  return 1 if n==0
  d=n%2
  r=pow(a,n/2,m)**2
  r*=a if d==1
  r%=m
end
f=[1.0]
1.upto(n){|i|f[i]=f[i-1]*i%m}
f.map!(&:to_i)
def g x,a,b
  !(/[^#{$a}#{$b}]/=~x.to_s)
end
r=0
(n+1).times do|i|
  if g(a*i+(n-i)*b,a,b)
    r+=f[n]*pow(f[n-i]*f[i],m-2,m)
    r%=m
  end
end
p r


n, k = gets.chomp.split(/ /).map(&:to_i)
odds = []
even = []
(1..n).each do |i|
    odds << i if i.odd?
    even << i if i.even?
end
final = odds + even
puts final[k - 1]


n, k = cin.split(/\s+/).map {|x| x.to_i}
class Integer
  def num_at_position (k)
    chet_num, ostatok = self.divmod(2)
    nechet_num = chet_num + ostatok
    if k > nechet_num
      return (k - nechet_num) * 2
    else
      return k * 2 - 1
    end
  end
end

puts n.num_at_position(k)


num = gets.chomp
num = num.split
numbers = num[0].to_i
position = num[1].to_i

if position <= (numbers/2) + (numbers%2)
	new_number = 1
	for i in (2..position)
		new_number += 2
	end
else
	new_number = 2
	for i in (1..position - ((numbers/2) + (numbers%2)))
		if i != 1
			new_number += 2
		end
	end
end

print new_number


#puts "Enter the total number and position to find the number\n"
n, v = gets.split.map(&:to_i)
a = [n]
c = 0
k = 0
for i in 1..n do
    if i%2 == 1
        a[k] = i
        k += 1
    end
end
l = 0
for j in 1..n do
    if  j%2 == 0
        a[k+l] = j
        l += 1
    end
end
puts a[v-1]


#puts "Enter the total number and position to find the number\n"
n, v = gets.split.map(&:to_i)
a = [n]
if n%2 == 0
    c = n/2
else
    c = n/2 + 1
end
#puts c
k = 0
for i in 1..n do
    if i%2 == 1
        a[k] = i
        k += 1
    else
         a[c] = i
         c += 1
    end
end

puts a[v-1]


n,i = gets.split.map(&:to_i)
p (((1..n).to_a.each.select{|x| x.odd?}) + ((1..n).to_a.each.select{|x| x.even?}))[i-1]


input = gets.split
n = input[0].to_i
k = input[1].to_i
half = (n/2.0).ceil

val = 0
if k > half
    val = 2
    k -= half
else
    val = 1
end

for i in 1..k-1
    val += 2
end

print val


input = gets.chomp.split(' ').map {|item| item.to_i}

n = input[0]
k = input[1]

odd = []
even = []
result = []

(1..n).each do |number|
 odd << number if number % 2 == 1
 even << number if number % 2 == 0
end

result = odd + even

puts result[k - 1]


t, w, b = gets.strip.split.map(&:to_i)

l = w.lcm(b)
a = t/l * [w, b].min
a += [t % l, [w, b].min].min
a -= 1

if w == b then
  puts "1/1"
else
  g = a.gcd(t)
  puts "#{a/g}/#{t/g}"
end


t, w, b = gets.split(" ").map &:to_i
x = [w, b].min * (t / w.lcm(b)) + ([w, b, 1 + t - [w, b].min * (t / w.lcm(b) * w.lcm(b))].min - 1)
y = t
puts Rational(x, y)


t, w, b = gets.split(" ").map &:to_i
x = [w, b].min * (t / w.lcm(b)) + ([w, b].min - 1)
y = t
puts Rational.new(x, y)


a = gets.chomp.split
n = a[0].to_i
k = a[1].to_i
x = 0
if (k == (n*(n + 1))/2)
    x = 0
else
    x = n - ((Math.sqrt(9 + (8 * (n + k)) - 3)/2))
end
puts (x).to_i


a = gets.chomp.split
n = a[0].to_i
k = a[1].to_i
if (k == (n*(n + 1))/2)
    x = 0
elsif( k == 0)
    x = (Math.sqrt(9 + (8 * n)) - 3)/2
else
    x = (Math.sqrt(2 * k))
end
y = x*(x+1)/2
count = 0
while (y < n - x) do
    count += 1
end
puts (n - x).to_i


n = gets.to_i
case n%4
when 0
	puts "1 A"
when 1
	puts "0 A"
when 3
	puts "2 A"
else
	puts "1 A"
end


def power(x, y, z)
	number = 1
	while (y > 0) do
		if (y%2==1)
			number = number * x % z
		end
		y >>= 1
		x = x * x % z
	end
	return number
end

n, m, k = gets.split.map(&:to_i)
md = 1000000007
p power(2, (n-1)*(m-1), md)


st = gets
s = st.split.first.to_i
k = st.split.second.to_i
d = ( s / 2 ) / ( k + 1)
puts "#{d} #{d*k} #{s-d*(k+1)}"


#         ... LETS HACK THE WORLD ...
#... KEEP CALM AND SAY LE ROI EST MORT IS HERE ...
#       ... EL-BADRY BECOME A LEGEND ...
n, m, a = gets.chomp.split.map(&:to_i)

 if m%a==0 and n%a==0

            puts (m/a)*(n/a)

        if m%a!=0 and n%a!=0

            puts ((m/a)+1)*((n/a)+1)

        if m%a==0 and n%a!=0

            puts (m/a)*((n/a)+1)

        if m%a!=0 and n%a==0

            puts ((m/a)+1)*(n/a)


n=gets.to_i
m=gets.to_i
a=gets.to_i

if((n%a)==0)
  l = n/a;
else
  l = n/a;
  l = l+1;
end
if(m%a)==0
  p = m/a;
else
  p = m/a;
  p = p+1;
end
print p*l


class A1
  def m(n, m, a)
    puts (n / a.to_f).ceil * (m / a.to_f).ceil
  end
end

n, m, a = gets.split.map(&:to_i)
a = A1.new
puts a.m(n,m,a)


class A1
  def m(n, m, a)
      (n / a.to_f).ceil * (m / a.to_f).ceil
    end
  end
end

n, m, a = gets.chomp.split("\s").map { |x| x.to_i }
a = A1.new
puts a.m(n,m,a)


n = gets.to_i
m = gets.to_i
a = gets.to_i

t = (n % a).ceil
y = (m % a ).ceil
puts t * y


n=gets.to_i
m=gets.to_i
a=gets.to_f

puts ((n/a).round) * ((m/a).round)


n = gets.to_i
m = gets.to_i
a = gets.to_i
puts ((n/a)+1)*((m/a)+1)


  a = gets.chomp.to_i
  b = gets.chomp.to_i
  c = gets.chomp.to_i

  p a.fdiv(c).ceil * b.fdiv(c).ceil


n = gets.chomp
    m = gets.chomp
    a = gets.chomp

    x = n/a;
    y = m/a;
    mod_n = n % a;
    if (mod_n > 0)
        x = x+1

    mod_m = m % a;
    if (mod_m > 0)
        y = y+1

    print("#{x*y}")


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

    x = n/a;
    y = m/a;
    mod_n = n % a;
    if (mod_n > 0)
        x = x+1;
    end

    mod_m = m % a;
    if (mod_m > 0)
        y = y+1;
    end

    puts x*y;


a,b,c=gets.split.map &:to_i;

    x = n/a;
    y = m/a;
    mod_n = n % a;
    if (mod_n > 0)
        x = x+1;
    end

    mod_m = m % a;
    if (mod_m > 0)
        y = y+1;
    end

    p (x*y);


n = gets.chomp.to_i
m = gets.chomp.to_i
a = gets.chomp.to_i

puts ((n + a - 1) / a) * ((m + a - 1) / a)


n, m, a = ARGV
puts (n.to_f/a.to_f).ceil * (m.to_f/a.to_f).ceil


n = gets.to_i
m = gets.to_i
a = gets.to_i

# m_tolerance
# n_tolerance
m_tolerance = (m / a).ceil
n_tolerance = (n / a).ceil
# mから考える

puts m_tolerance + n_tolerance - 1


n,m = gets().split(' ')
n,m = n.to_i, m.to_i
k1 = n / m + (n % m > 0 ? 1 : 0)
k2 = n - (m - 1)
couples = lambda {|n| n*(n-1)/2}
same = n%m == 0 ? m : n%m
print couples.call(k1)*same, ' ', couples.call(k2)


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

def C(x)
	return x*(x-1)/2
end

def kmin(n,m)
	k = (n/m).floor
	r = n&m
	return C(k)*(m-r)+C(k+1)*r
end

def kmax(n,m)
	return m-1+C(n-m+1)
end

puts "#{kmin} #{kmax}"


def comb(n,r)
	return 0 if n < r
    return 1 if n == r
    return n if r == 1
    return 1 if n == 0
    comb(n-1,r) + comb(n-1,r-1)
end

n,m = gets.split(" ").map(&:to_i)
max = comb(n-m+1,2)

q = n / m
r = n % m
min = 1
min = (r * comb(q+1,2)) + ((m-r) * comb(q,2))

puts "#{min} #{max}"


n, m = gets.chomp.split.map(&:to_i)
def fi(n)
  f = 0
  for i in 1...n
    f += i
  end
  f
end
max = fi(n - m + 1)
if n % m == 0
  min = fi(n / m) * m
else
  a = []
  min = 0
  m.times do
    a << n / m
  end
  (n % m).times do |i|
    a[i] += 1
  end
  m.times do |i|
    min += fi(a[i])
  end
end
print min, " ", max, "\n"


#ruby 2.4.1

require "prime"
t = gets.to_i
t.times do |a, b|
	nums = gets
	a1, b1 = nums.split
	a = a1.to_i
	b = b1.to_i
	if Prime.prime?(((a+b)*(a-b))) == true
		puts  "YES"
	else
		puts "NO"
	end
	#puts "#{a}  #{b}"
end


#ruby 2.4.1

require "prime"
t = gets.to_i
t.times do |a, b|
	flag = false
	nums = ""
	nums = gets
	a1, b1 = nums.split(' ')
	a = a1.to_i
	b = b1.to_i
	if ((a-b)*(a+b)) == (a + b)
		puts "YES"
	else
		puts "NO"
	end
end


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

if n < m
    puts "Impossible"
else
    puts n + m - [n,m].min, n + m - [1,m].min


#!/usr/bin/ruby
include Math

data = gets.split.map{ |x| x.to_i}
otona = data[0]
kodomo = data[1]

if otona == 0
  puts "impossible"
else
  print otona+kodomo-1
  print ' '
  kodomo -= min(otona,kodomo)
  print otona+kodomo
  print "\n"
end


n,m=gets.split.map(&:to_i)
if n==0
  puts "Impossible"
else
  puts "#{n<m?m:n} #{n+m-1}"
end


l,r,x,y,k=gets.split.map &:to_i
l=(l+k-1)/k
r=r/k
puts l<=r && x<=r && l<=r ? :YES : :NO


l,r,x,y,k=gets.split.map &:to_i
puts max((l+k-1)/k,x)>min(r/k,y) ?"NO":"YES"


l,r,x,y,k=gets.split.map &:to_i
puts [l,x*k-k+1].max>[r,y*k].min ? 'NO':'YES'


#!/usr/bin/ruby
n,x=gets.split.map(&:to_i)
p 1.step(n).count{|i|x%i==0}


n, x = gets.split.map(&:to_i)
s = 0

for i in 1..n
 s+=1 if x % i == 0
end

s-=1 if x > n

puts s


n, x = gets.split.map(&:to_i)
s = 0
for i in 1..n do
  for j in 1..n do
   s+=1 if i*j == x
  end
end

puts s


n = gets.chomp.to_i
k = gets.chomp.to_i
a = gets.chomp.to_i
b = gets.chomp.to_i

result = 0

if k != 1
  while n != 1
    if(n%k == 0)
      sum = (n - n/k) * a

      if(b < sum)
        result += b
        n = n/k
      else
        result += (n - 1) * a
        break
      end
    else
      n -= 1
      result += a
    end
  end
else
  result = (n - 1) * a
end

puts result


n = gets.chomp.to_i
k = gets.chomp.to_i
a = gets.chomp.to_i
b = gets.chomp.to_i

result = 0

if k != 1
  while n != 1
    if(n%k == 0)
      sum = (n - n/k) * a

      n = n/k

      if(b < sum)
        result += b
      else
        result += (n - 1) * a
        break
      end
    else
      n -= 1
      result += a
    end
  end
else
  result = (n - 1) * a
end

puts result


# coding: utf-8

# if __FILE__ == $0
# end

# power of 1378, and last digit
n = gets.to_i
base = 8
(n-1).times {
    base *= 8
    base = base % 10
}

puts base


n = gets.strip.to_i
a = [8, 4, 2, 6]
n -= 1
puts a[n % 4]


#!/usr/bin/env ruby

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

if k == 1
  puts [0, ((1+n*b-t)/b.to_f).ceil].max
else
  lim = Math.log(t) / Math.log(k)
  left = 0
  right = n
  30.times do
    center = (left+right) / 2
    if n-center > lim
      left = center
    else
      sum = k**(n-center) + b*(1-k**(n-center))/(1-k)
      if sum <= t
        right = center
      else
        left = center+1
      end
    end
  end

  puts (left+right)/2
end


k,b,n,t,x = gets.split.map{|i| i.to_i},1
x,n=x*k+b,n-1 until x > t
puts [0, n+1].max


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]==intsone[i+1]
		count+=1
	end
	i+=1
end
if all_equal(instone)
	count = instone.length
end
puts count


def all_equal?(array) 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 IsVowel(c)
  "aeiou".include?(c)
end

def HasConsVowels(s)
  s.each_cons(2).to_a.map{|a, b| IsVowel(a)&&IsVowel(b)}.include?(true)
end
gets
s = gets.chomp.chars
until !HasConsVowels(s) do
s.each_index do |i|
  next if i == 0
  s.delete_at(i) if IsVowel(s[i]) && IsVowel(s[i-1])
end
end
puts s.join


n = gets
s = gets

1000.times{s = s.sub(/([aeiou])[aeiou]/,'\1')}

puts s


length = gets.chomp().to_i
word = gets.chomp().split("")
del = 1
vowels = ["a", "e", "i", "o", "u", "y"]
vowel = false

for i in 1..length do
    if vowels.include?(word[i - del]) and vowel == true
        word.delete_at(i - del)
        del += 1
    elsif vowels.include?(word[i - 1])
        vowel = true
    else
        vowel = false
    end
end

puts word.join


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=gets.to_i
checked=Array.new(n,false);
s=0
n.times do |t|
  if checked[s] then puts "NO"; exit; end
  checked[s]=true;
  s=(s+t)%n
end
puts "YES"


recipe = gets
n = gets.split.map{|e| e.to_i}
p = gets.split.map{|e| e.to_i}
budget = gets.to_i

k = ["B", "S", "C"].map{|e| recipe.count e}

l = 0; r = budget + n.max; x = 0
while l <= r
    m = (l + r) / 2
    sum_cost = k.map.with_index{|e, i| e == 0 ? 0 : (e * m - n[i]) * p[i]}.inject(:+)
    if sum_cost < budget
        l = m + 1
        x = m
    elsif sum_cost > budget
        r = m - 1
    else
        x = m
        break
    end
end
puts x


recipe = gets.chomp
has = Hash.new(0)
price = Hash.new(0)

has['B'],has['S'],has['C'] =  gets.split(" ").map(&:to_i)
price['B'],price['S'],price['C'] =  gets.split(" ").map(&:to_i)

ruby = gets.to_i

cost = 0
count = Hash.new(0)
recipe.each_char do |a|
	cost += price[a]
	count[a] += 1
end

possible = {}
count.each_key do |a|
	possible[a] = has[a] / count[a]
end

min,max = possible.values.minmax
required_cost = nil
# puts "min #{min} max #{max} coutn #{count}"
while min < max
	mid = min + ((max-min)+1)/2

	needed_cost = 0

	count.each_key do |a|
		mid_count = count[a] * mid
		if mid_count > has[a]
			needed_cost += (mid_count - has[a]) * price[a]
		end
	end

	if needed_cost <= ruby # purchasing things amount should be less than ruby
		required_cost = needed_cost
		min = mid
	else
		max = mid - 1
	end
end
# puts "min #{min} max #{max} req #{required_cost}"
# puts "cost #{cost}"
# puts "count #{count}"

if required_cost
	ruby -= required_cost
end
ans = max

qty = ruby / cost
spent = cost * qty
# puts "qt #{qty}"
ans += qty

ruby -= spent

remaining_cost = 0

count.each_key do |a|
	rem = has[a] % (count[a] * max)
	remaining_cost += (count[a] - rem) * price[a]
end
# puts "ruby #{ruby} rem #{remaining_cost} count #{count}"
if remaining_cost > 0 && ruby >= remaining_cost
	ans += 1
end

puts ans


recipe = gets.chomp
has = Hash.new(0)
price = Hash.new(0)

has['B'],has['S'],has['C'] =  gets.split(" ").map(&:to_i)
price['B'],price['S'],price['C'] =  gets.split(" ").map(&:to_i)

ruby = gets.to_i

cost = 0
count = Hash.new(0)
recipe.each_char do |a|
	cost += price[a]
	count[a] += 1
end

possible = {}
count.each_key do |a|
	possible[a] = has[a] / count[a]
end

min,max = possible.values.minmax
required_cost = nil
# puts "min #{min} max #{max} coutn #{count}"
while min < max
	mid = min + ((max-min)+1)/2

	needed_cost = 0

	count.each_key do |a|
		mid_count = count[a] * mid
		if mid_count > has[a]
			needed_cost += (mid_count - has[a]) * price[a]
		end
	end

	if needed_cost <= ruby # purchasing things amount should be less than ruby
		required_cost = needed_cost
		min = mid
	else
		max = mid - 1
	end
end
# puts "min #{min} max #{max} req #{required_cost}"
# puts "cost #{cost}"
# puts "count #{count}"

if required_cost
	ruby -= required_cost
end
ans = max

qty = ruby / cost
spent = cost * qty
# puts "qt #{qty}"
ans += qty

ruby -= spent

remaining_cost = 0

count.each_key do |a|
	rem = 0
	rem = has[a] % (count[a] * max) if has[a] >= count[a] * max
	remaining_cost += (count[a] - rem) * price[a]
end
# puts "ruby #{ruby} rem #{remaining_cost} count #{count}"
if remaining_cost > 0 && ruby >= remaining_cost
	ans += 1
end

puts ans


nm = gets.chomp.split(" ").map(&:to_i)
n = nm[0]
m = nm[1]

def findfor(x,y,k)
  count = 0
  (1..x).each do |a|
    (1..y).each do |b|
      if (a**2+b**2)%k==0
        count += 1
      end
    end
  end
  return count
end

if n<m
  puts findfor(n,n,m)
  exit
else
  form = findfor(m,m,m)
  nbym = n/m
  nmodm = n%m

  ans = form*(nbym**2)
  ans += 2*nbym*findfor(m,nmodm,m)
  ans += nbym*findfor(nmodm,nmodm,m)
end
puts ans


n, m = gets.split.map &:to_i
if n == m
  puts "Second"
else
  if [n, m].max == n
    puts "First"
  else
    puts "Second"
  end
e


arr = $stdin.readline.split(" ")
n1 = arr[0].to_i
n2 = arr[1].to_i
n2 + 1 > n1 ? puts "Second" : puts "First"


a = gets.split(" ").to_i

if a[0] > a[1]
    puts "First"
else
    puts "Second"
end


a , b , c ,d = gets.split.map |i|{i.to_i}

if a > b
    puts "First"
else
    puts "Second"
end


input = ARGV ? $< : File(ARGV[0])

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

arr.sort!()

diff = arr[n] - arr[0]
stop = m - n
for i in (1..stop)
	local = arr[n-1+i] - arr[i]
	diff = [diff, local].min
end

puts diff


n=gets.to_i
s=gets.to_s.downcase!

if s.split('').uniq.size == 26
  puts "YES"
else
  puts "NO"
end


puts gets.chomp.downcase.chars.uniq.sort == ('a'..'z').to_a ? "YES" : "NO"


b = [1]
10.times { b << b.last * 9 }

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

m = a.reduce(:*)

a.count.times do |i|
  r = (a[0..i].join.to_i - 1).to_s.split('').map(&:to_i).reduce(:*)
  rem_digits = a.count - i - 1
  r *= b[rem_digits]
  m = [r, m].max
end

puts m


a1=gets.chomp
w=a1.split(" ")
a=w[0].to_i
b=w[1].to_i

puts sum(a*b-1)/(b-1)


a,b = gets.chomp.split(" ").map(&:to_i)
acc = a
loop do
	a += 1 if a % b != 0
	acc += a /= b
	break if a == 0
end
puts acc


ar=gets.chomp.strip
a=ar[0].to_i
b=ar[2].to_i
#puts a
#puts b
sum=0
while a!=0
	sum+=a
	a/=b
end
puts sum


amount_candles = gets.to_i
divide = gets.to_i
sum = amount_candles

while amount_candles / divide >= 1 do
    sum += amount_candles / divide
    amount_candles = amount_candles / divide + amount_candles % divide
end

puts sum


def solve(str)
  x,m = str.split.map{|x| x.to_i}
  data = []
  loop do
    d = x % m
    if d.zero?
      puts 'Yes'
      return
    end
    x = x + d
    if data.include? d
      puts 'No'
      return
    else
      data << d
    end
  end
end

solve(gets)


def solve(str)
  x,m = str.split.map{|x| x.to_i}
  data = []
  t = 0
  loop do
    t += 1 if x > m
    d = x % m
    if d.zero?
      puts 'Yes'
      return
    end
    x = x + d
    if data.include?(d) || t>20
      puts 'No'
      return
    else
      data << d
    end
    puts "x:#{x} d:#{d} m:#{m}"
  end
end

puts solve(gets)


puts gets.split.map{|i| i.to_i}.min % 2 ? 'Akshat' : 'Malvika'


n,m = gets.split.map{ |e| e.to_i }
if n.even? or m.even?
  puts 'Malvika'
else
  puts 'Akshat'
end


n,m = gets.split
turnos=[n,m].min
if turnos.to_i%2==0
    puts "Malvika"
else
    puts "Akshat"
end


n,m=gets.split.map{|x|x.to_i}
#n,m=gets.split.map(&:to_i)
prev="z"; result=true
n.times do
	line=gets.split(//)
	if line[0]==prev
		result=false
	end
	prev=line[0]
	if line.count(line[0])!=m
		result=false
	end
end

if result
	puts "YES\n"
else
	puts "NO\n"
end


def palindrome?( hh, mm )
    hh == mm.reverse
end
hh, mm = gets.chomp.split(":")
found = false
n_hh, n_mm = hh.to_i, mm.to_i
while !found
    n_hh = n_hh.to_s.rjust(2, '0')
    t = n_hh.reverse.to_i
    if n_mm.to_i >= t || t > 32
        n_hh = n_hh.to_i + 1
        n_hh = 0 if n_hh == 24
        n_mm = n_hh.to_s.reverse
    else
        n_mm = t
    end
    n_mm = 0 if n_mm.to_i > 60
    n_hh = n_hh.to_s.rjust(2, '0')
    n_mm = n_mm.to_s.rjust(2, '0')
    found = palindrome? n_hh, n_mm
end
puts "#{n_hh}:#{n_mm}"


def palindrome?( hh, mm )
    hh == mm.reverse
end
hh, mm = gets.chomp.split(":")
found = false
n_hh, n_mm = hh.to_i, mm.to_i
while !found
    n_hh = n_hh.to_s.rjust(2, '0')
    t = n_hh.reverse.to_i
    if n_mm.to_i >= t
        n_hh = n_hh.to_i + 1
        n_hh = 0 if n_hh == 24
        n_mm = n_hh.to_s.reverse
    else
        n_mm = t
    end
    n_mm = 0 if n_mm.to_i > 60
    n_hh = n_hh.to_s.rjust(2, '0')
    n_mm = n_mm.to_s.rjust(2, '0')
    found = palindrome? n_hh, n_mm
end
puts "#{n_hh}:#{n_mm}"


inp = gets.split(':')

hh = inp[0]
mm = inp[1]

if hh.to_i == mm.reverse.to_i
  if hh.to_i == 23
    puts "00:00"
  else
    hh2 = hh.to_i+1
    if hh2/10 == 0
      hh2 = "0#{hh2}"
    end
    puts "#{hh2}:#{hh2.reverse}"
  end
else
  if hh.reverse.to_i < mm.to_i
    if hh == '23'
      puts "00:00"
    else
      hh2 = hh.to_i+1
      if hh2/10 == 0
        hh2 = "0#{hh2}"
      end
      puts "#{hh2}:#{hh2.reverse}"
    end
  else
    puts "#{hh}:#{hh.reverse}"
  end
end


def toMin arg
  arg[0].to_i*60 + arg[1].to_i
end
arg = STDIN.gets.split(":")

now = toMin(arg)
cand = toMin([arg[0],arg[0].reverse])
if cand > now and arg[0].reverse.to_i < 60
  puts sprintf("%02d:%02d",arg[0].to_i,arg[0].reverse.to_i)
  exit 0
else
  begin
    arg[0] = ((arg[0].to_i + 1) % 24).to_s
    cand = toMin([arg[0],arg[0].reverse])
    if ( cand > now and arg[0].reverse.to_i < 60)
      puts sprintf("%02d:%02d",arg[0].to_i,arg[0].reverse.to_i)
      exit 0
    end
  end while (arg[0].to_i > 0)
  puts "00:00"
end


n,a,b=gets.split.collect{|i| i.to_i}
puts min n-a, b+1


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

if a+b == n
    puts b
else
    for i in n-b..n
       counter+=1
    end
end

puts counter


n, a, b = gets.split.map &:to_i
puts a == b ? n - 1 : n - a


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

s = gets.chomp
result = "YES"
k = s.index("@")
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

puts result


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


n,R,r = gets.split.map{|x| x.to_f}

if R == r then
	puts "YES" if n == 1
	puts "NO" if n != 1
elsif r > R then
	puts "NO"
else
	theta = 2*Math.acos(r/(R-r))

	if (n-2)*Math::PI <= n * theta then
		puts "YES"
	else
		puts "NO"
	end
end


n, u, r = gets.split.map { |x| x.to_i }
r_max = u
if n > 1
  s = Math.sin(180 / n)
  r_max = s * u / (1 + s)
end
puts(r <= r_max ? 'YES' : 'NO')


a = gets.chomp!.split
n = a[0].to_i
r = a[2].to_i
s = a[1].to_i - r
if s == 0 then
	if n == 1 then puts("YES")
	else puts("NO") end
elsif s < 0 then puts("NO")
else
	r = r.to_f
	s = s.to_f
	n = n.to_f
	if Math.asin(r / s) <= Math::PI / n then puts("YES")
	else puts("NO") end
end


n, R, r = gets.split.map{|_|_.to_i}
puts n == 1 && r <= R || n > 1 && (R - r) * Math.sin(Math::PI / n) >= r ? "YES" : "NO"


def binpow(a,n,m)
  return 1%m if n == 0
  if n%2 == 0
    b = binpow(a,n/2,m)
    return (b*b)%m
  end
  return (a*binpow(a,n-1,m))%m
end
n,m = gets.split.map &:to_i

puts binpow(3,n,m)-1


n, m = gets.split.map(&:to_i)
# p gets.split.map(&:to_i)
def f(day, n, m)
  minus = (m + 1 + day) * (day - m) / 2
  plus = (day - m - 1) * m
  return n - minus + plus <= 0
end

if(m >= n)
  puts m
else

  l = m
  r = 1000000000000000000
  while(r - l > 1)
    mid = (r + l) / 2
    if(f(mid, n, m))
      r = mid
    else
      l = mid
    end

  end

  while(r >= l)
    if(f(r, n, m))
      r -= 1
    else
      r += 1
      break
    end
  end

  puts(r)
end


def pred(x, n, m)
    (n-m+x*m)-((m+x)*(m+x+1)-m*(m+1))/2 <= 0;
end
input = gets.chomp.split(' ').map(&:to_i)
n = input[0];
m = input[1];
if m > n
  puts n;
end

lo = 0
hi = n;
while lo < hi
  mid = lo+(hi-lo)/2;
  if pred(mid, n, m)
    hi = mid;
  else
    lo = mid+1
  end
end

puts m+hi;


def pred(x, n, m)
    (n-m+x*m)-((m+x)*(m+x+1)-m*(m+1))/2 <= 0;
end
input = gets.chomp.split(' ').map(&:to_i)
n = input[0];
m = input[1];
if m > n
  puts n;
else
  lo = 0
  hi = n;
  while lo < hi
	mid = lo+(hi-lo)/2;
	if pred(mid, n, m)
	  hi = mid;
	else
	  lo = mid+1
	end
  end
end

puts m+hi;


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

if n<=m
    p n
else
    res=2**63-1
    a=2**62
    while a>0
        x=res-a
        res=x if x*(x+1)/2-m*(m+1)/2>=n+m*(x-m-1)
        a>>=1
    end
    p res
end


str = gets
if str.include?"ABC" or str.include?"ACB" or str.include?"BCA" or str.include?"BAC" or str.include?"CBA" or str.include?"CBA"
    puts 'YES'
else
    puts 'NO'
end


# coding: utf-8

# if __FILE__ == $0
# end

def weigh(c)
    c = c.capitalize
    case c
    when 'Q'
        9
    when 'R'
        5
    when 'B'
        3
    when 'N'
        3
    when 'P'
        1
    else
        0
    end
end

white, black = 0, 0
8.times {
    gets.chomp.split(//).each { |c|
        if c == '.'
            next
        elsif c == c.upcase
            white += weigh(c)
        else
            black += weigh(c)
        end
    }
}

if black < white
    puts "White"
elsif black == white
    puts "Draw"
else
    puts "Black"
end


# coding: utf-8

# A's standard: 1 Expert 2 Newbs
# B's standard: 2 Experts 1 News
# Maximize the number of teams

n, m = gets.split.map(&:to_i)
# 0<=n,m<=5*10**5
teams = 0
if n < m
    n, m = m, n
end

q = [n/2, m].min
teams += q
n -= q*2
m -= q
if m > 0
    q2 = [n, m/2].min

    if q2 > 0
        teams += q2
    end
end

puts teams


# coding: utf-8

# A's standard: 1 Expert 2 Newbs
# B's standard: 2 Experts 1 News
# Maximize the number of teams

n, m = gets.split.map(&:to_i)
# 0<=n,m<=5*10**5
teams = 0

while n > 0 && m > 0
    if n < m
        n, m = m, n
    end

    if n >= 2
        teams += 1
        n -= 2
        m -= 1
    end
end

puts teams


def raise(x, n, mod)
	res = 1;
	while n != 0
		res = (res*x)%mod if x%2
		x = (x*x)%mod
		n = n/2
	end
	res
end
n, mod = gets.split.map(&:to_i)
ans = raise(3, n, mod) - 1
puts ans


def pow(a, b)
    if (b==1) return a;
    if (b==0) return 1;
    c = pow(a,b/2)
    c = (c * c) % $mod
    c = (c * a) % $mod if (b % 2==1)
    c
end

n, m = *gets.split.map {|x|x.to_i}
$mod = m
puts (pow(3, n) - 1 + m) % m


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

c = 0
loop do
  break if b <= 0
  c += 1

  a, b = [a, b].sort
  a += 1
  b -= 2
end
puts c


x= gets.chomp.split(' ').map(&:to_i)
if x[0]>=x[1]
	mn=x[1]
	mx= x[0]
else
  mn=x[0]
  mx=x[1]
end

t=0;
#puts"#{mn}"
#print mx

  while (mx >= 0 && mn>=0) do

   mx=mx-2
   mn=mn+1
   t=t+1
   a= mx
   b=mn
   if a>=b
	mn=b
	mx=a
else
  mn=a
  mx=b
end

   end
   print t-2
  # print mx
 #  print mn


a, b = gets.split.map(&:to_i)
puts a + b - ((a - b) % 3 == 0 ? 3 : 2)


def solve(a,b)
	if a<=0 || b<=0
		return 0
	end
	if a<=1 && b<=1
		return 0
	end
	ans=[solve(a-2,b+1),solve(a+1,b-2)].max+1
	#puts 'a='+a.to_s+' b='+b.to_s
	#puts 'ans='+ans.to_s
	return ans
end
a,b=gets.split.map(&:to_i)
puts solve(a,b)


n = gets.to_i
puts (n/Math.sqrt(n)).ceil + Math.sqrt(n).floor


p = gets.to_i

count = 0
for i in 2...p
  pri = true
  x = i
  for j in 1...(p-1)
    if (x-1)%p == 0
	  pri = false
	  break
	end
	x *= i
  end
  if pri && (x-1)%p == 0 then
    count+=1
  end
end
puts count


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

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

    if flag and check(x, p - 1, p)
      count += 1
    end
  end

  puts count
end

run if $0 == __FILE__


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


def read_line
  gets.chomp.split.map &:to_i
end

c, d = gets.chomp.split('').map

k = 8
k -= 3 if c=='a' || c=='h'
k -= 3 if d=='1' || d=='8'

puts k


n = gets.chomp.to_i
interestings = gets.chomp.split(/ /).map(&:to_i)
watch = 0
prev = 0
(0...n).each do |i|
    curr = interestings[i]
    watch = curr
    if curr - prev > 15
        watch = prev + 15
        break
    end
    prev = curr
end
watch = prev + 15 if 90 - prev > 15
watch = 90 if watch > 90 || 90 - prev < 15
puts watch


n = gets.to_i
a = [0] + gets.split.map(&:to_i)
ans = 0
n.times do |i|
  if a[i + 1] - a[i] > 15
    ans = a[i] + 15
    break
  end
  ans = a[n] if i == n - 1
end
puts ans


arr = gets.split(" ").map(&:to_i)

ans = 0
# if sum >=3
# 	min,min_ind = arr.each_with_index.min
# 	arr.delete_at(min_ind)
# 	arr = arr.map{|e| e - min}
# 	ans = min
# 	sum = arr.inject(0,:+)
# 	if sum >= 3
# 		max = arr.max
# 		pair =  max / 2
# 		min = arr.min
# 		if pair <= min
# 			ans += pair
# 			if pair % 2 != 0
# 				min -= pair
# 				ans += 1 if min >= 2
# 			end
# 		else
# 			ans += min
# 		end

# 	end
# end
# arr = []
# ac2 = a/2
# bc2 = b/2
# cc2 = c/2
# # 0 2 1
# arr << [bc2,c].min
# # 0 1 2
# arr <<  b + cc2
# # 1 1 1
# arr << a + b + c
# # 1 2 0
# # 1 0 2
# puts ans
#  66,
#  34,23

arr.sort!
if((2 * (arr[0] + arr[1])) >= arr[2])
	puts arr[0] + arr[1]
else
	puts arr.inject(0,:+) / 3
end


c = gets.split.collect{|i| i.to_i}
ans = c.min
c = c.collect{|i| i-ans if i!=ans}.compact
if c.size == 2
    ans += [c.min, c.max-c.min].min
end
puts ans


n, m = gets.chomp.split.map(&:to_i)
def fi(n)
  f = n * (n - 1) / 2
end
max = fi(n - m + 1)
if n % m == 0
  min = fi(n / m) * m
else
  q = fi(n / m)
  p = q + n / m
  min = 0
  min += p * (n % m)
  min += q * (m - n % m)
end
print min, " ", max, "\n"


gets
puts gets.chomp.gsub("ogogogo", "***").gsub("ogogo", "***").gsub("ogo", "***")


def min (a,b) if a<b then a else b end end

p1,p2,p3,p4,a,b=gets.split.map{|v| v.to_i}
mod=min(min(p1, p2), min(p3,p4))

mp=Hash.new(0)
for i in a..b do
    res=i%mod
    mp[res]+=(res==i)?1:0
end

print mp.find_all{|key, value| value>=7}.size


p1,p2,p3,p4,a,b = gets.split.map(&:to_i)

pp = [p1,p2,p3,p4].min

p [[b,pp].min - a, 0].max


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

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

result = 0

while true
  hash = Hash.new(0)

  points.each_with_index do |point, index|
    points.each_with_index do |p, i|
      hash[index] += 1 if((point - p).abs > d and index != i)
    end
  end

  hash = hash.sort{|x, y| y[1] <=> x[1]}
  break if hash.empty?
  ind, repeat = hash[0][0], hash[0][1]
  if repeat > 0
    points.delete_at(ind)
    result += 1
  else
    break
  end
end

result


#Infinity
#geti,getia
#Object # dcopy
#
#String # to_a
#   "abc".to_a #=> ["a","b","c"]
#String # to_ia
#   "1 2 3".to_ia #=> [1,2,3]
#
#Array # rsort,rsort!
#   [1,3,2,4].rsort #=> [4,3,2,1]
#
#Integer # divisor
#   24.divisor #=> [1,2,3,4,6,8,12,24]
#
include Math
require "prime"
require "bigdecimal"
require "bigdecimal/math"
require "matrix"
require "pp"
require "benchmark"

Infinity = 1/0.0
class Matrix;def inspect;empty? ? "Matrix.empty(#{row_size}, #{column_size})":"Matrix[\n#{@rows.map(&:inspect).join("\n")}\n]";end;end
def pbin(obj);case obj;when Integer;puts obj.to_s(2);end;end
class String;def to_a;split("");end;end
class String;def to_ia;split.map(&:to_i);end;end
def getia;gets.to_ia;end
def geti;gets.to_i;end
class Object;def dcopy;Marshal.load(Marshal.dump(self));end;end
class Array;def rsort;sort.reverse;end;def rsort!;sort!.reverse!;end;end

x,y = getia
sum = x * 100 + y * 10
a = sum / 220
puts a&1 == 0 ? "Hanako" : "Ciel"


n, c = gets.split.map(&:to_i)
ps = gets.split.map(&:to_i)
ts = gets.split.map(&:to_i)

l = 0
lt = 0
r = 0
rt = 0
(0..n-1).each do |i|
  lt += ts[i]
  rt += ts[i-1]
  l += [0, ps[i]-lt*c].max
  r += [0, ps[i-1]-rt*c].max
end
if l == r
  puts 'Tie'
elsif l > r
  puts 'Limak'
else
  puts 'Radewoosh'
end


#!/Users/mike/.rvm/rubies/ruby-1.9.3-p327/bin/ruby

redNum, blueNum = STDIN.readline.split.collect {|s| s.to_i}

def msg s=''
	puts s
end

def simulate(isRed, redCount, blueCount, petyaMove)
	return [0, 0] if redCount+blueCount == 0
	if petyaMove
		if isRed and redCount > 0
			p, v = simulate(true, redCount-1, blueCount, false)
			msg 'red'
			return [p+1, v]
		elsif not isRed and blueCount > 0
			msg 'blue'
			p, v = simulate(false, redCount, blueCount-1, false)
			return [p+1, v]
		elsif redCount > 0
			msg 'red'
			p, v = simulate(true, redCount-1, blueCount, false)
			return [p, v+1]
		else
			msg 'blue'
			p, v = simulate(true, redCount, blueCount-1, false)
			return [p, v+1]
		end
	else
		if isRed and blueCount > 0
			msg 'blue'
			p, v = simulate(false, redCount, blueCount-1, true)
			return [p, v+1]
		elsif not isRed and redCount > 0
			msg 'red'
			p, v = simulate(true, redCount-1, blueCount, true)
			return [p, v+1]
		elsif redCount > 0
			msg 'red'
			p, v = simulate(true, redCount-1, blueCount, false)
			return [p+1, v]
		else
			msg 'blue'
			p, v = simulate(true, redCount, blueCount-1, false)
			return [p+1, v]
		end
	end
end

msg 'red'
petya0, vasya0 = simulate(true, redNum-1, blueNum, false)
msg
msg 'blue'
petya1, vasya1 = simulate(false, redNum, blueNum-1, false)
msg

if (petya0 > petya1)
	puts '%s %s' % [petya0, vasya0]
else (petya1 > petya0)
	puts '%s %s' % [petya1, vasya1]
end


#!/Users/mike/.rvm/rubies/ruby-1.9.3-p327/bin/ruby

redNum, blueNum = STDIN.readline.split.collect {|s| s.to_i}

def msg s=''
	#puts s
end

def simulate(isRed, redCount, blueCount, petyaMove)
	return [0, 0] if redCount+blueCount == 0
	playRed, playBlue = false, false
	petyaScore, vasyaScore = 0, 0
	if petyaMove
		if isRed and redCount > 0
			playRed, petyaScore = true, 1
		elsif not isRed and blueCount > 0
			playBlue, petyaScore = true, 1
		elsif redCount > 0
			playRed, vasyaScore = true, 1
		else
			playBlue, vasyaScore = true, 1
		end
	else
		if isRed and blueCount > 0
			playBlue, vasyaScore = true, 1
		elsif not isRed and redCount > 0
			playRed, vasyaScore = true, 1
		elsif redCount > 0
			playRed, petyaScore = true, 1
		else
			playBlue, petyaScore = true, 1
		end
	end
	redCount -= 1 if playRed
	blueCount -= 1 if playBlue
	msg 'red' if playRed
	msg 'blue' if playBlue
	p, v = simulate(playRed, redCount, blueCount, !petyaMove)
	return [p+petyaScore, v+vasyaScore]
end

msg 'red'
petya0, vasya0 = simulate(true, redNum-1, blueNum, false)
msg
msg 'blue'
petya1, vasya1 = simulate(false, redNum, blueNum-1, false)
msg

if (petya0 > petya1)
	puts '%s %s' % [petya0, vasya0]
else (petya1 > petya0)
	puts '%s %s' % [petya1, vasya1]
end


a=gets.split.map(&:to_i)
line=[]
line << (a[0]>=a[1]?0:1)
a[line[0]]-=1

(1..(a[0]+a[1])).each {|i|
  if i%2==0 #first player
    if a[line[i-1]]>0
      line<<line[i-1]
      a[line[i-1]]-=1
    else
      line<<(line[i-1]+1)%2
      a[(line[i-1]+1)%2]-=1
    end
  else #second player
    if a[(line[i-1]+1)%2]>0
      line<<(line[i-1]+1)%2
      a[(line[i-1]+1)%2]-=1
    else
      line<<line[i-1]
      a[line[i-1]]-=1
    end
  end
}

score=[0]*2

(line.size-1).times {|i|
  if line[i]==line[i+1]
    score[0]+=1
  else
    score[1]+=1
  end
}

puts "#{score.max} #{score.min}"


BEGIN{
	n, m = gets.split.map(&:to_i)
	print (n+m) / 2 ,' ', n+m - 1 - (n+m)/2
}


a,b = gets.split(" ").map{|item| item.to_i}
query = gets.to_i
maxans = 0

query.times do
    ans = -1
    low,high = gets.split(" ").map{|item| item.to_i}

    (low..high).each do |item|

        break if [a,b].max < item

        next if a%item != 0
        next if b%item != 0
        ans = item
        answer << item
    end
    puts ans
end


a = gets.chomp
b = gets.chomp
s = a.to_i + b.to_i

a.sub(/0/, "")
b.sub(/0/, "")

if (a.to_i + b.to_i == s)
    puts "YES"
else
    puts "NO"
end


a = gets.chomp
b = gets.chomp
s = a.to_i + b.to_i

if (a.gsub(/0/, "").to_i + b.gsub(/0/, "").to_i == s.gsub(/0/, "").to_i)
    puts "YES"
else
    puts "NO"
end


parse_int = lambda { gets.split.map{|x| x.to_i} }

def sign(x)
  x>0 ? 1 : x<0 ? -1 : 0
end
x, o = 0, 0

mtx = []
4.times do |_|
  line = gets.chomp
  x += line.count 'x'
  o += line.count 'o'
  mtx << line
end

$ourchar = x > o ? 'o' : 'x'

def check(mtx)
  for i in (0..3)
    for j in (0..1)
      return true if (mtx[i][j] == $ourchar) && (mtx[i][j+1] == $ourchar) && (mtx[i][j+2] == $ourchar)
    end
  end

  for i in (0..1)
    for j in (0..3)
      return true if (mtx[i][j] == $ourchar) && (mtx[i+1][j] == $ourchar) && (mtx[i+2][j] == $ourchar)
    end
  end

  for i in (0..1)
    for j in (0..1)
      return true if (mtx[i][j] == $ourchar) && (mtx[i+1][j+1] == $ourchar) && (mtx[i+2][j+2] == $ourchar)
    end
  end
  false
end

for i in (0..3)
  for j in (0..3)
    if mtx[i][j] == '.'
      mtx[i][j] = $ourchar

      if check(mtx)
        puts 'YES'
        exit
      end

      mtx[i][j] = '.'
    end
  end
end

puts 'NO'


#!/usr/bin/env ruby
H={'Q'=>9,'R'=>5,'B'=>3,'K'=>3,'P'=>1}
w=b=0
$<.read.each_char{|c|
	if H[c]
		w+=H[c]
	elsif H[c.upcase]
		b+=H[c.upcase]
	end
}
puts %w(White Draw Black)[(b<=>w)+1]


class Board
  WEIGHTS = { q: 9, r: 5, b: 3, k: 3, p: 1 }

  def initialize(lines)
    @pieces = lines.join.chars
  end

  def which_to_win?
    case
    when score('white') > score('black')
      'White'
    when score('white') == score('black')
      'Draw'
    else
      'Black'
    end
  end

  private

  def score(color)
    selector = (color == 'white') ? ('A'..'Z').to_a : ('a'..'z').to_a

    @pieces.select { |piece| selector.include? piece }.map do |piece|
      weight piece
    end.inject(0, :+)
  end

  def weight(piece)
    key = piece.downcase.to_sym

    WEIGHTS.key?(key) ? WEIGHTS[key] : 0
  end
end

lines = [].tap do |arr|
  8.times { arr << gets.chomp }
end

board = Board.new(lines)
puts board.which_to_win?


n=gets.to_i
k=n.size-1
p (n-('9'*k).to_i).to_s.chars.map(&:to_i).reduce(:+)+9*k


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 = 0
nums = Array.new

biggest = 0
smallest = 100

n = gets.chomp.to_i
for i in 1..n
	nums.push(gets.chomp.to_i)
	if n == nums.last
		biggest = i
	end
	if 1 == nums.last
		smallest = i
	end
end

puts "\n#{[n - [smallest, biggest].min, [smallest, biggest].min - 1].max}"

=begin
7
1
6
5
3
4
7
2

=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].min - 1].max

=begin
7
1
6
5
3
4
7
2

6
6
5
4
3
2
1

=end


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


k = gets.split.map(&:to_i)[1]
ps = gets.split.map(&:to_i)
res = ps.length
ps.each { |p|
 res = res - 1 if (p < ps[k] or p == 0)
}
puts res


#!/usr/bin/env ruby
input = gets.chomp.split(' ').map(&:to_i)
scores = gets.chomp.split(' ').map(&:to_i)

i = k = input[1] - 1
n = input[0]

if scores[k] > 0
  if i == n - 1
    abort(i.to_s)
  end
  while scores[i] == scores[k] && i < n
    i += 1
  end

  puts i
else
  loop do
    i -= 1
    break if i < 0 || scores[i] != 0
  end

  if i == 0 && scores[i] == 0
    puts 0
  end

  puts i + 1
end


n, k = gets.chomp.split(" ").map(&:to_i)
s = gets.chomp.split(" ").map(&:to_i)
w = s[k]
# puts "k: #{k}, w: #{w}"
s.reject! { |e| e < w || w <= 0 }
puts s.count


#!/usr/bin/ruby
gets
prev='0'
x=0
gets.chomp.chars{|c|
	if c=='0'
		if prev=='0'
			print 0
		else
			print x
			x=0
		end
	else
		x+=1
	end
	prev=c
}
print x if prev!='0'


n=gets.to_i
s=gets.chomp
t=s.split('0')
puts t.map{|e| e.size}.join


n = gets.to_i
c = 1
k = 1
while c<n do
  k+=1
  c+=(k-1)*4
end
puts (k-1)*2+1


a,b,c=gets.split.map(&:to_i)
if c==0
	puts b==a ? :YES : :NO
else
	puts (b>a ^ c>0)&&(b-a)%c==0 ? :YES : :NO
end


a, b, c = gets.strip.split(" ").collect{|v| v.to_i}

if (c == 0 and a == b) or ((b-a)%c == 0 and (b-a)/c >= 0)
	puts 'YES'
else
	puts 'NO'
end


a, b, c = gets.chomp.split(/ /).map(&:to_i)
ans = "NO"
while true
    if a == b
        ans = "YES"
        break
    end
    a += c
    break if a > b
end
puts ans


a,b,c=gets.split.map{|e| e.to_i}

d=b-a

if d%c==0
	puts "YES"
else
	puts "NO"
end


a, b, c = gets.split.map(&:to_i)
puts a == b || (c == 0 and a == b) || ( (b - a) % c == 0 and b < a and c < 0 ) || ( (b - a) % c == 0 and b > a )  ? :YES : :NO


s = gets.chomp
len = s.length
num_distic_chars = s.chars.uniq.count
puts ((len+1)*26)-num_distic_chars
=begin
aa
=end


def make(a, b, c, x)
  (x ** a) * b + c
end

def cnt(t)
  x = 0
  while t != 0
    x += t % 10
    t /= 10
  end
  x
end

a, b, c = gets.split.map(&:to_i)
x = 1
ans = []
while(true)
  t = make(a, b, c, x)
  if t >= 10 ** 9
    break
  end
  if x == cnt(t)
    ans << t.to_s
  end
  x += 1
end
puts ans.size
if ans.size != 0
  puts ans.join(" ")
end


def digit_sum(a)
  a.to_s.split(//).map(&:to_i).inject(:+)
end

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

result = []

(1..81).each do |sx|
  num = b * (sx ** a) + c
  if num > 0 && digit_sum(num) == sx
    result << num
  end
end

puts result.size
puts result.sort.map(&:to_s).join(" ")


a=gets.split()
b=a.collect{|x| x.to_i}
c=b[0]*b[1]+2*b[3]
d=b[0]*b[2]+2*b[4]
if c>d
    puts 'Second'
elsif b==d
    puts 'Friendship'
else
    puts 'First'
end


gets
a=gets.chars.chunk{|c|c}.select{|k,v|k=='B'}.map{|k,v|v.size}
a<<0 if a.empty?
p a.size
puts a*' '


n = gets.chomp.to_i
line = gets

groups = []
i = 0
while i < n-1
  c=0
  while line[i]=='B'
    c+=1
    i+=1
  end
  groups << c unless c == 0
  i+=1
end

puts groups.size
puts groups.join(' ')


BEGIN{
	def gint()
		return gets.split.map(&:to_i)
	end
	def main()
		n, t = gint
		s = gets.to_s
		l = s.length - 1
		t.times do |item|
			flag = false
			(0..l).each do |i|
				if flag then
					flag = false
					next
				end
				if s[i] == 'B' and s[i + 1] == 'G' then
					s[i], s[i + 1] = s[i + 1], s[i]
					flag = true
				end
			end
		end
		puts s
	end
	Test_case = 3
	Test_case.times do
		main()
	end
}


n, t = gets.chomp.split.map.to_i
f = gets.chomp
t.times do |i|
    f.gsub!(/BG/) { |x| 'GB' }
end
puts f


# 09 A
def gcd(a, b)
  while b != 0 do
    c = a % b
    a = b
    b = c
  end
  return a;
end

a,b = gets.split.map(&:to_i)
c = 1
if a > 0 && b > 0 then
  c = gcd(a, b)
end

print b/c, "/", a/c
puts


s = gets
x = 0
gets.each_char do |c|
  x += 1 if c == s[x]
end
puts x


s = gets.chomp.split('')
t = gets.chomp.split('')
c = 0
for i in 0...[s.size, t.size].min
  c += 1 if t[i] == s[c]
end
puts(c + 1)


a1, b1 = gets.split.map {|x| Integer x}
a2, b2 = gets.split.map {|x| Integer x}
a3, b3 = gets.split.map {|x| Integer x}
a4, b4 = gets.split.map {|x| Integer x}
if (a1 > b3 and b2 > a4 and a1 > b4 and b2 > a3) or (b1 > a3 and a2 > b4 and b1 > a4 and a2 > b3)
  puts 'Team 1'
elsif (a3 > b1 and b4 > a2 or b3 > a2 and a4 > b1) and (b3 > a1 and a4 > b2 or b4 > a1 and a3 > b2)
  puts 'Team 2'
else
  puts 'Draw'
end


n, t = gets.split.map{ |e| e.to_i}
q = gets.chomp

for i in 1..t
  s = q.split('BG')

  q = s[0]

  for i in 1..s.size-1
    q += 'GB' + s[i]
  end
  q += 'GB' if q.length < n
end

puts q


require 'algorithms'

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

t.times do |i|
    a.gsub!(/BG/) { |x| 'GB' }
end

puts a


n, t = gets.split.map(&:to_i)
s = gets.chomp.to_a
t.times do
	i = 0
	while i < s.size - 1
		if s[i] == "B" and s[i + 1] == "G"
			s[i], s[i + 1] = s[i + 1], s[i]

			i += 1
		end

		i += 1
	end
end

puts s.join


# frozen_string_literal: true

# @param [String] stones
# @param [String] instructions
def find_last_stone_to_stand_on(stones, instructions)
  current_stone = 0
  current_inst = 0

  stones.each_char do |stone|

    if current_inst.nil?
      return current_stone
    else
      current_inst = instructions.index(stone, current_inst)
      current_stone += 1
    end

    unless current_inst.nil?
      current_inst += 1
    end
  end

end

stones = gets.chomp
instructions = gets.chomp
print find_last_stone_to_stand_on(stones, instructions)


s1,s2=gets.chomp
a=0
for i in 0...s2.size do
a+=1 if s2[i]==s1[a]
end
puts a+1


TEST_MODE = ARGV[0] == 't'

def evaluate(actual, expected); actual == expected ? "OK" : "**NG**"; end
def tests(); yield if TEST_MODE; end
def to_array(val); val.kind_of?(Array) ? val : [val]; end
def parse_int_array(str); str.split(" ").collect{|s| s.to_i}; end

def t(input, expected_output)
  input = to_array(input)
  expected_output = to_array(expected_output)
  output = []
  solve(input, output)
  puts "#{evaluate(output, expected_output)} : input=#{input.to_s}, expected=#{expected_output.to_s}, actual=#{output.to_s}"
end

require 'prime'

def lcd(a, b)
  temp = {}
  a.prime_division.each {|p|
    temp[p[0]] = p[1]
  }
  b.prime_division.each {|p|
    if temp.has_key? p[0]
      temp[p[0]] += p[1]
    else
      temp[p[0]] = p[1]
    end
  }
  temp.keys.reduce(1) {|a, n| a * (n**temp[n])}
end

def solve(input, output)
  n, m, z = parse_int_array(input[0])
  output << (z/lcd(n, m)).to_s
end

tests do
  # test cases
  puts lcd(2,3)
  puts lcd(4, 10)
  t("1 1 10", "10")
  t("1 2 5", "2")
  t("2 3 9", "1")
end

puts solve(STDIN.read.split, []) unless TEST_MODE


n, m, z = gets.strip.split.map(&:to_i)
count = 0
(1..z).each do |i|
    call = i * n
    count += 1 if call % m == 0
    break if call > z
end
puts count


b = gets.to_i
g = gets.to_i
n = gets.to_i

cnt=0

if b>=n && g>=n
  cnt = n+1
else
  cnt = [b,g].min+1
end

puts cnt


_, base = gets.chomp.split.map(&:to_i)
a = gets.chomp.split.join.to_i(base)

_, base = gets.chomp.split.map(&:to_i)
b = gets.chomp.split.join.to_i(base)

ans = "".tap do |out|
  case
  when a == b
    out << "="
  when a > b
    out << ">"
  else
    out << "<"
  end
end
puts ans


_, b1 = gets.split.map(&:to_i)
a1 = gets.split.join('').to_i(b1)
_, b2 = gets.split.map(&:to_i)
a2 = gets.split.join().to_i(b2)
if a1 < a2
  puts '<'
elsif a1 > a2
  puts '>'
else
  puts '='
end


x, y = 2.times.map {
  n, b = gets.split.map(&:to_i)
  gets.delete(' ').to_i(b)
}
puts '<' if x < y
puts '>' if x > y
puts '=' if x == y


x, y = 2.times.map{
  n, a = gets.split.map(&:to_i)
  gets.split.map(&:to_i).inject{|x, y| x *= a ; x += y}
}
p '=><'[x <=> y]


# cook your code here

a = gets.to_i;
b = gets.to_i;
ans = 0;

while a>0 and b>0
    if a>=b
        ans += a/b;
        a %= b;
    else
        ans += b/a;
        b %= a;
    end
end

puts ans;


a,b = gets.split(" ").map{|x| x.to_i}
counter=1
if b == 1
  puts a
  exit
end
while a!=b do
  if b > a
    a ,b = b,a
  end
  a -= b
  counter+=1
end
puts counter


a,b = gets.split(" ").map{|x| x.to_i}
counter=1
if b == 1
  puts a
  exit
elsif b==a-1
  puts a
  exit
elsif b==a-2
  puts (a/2)+1
  exit
end
while a!=b do
  if b > a
    a ,b = b,a
  end
  a -= b
  counter+=1
end
puts counter


h,w=gets.split.map{|e| e.to_i}
ans=0
while h>1 && w>1
	h1=[h,w].max
	w1=[h,w].min
	ans+=h1/w1
	h1=h1%w1
	w=w1
	h=h1
end
ans+=[h,w].max
puts ans


n = gets.to_i

def split_amount(amount, count = 0)
  return count if amount == 0
  bill = [100, 20, 10, 5, 1].find { |n| n <= amount }
  count += 1
  split_amount(amount - bill, count)
end

puts split_amount(n)


n = gets.to_i

def split_amount(amount, count = 0)
  multiple = [100, 20, 10, 5, 1].find { |n| amount % n == 0 }
  if amount == 0
    return count
  elsif !multiple.nil?
    return count + amount / multiple
  else
    bill = [100, 20, 10, 5, 1].find { |n| n <= amount }
    count += 1
    split_amount(amount - bill, count)
  end
end

puts split_amount(n)


# frozen_string_literal: true

require 'set'

def findMinNeededHorseShoes (shoecolors)
  s = Set.new
  counter = 0
  shoecolors.each do |color|
    if s.include? color
      counter += 1
    else
      s << color
    end
  end
  counter
end

shoecolors = []
for i in 1..4 do
  shoecolors[i] = gets.chomp
end
puts findMinNeededHorseShoes(shoecolors).to_s


def add_count counter, item
    if counter[item].nil?
        counter[item] = 1
    else
        counter[item] += 1
    end
end
a, b, c, d = gets.strip.split.map(&:to_i)
count = {}
add_count count, a
add_count count, b
add_count count, c
add_count count, d
ans = count.length % 4
ans = 4 - ans
puts ans


puts (4 - gets.split.map(&:to_i).uniq!.length).to_i


def calc(n, k)
  base = k
  sum = n
  while n / base > 0
    sum += n / base
    base *= k
  end
  sum
end
n, k = gets.split.map(&:to_i)
ans = n
while calc(ans-1, k) >= n
  ans -= 1
end
puts ans


n,k = gets.split.map(&:to_i)
f = false
1.upto n do |i|
  s = 0
  j = 0
  l = 0
  loop do
    l = i*(k**j)
    break if l >= n
    s += l
    if s >= n
      f = true
      break
    end
    j += 1
  end
  if f
    p l
    exit
  end
end
p n


MOD = 10 ** 9 + 9
def pow2(x)
    st = 1
    pow = 2
    while(x != 0)
        if(x & 1)
            st = (st * pow) % MOD
        end
        pow = (pow * pow) % MOD
        x >>= 1
    end
    return st
end
n, m, k = gets.chop.split.map(&:to_i)
extra = n - m
if(extra * k >= n)
    print m % MOD
else
    st = n - extra * k
    cnt = st / k
    rest = st % k
    total = pow2(cnt)
    total = (total - 2 + MOD) % MOD
    total = (total * k + rest) % MOD
    total += extra * (k - 1)
    total %= MOD
    print total
end


MOD = 10 ** 9 + 9
n, m, k = gets.chop.split.map(&:to_i)
extra = n - m
if(extra * k >= n)
    print m % MOD
else
    st = n - extra * k
    cnt = st / k
    rest = st % k
    total = 1
    (cnt + 1).times do
        total = (total * 2) % MOD
    end
    total = (total - 2 + MOD) % MOD
    total = (total * k + rest) % MOD
    total += extra * (k - 1)
    total %= MOD
    print total
end


module Containers
  class Stack

  end
end

module Algorithm
  def pow_mod(a, b, c) #compute (a ^ b) mod c
    ans, tich = 1, a
    while b > 0
      ans = (ans * tich) % c if b % 2 == 1
      tich = (tich * tich) % c
      b /= 2
    end
    ans
  end
end

def read(f = nil)
  if f
    @n, @m, @k = f.gets.split.map(&:to_i)
  else
    @n, @m, @k = gets.split.map(&:to_i)
  end
end

def input(test_case, &block)
  (1..test_case).each do |e|
    f = File.new("test#{e}.txt", 'r')
    read
    yield
    f.close
  end
end

def solve(n = @n, m = @m, k = @k)
  t = (n / k) * (k - 1) + n % k
  if m <= t
    puts m
  else
    a = m - t
    puts k * ((1 << (a + 1)) - 2) + m - a * k
  end
end

def main
  input 2 do
    solve
  end
end

main


module Containers
  class Stack

  end
end

module Algorithm
  def pow_mod(a, b, c) #compute (a ^ b) mod c
    ans, tich = 1, a
    while b > 0
      ans = (ans * tich) % c if b % 2 == 1
      tich = (tich * tich) % c
      b /= 2
    end
    ans
  end
end

def solve
  n, m, k = gets.split.map(&:to_i)
  t = (n / k) * (k - 1) + n % k
  if m <= t
    puts m
  else
    a = m - t
    puts k * ((1 << (a + 1)) - 2) + m - a * k
  end
end

solve


h1, h2 = gets.split.map(&:to_i)
a, b = gets.split.map(&:to_i)

h1 += a * 8
if h1 < h2 and b > a
  puts -1
else
  cnt = 0
  rem = (h2 - h1)
  while rem > 0 do
    rem -= (a - b) * 12
    cnt += 1
  end
  puts cnt
end


a=gets.chomp.split(" ")
0.upto(1) {|i| a[i]=a[i].to_i}
b=gets.chomp.split(" ")
0.upto(1) {|i| b[i]=b[i].to_i}
dis=a[1]-a[0]
fd=8*b[0]
fn=12*b[1]
ad=12*b[0]
an=12*b[1]
if dis-fd<=0
puts "0"
elsif ad<=0
puts "-1"
else
dis=dis-fd+fn
ans=1
loop do
dis-=ad
break if dis<=0
ans+=1
dis+=an
end
puts "#{ans}"
end


def solve(t, acc, type)
  return t if acc >= @goal
  return -1 if t == 0 and @n_mul > @d_mul and acc < @goal

  if type == :day
    solve(t+1, acc + (@d_mul * 12), :night)
  else
    solve(t, acc - (@n_mul * 12), :day)
  end
end

sp, @goal = gets.split(" ").map(&:to_i)
@d_mul, @n_mul = gets.split(" ").map(&:to_i)

puts solve(0, sp + (8 * @d_mul), :day)


def solve(t, acc, type)
  return -1 if t == 0 and @n_mul >= @d_mul and acc < @goal

  if type == :day
    return t if acc >= @goal
    solve(t+1, acc + (@d_mul * 12), :night)
  else
    solve(t, acc - (@n_mul * 12), :day)
  end
end

sp, @goal = gets.split(" ").map(&:to_i)
@d_mul, @n_mul = gets.split(" ").map(&:to_i)

puts solve(0, sp + (8 * @d_mul), :day)


a,b=gets.split
idx=(1...a.size).find{|i|a[i]>b[0]}||a.size
puts a[0...idx]+b[0]


# http://codeforces.com/contest/586/problem/A
# A. Alena's Schedule
n = gets.chomp.to_i
arr = gets.chomp.split.join.gsub(/00/, '').chars

arr.pop if arr.last == '0'
arr.shift if arr.first == '0'
puts arr.join.length


a=gets.chomp.to_i
b=gets.chomp.split(" ")
loop do
if b[0]=="0"
b.delete_at(0)
else
break
end
end
loop do
if b[b.length-1]=="0"
b.delete_at(b.length-1)
else
break
end
end
trig=0
0.upto(b.length-3) do |i|
if b[i]=="0"&& b[i+1]=="0"
b.delete_at(i)
b.delete_at(i+1)
end
end
puts "#{b.length}"


n = gets.to_i
v = gets.split.map(&:to_i)
cont = 0
sw = 0
c = 0
for i in(0..(n-1))
    if v[i] == 1
        sw = 1
    end
    if sw == 1
        if(v[i]==0)
            c+=1
        elsif c < 2
            cont=cont+1+c
            c=0
        else
            cont+=1
        end
    end
end
p cont


# #325 Div2 A. Alena's Schedule
n = gets.chomp.to_i
l = gets.chomp.split(" ").map(&:to_i)
if l.length <=3
  puts l.count(1)
else
  start = l.index(1)
  lessons = []
  lesson = 0
  (start..n-2).each do |i|
    if l[i] == 1 then
      lesson += 1
    else
      if l[i-1] == 1 and l[i+1] == 1 then
        lesson += 1
      else
        lessons << lesson
        lesson = 0
      end
    end
  end
  if l[n-1] == 1 then
    lesson += 1
  end
  lessons << lesson
  puts lessons.inject(:+)
end


def function
a=gets.chomp
b=gets.chomp
c=gets.chomp
a=a.to_i
b=b.to_i
c=c.to_i
z=a+b
if c<z || (c%2==0 && z%2!=0) || (c%2!=0 && z%2==0)
print "NO"
else
print "YES"
end
end
function


a=gets.chomp.split(" ").map {|i| i.to_i}
need=a[0].abs+a[1].abs
step=a[2]
if need>step
    puts "No"
elsif need==step
    puts "Yes"
else
    if (need-step)%2==o
        puts "Yes"
    else
        puts "No"
    end
end


a, b, s = gets.chomp.split.map &:to_i
sum = a + b
puts if s >= sum && (s - sum) % 2 == 0 then
  "Yes"
else
  "No"
end


target = ARGV[0..1].map{|i| i.to_i }
steps = ARGV[2].to_i

def can_do_in_n_steps(target, steps)
    sum_of_target_coords = target[0].abs + target[1].abs
    if sum_of_target_coords <= steps and (steps - sum_of_target_coords) % 2 == 0
        return true
    end
    return false
end

puts can_do_in_n_steps(target, steps) ? 'Yes' : 'No'


n = gets.to_i
i = n
i -= 1
if( i != 0)
  while(n % i != 1)
    i -= 1
  end
end
puts n - i


def fact(n)
    (1..n).inject(&:*)
end

def kind_cnt(arr)
    list = Hash.new(0)
    arr.each do |c|
        list[c] += 1
    end

    tmp = 24
    vals = list.values.sort
    vals.each do |i|
        tmp /= fact(i)
    end
    tmp / (4-vals[0]+1)
end

arr = gets.chomp.each_char.sort.freeze
prev = ''
cnt = 0
(1..5).each do |i|
    c = arr[i]
    next if c == prev

    sub = arr[1...i]
    sub += arr[(i+1)..-1] if i+1 < arr.size
    cnt += kind_cnt(sub)

    prev = arr[i]
end

p cnt


#!/usr/bin/ruby
gets;a=gets.split.map(&:to_i)
s=0;h=Hash.new(0)
a.each{|e|s+=e;h[e]+=1}
r=s
h.each{|k,v|
	if v>=2
		r=[r,s-k*[v,3].min].min
	end
}
p r


cards = gets.strip.split.map(&:to_i)
counts = Array.new(100, 0)
cards.each do |i|
    counts[i - 1] += 1
end
duplicates = counts.each_index.select { |i| counts[i] >= 2 }.sort.reverse
if duplicates.length == 0
    puts cards.inject(:+)
else
    discard = duplicates[0]
    count = counts[discard]
    index = 0
    upto = [count, 3].min
    while index < upto
        pos = cards.index(discard + 1)
        cards.delete_at pos
        index += 1
    end
    puts cards.inject(:+)
end


n, l, r = gets.split.map(&:to_i)
arr = [0] * 3
(l..r).each do |e|
  arr[e % 3] += 1
end
cur = arr.dup
nxt = [0] * 3
(2..n).each do |i|
  nxt = [0] * 3
  nxt[0] = cur[0] * arr[0] + cur[1] * arr[2] + cur[2] * arr[1]
  nxt[1] = cur[0] * arr[1] + cur[1] * arr[0] + cur[2] * arr[2]
  nxt[2] = cur[0] * arr[2] + cur[1] * arr[1] + cur[2] * arr[0]
  # puts nxt.join(' ')
  cur = nxt.dup
  cur = cur.map{ |e| e % (10 ** 9 + 7)}
end
puts cur[0]


require 'test/unit'

class UnitTest < Test::Unit::TestCase

    def test_first
        res = solve "CPCPCPC"
        assert_equal(7,  res)
    end

    def test_second
        res = solve "CCCCCCPPPPPP"
        assert_equal(4, res)
    end

    def test_third
        res = solve "CCCCCCPPCPPPPPPPPPP"
        assert_equal(6, res)
    end

    def test_fourth
        res = solve "CCCCCCCCCC"
        assert_equal(2, res)
    end
end

def solve inp
    count = 0
    curr = 1
    prev = inp[0]
    (1..(inp.length - 1)).each  do |index|
        if inp[index] == prev
            curr += 1
        else
            prev = inp[index]
            count += 1
            curr = 1
        end
        if curr == 5
            count += 1
            curr = 0
        end
    end
    curr == 0 ? count : count + 1
end

str = STDIN.gets.chomp
puts solve str


s = gets.chomp
res = 0
k = s.index("CP")
n = s.index("PC")
if n && k then
    st = n > k ? "CP" : "PC"
elsif n then
    st = "PC"
elsif k
    st = "CP"
end
k = -1
n = 0

if st then
    while k = s.index(st, k+1) do
        res += s[n..k].size / 5
        if (s[n..k].size % 5) != 0 then
            res += 1
        end
        n = k
        st = st == "CP" ? "PC" : "CP"
    end
    res += s[n+1..-1].size/5
    if (s[n+1..-1].size % 5) != 0 then
        res += 1
    end
else
    res += s.size / 5
    if s.size % 5 != 0 then
        res += 1
    end
end

p res


c = 0
(gets.trim.split(/(P+)/) - [""]).each do |r|
	dm = r.length.divmod 5
	c += dm[1] == 0 ? dm[0] : dm[0] + 1
end
print c


class Fixnum
  def compare(fixnum)
    return -1 if self < fixnum
    return 1 if self > fixnum
    return 0 if self == fixnum
  end
end

class Tram
  attr_reader(:s, :x1, :x2, :t1, :t2, :p, :d)
  def initialize(s, x1, x2, t1, t2, p, d)
    @s = s
    @x1 = x1
    @x2 = x2
    @t1 = t1
    @t2 = t2
    @p = p
    @d = d
  end

  def direction
    x2.compare(x1)
  end

  def by_foot
    (x1 - x2).abs * t2
  end

  def wait_time
    if(direction == d)
      if(d == -1)
        if(p <= x1)
         (((p + s) + (s - x1)))  * t1
        else
          (x1 - p).abs * t1
        end
      else
        if(p <= x1)
          (x1 - p).abs * t1
        else
         ((s - p) + s + x1)  * t1
        end
      end
    else
      if(d == -1)
        (p * t1) + (x1 * t1)
      else
        ((s - p) * t1) + ((s - x1) * t1)
      end
    end
  end

  def tram_time
    (x1 - x2).abs * t1
  end

  def by_tram
    wait_time + tram_time
  end
end

def main
  s, x1, x2 = gets.split(" ").map(&:to_i)
  t1, t2 = gets.split(" ").map(&:to_i)
  p, d = gets.split(" ").map(&:to_i)
  tram = Tram.new(s, x1, x2, t1, t2, p, d)
  cands = [tram.by_tram, tram.by_foot]
  puts cands.select{|x| x >= 0 }.min
end

main


a = gets.chomp
x = a.size

puts (2**x.size * (a.to_i(2)))%1000000007


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

if l == r
  puts 0
else
x = r^l

puts 2**(Math.log2(x).ceil) -1
end


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

x = r^l

puts 2**(Math.log2(x).ceil) -1


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

if l == r puts 0
else
x = r^l

puts 2**(Math.log2(x).ceil) -1
end


l, r = gets.split.map(&:to_i)
ans = 0
70.downto(0) do |i|
	st = 1<<i
	if ( st>l && st<=r )
		ans = [ans, st*2-1].max
	elsif (r<st*2 && l>st)
		l -= st
		r -= st
	end
end
puts ans


n, m = gets.strip.split.map(&:to_i)
ans = 0
(1..n).each do |i|
    (1..m).each do |j|
        ans += 1 if (i + j) % 5 == 0
    end
end
puts ans


n, m = gets.strip.split.map(&:to_i)
count = Array.new(n, 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


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
end


n, m = gets.chomp.split(' ').map(&:to_i)
x = 1
ans = 0
until x > n
	balanceFactor = (5 * ((x / 5) + 1)) - x
	y = balanceFactor
	until y > m
		#puts "x : #{x}, y : #{y}"
		ans += 1
		y += 5
	end
	x += 1
end

puts ans


n = gets.to_i
temp = gets.to_i
a = []
a[0] = 2 if temp == 1
a[0] = 1 if temp == 2
a[1] = temp
flag = true
for i in 2..n
	a[i] = gets.to_i
	flag = false if a[i]==a[i-2]
end
if temp == 3 || flag == false
	print('NO')
else
	print("YES")
end


n = gets.to_i
temp = gets.to_i
a = []
a[0] = 2 if temp == 1
a[0] = 1 if temp == 2
a[1] = temp
flag = true
flag = false if temp=3
ty = [1,2,3] - a[0]
for i in 2..n
	a[i] = gets.to_i
	flag = false if !ty.include? a[i]
	tyr = ty - a[i]
	ty = [1,2,3] - tyr
end
if temp == 3 || flag == false
	print('NO')
else
	print("YES")
end


arr = gets.split(' ')
k = arr[0].to_i
n = arr[1].to_i
w = arr[2].to_i
total_sum = w*(k+w*k)/2
needed = total_sum - n
needed>0 ? puts needed : puts 0


a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i

r = (a + c -1)*(b + c -1)/c**2
puts r


n = gets
m = gets
a = gets
n = n.to_i
m = m.to_i
a = a.to_i

l = (n-n%a)/a
h = (m-m%a)/a

if(n%a != 0)
	l = l + 1
end

if(m%a != 0)
	h = h + 1
end

puts l*h


n = gets.chomp.to_i
m = gets.chomp.to_i
a = gets.chomp.to_i

m_div_a = m/a
m_rest_a = m%a

n_div_a = n/a
n_rest_a = n%a

m_a = m_div_a + (m_rest_a != 0 ? 1 : 0)
n_a = n_div_a + (n_rest_a != 0 ? 1 : 0)

puts m_a * n_a


n = gets.to_i
m = gets.to_i
a = gets.to_i

res = n / a
if ((n % a) != 0) then res+=1
end
res += m / a
if ((m % a) != 0) then res+=1
end
puts res


#C:\Ruby26-x64\bin -w
# -*- coding: UTF-8 -*-

n, m, a = get.split.map(&:to_i)
puts (n.to_f/a).ceil*(m.to_f/a).ceil


def chrnum(ch)
  if ch >= "0" && ch <= "9"
    return ch.to_i
  end
  return ch.ord - 55
end

def strnum(str, rdx)
  ret = 0
  mult = 1
  str.reverse!.each_byte{|s|
    ret += chrnum(s.chr)*mult
    mult *= rdx
  }
  return ret
end

h,m = gets.chomp.split(":")
h = h.sub(/^0+/,"")
m = m.sub(/^0+/,"")
minrdx = 2
(h+m).each_byte{|hm|
  wk = chrnum(hm.chr)+1
  minrdx = wk if wk > minrdx
}
if h.length == 1 && m.length == 1
  if chrnum(h) < 24 && chrnum(m) < 60
    puts "-1"
  else
    puts "0"
  end
else
  if strnum(h,minrdx) >= 24 || strnum(m,minrdx) >= 60
    puts "0"
  else
    print minrdx.to_s
    minrdx += 1
    while strnum(h,minrdx) < 24 && strnum(m,minrdx) < 60
      print " " + minrdx.to_s
      minrdx += 1
    end
    puts ""
  end
end


time = gets
m = /(.*):(.*)/.match(time)
hour = m[1]
minute = m[2]

max = 0
hour.each_char {|c| max = [c.to_i(36), max].max}
minute.each_char {|c| max = [c.to_i(36), max].max}
infinite = false
bases = []
for i in max + 1..35
  if(!(hour.to_i(i) < 0 || hour.to_i(i) > 23  || minute.to_i(i) < 0 || minute.to_i(i) > 59))
    bases << i
	if(hour.to_i(i) == hour.to_i(i + 1) && minute.to_i(i) == minute.to_i(i + 1))
	  infinite = true
	end
  end
end

if infinite
  puts -1
elsif bases.length > 0
  puts bases.join(" ")
else
  puts 0
end


def convert str, b
  num = 0
  for i in 0..str.length-1
    num += (str[i].to_i(36) * (b**(str.length-1 - i)).to_i)
  end
  return num
end

time = gets
m = /(.*):(.*)/.match(time)
hour = m[1]
minute = m[2]

max = 1
hour.each_char {|c| max = [c.to_i(36), max].max}
minute.each_char {|c| max = [c.to_i(36), max].max}
infinite = false
bases = []
for i in max + 1..60
  if(!(convert(hour,i) < 0 || convert(hour,i) > 23  || convert(minute, i) < 0 || convert(minute, i) > 59))
    bases << i
	if(i < 36 && convert(hour,i) == convert(hour, i + 1) && convert(minute, i) == convert(minute, i + 1))
	  infinite = true
	  break
	end
  end
end

if infinite
  puts -1
elsif bases.length > 0
  puts bases.join(" ")
else
  puts 0
end


h, m = gets.chomp.split(":").map do |s|
  s.sub(/^0+(.)/, '\1').bytes.to_a.map do |s|
    if s <= 57
      s - 48
    else
      s - 55
    end
  end
end

if h.size == 1 && m.size == 1 && h.first < 24 && m.first < 59
  puts -1
  exit
end

def cand(a, n)
  sum = 0
  a.reverse.each_with_index do |i, index|
    sum += i * (n ** index)
  end
  sum
end

hh = []
mm = []
(2..60).each do |n|
  hh << n if h.all?{|i| i < n} && cand(h, n) < 24
  mm << n if m.all?{|i| i < n} && cand(m, n) < 59
end
r = hh & mm
puts r.empty? ? 0 : r.join(" ")
exit


n, k = gets.strip.split.map(&:to_i)
ans = "YES"
mod = n % k
div = n / k
ans = "NO" if div.even? && mod > 0
puts ans


nk = gets.chomp.split.map(&:to_i)
n = nk[0]
k = nk[1]

if n%k == 0
	print "YES"
else
	if (n/k)%2 == 0
		print "NO"
	else
		print "YES"
	end
end


n = gets
k = gets

def kek(n,k)
  (n/k).even? ? 'NO' : 'YES'
end
puts kek(n,k)


b = gets.to_i

#example 1
# b = 1
#assert 1
#example 2
# b  = 2
#assert 2
require 'prime'

fast_divisors = b.prime_division.map{ |e| e.last + 1  }.inject(:*)

puts fast_divisors


#!/usr/bin/ruby
n,k=gets.split.map(&:to_i)
s=gets
a,b=['G','T'].map{|e|s.index(e)}.sort
puts (b-a)%k==0 && a.step(b,k).all?{|i|a[i]!='#'} ? :YES : :NO


input_word = gets.chomp
initial = input_word.split("")

if input_word == input_word.upcase
  p input_word.downcase
elsif input_word[1,input_word.length-1]==input_word.upcase[1,input_word.length-1] && initial == input_word.at(0) ==initial
  p input_word.capitalize
end


input_word = gets.chomp
initial = input_word.split("")
if input_word[1,input_word.length-1] == input_word.upcase[1,input_word.length-1]
  if  input_word.at(0) == input_word.downcase.at(0)
    print (input_word.capitalize+"\n")
  else
    print(input_word.downcase+"\n")
  end
else
  print(input_word+"\n")
end


a = gets.chomp
b = "a".."z"
c = b.to_a
d = c.join(" ")

if d.include([0])
puts a.capitalize

else
puts a
end


a = gets.split('').map(&:to_i)
(a.length-1).times{|i|
  if (i!=0 && a[i]>4)
    print 9-a[i]
  else
    print a[i]
    end
}


def lights_out(a,b,c)
	input = [a,b,c]
	grid = [[1,1,1],[1,1,1],[1,1,1]]
	input.each_with_index do |inp, ind|
		inp.each_with_index do |element,index|
			element.times do |i|
				grid[ind][index] = toggle(grid[ind][index])
				grid[ind][index-1] = toggle(grid[ind][index-1]) unless index <= 0 #izquierda
				grid[ind][index+1] = toggle(grid[ind][index+1]) unless index >= grid[0].size-1 #derecha
				grid[ind+1][index] = toggle(grid[ind+1][index]) unless ind+1 > grid.size-1 # el de abajo
				grid[ind-1][index] = toggle(grid[ind=1][index]) unless ind-1 <= 0 #el de arriba
			end
		end
	end
	puts grid[0].join('')
	puts grid[1].join('')
	puts grid[2].join('')
end

def toggle(number)
	number = 1 - number # MATH! PROBLEM?
end

a = gets.chomp.split(' ').map { |str| str.to_i }
b = gets.chomp.split(' ').map { |str| str.to_i }
c = gets.chomp.split(' ').map { |str| str.to_i }

lights_out(a,b,c)


def lights_out(a,b,c)
	input = [a,b,c]
	grid = [[1,1,1],[1,1,1],[1,1,1]]
	input.each_with_index do |inp, ind|
		inp.each_with_index do |element,index|
			element.times do |i|
				grid[ind][index] = toggle(grid[ind][index])
				grid[ind][index-1] = toggle(grid[ind][index-1]) unless index < 0 #izquierda
				grid[ind][index+1] = toggle(grid[ind][index+1]) unless index > grid[0].size-1 #derecha
				grid[ind+1][index] = toggle(grid[ind+1][index]) unless ind+1 > grid.size-1 # el de abajo
				grid[ind-1][index] = toggle(grid[ind=1][index]) unless ind-1 < 0 #el de arriba
			end
		end
	end
	puts grid[0].join('')
	puts grid[1].join('')
	puts grid[2].join('')
end

def toggle(number)
	number = 1 - number # MATH! PROBLEM?
end

a = gets.chomp.split(' ').map { |str| str.to_i }
b = gets.chomp.split(' ').map { |str| str.to_i }
c = gets.chomp.split(' ').map { |str| str.to_i }

lights_out(a,b,c)


n = gets.to_i
a = gets.split.map{|x| x = x.to_i}
a.uniq!
if(a.length <= 3)
	if(a.length == 3)
		if((a[1]-a[0]).abs == (a[1]-a[2]).abs)
			print((a[1]-a[0]).abs)
		else
			print(-1)
		end
	elsif (a.length == 2)
		#for fucking minimum
		if((a[1]-a[0]).abs % 2 == 0)
			print((a[1]-a[0]).abs / 2)
		else
			print((a[1]-a[0]).abs)
		end
	else
		print(0)
	end
else
	print(-1)
end


def get_sumator(arr)
    return -1 if arr.length > 3
    case arr.length
    when 1
        return 0
    when 2
        max = arr.max
        min = arr.min
        if (max - min) % 2 == 0
            return (max - min) / 2
        else
            return (max - min)
        end
    when 3
        max = arr[-1]
        min = arr[0]
        # if the average of max and min is the same as
        # the middle one it can be done
        if (max + min) / 2 == arr[1]
            return (max - min)/ 2
        else
            return -1
        end
    else
        return -1
    end
end

n = gets.chomp.to_i
nums = gets.chomp.split(" ").map(&:to_i)
unique_arr = []
nums.each do |num|
    unique_arr.push(num) if !unique_arr.include?(num)
end

puts get_sumator(unique_arr.sort)


a=gets.chomp.split(" ")
sum=0
a.each {|i| sum+=i.to_i}
if sum%5==0
puts "#{sum/5}"
else
puts "-1"
end


line=gets.chomp.strip.split(' ').map{|x| x.to_i}
sum=line.inject(&:+)
puts sum%line.size==0? sum/line.size : -1


input = gets.split
sum = 0
input.each { |num| sum += num.to_i }
if sum % 5 == 0
    puts sum / 5
else
    puts -1
end


min = gets().chomp!.split(" ").max {|a, b| a.to_i <=> b.to_i}.to_i - 1
case min
  when 0 then puts( "1/1" )
  when 1 then puts( "1/6" )
  when 2 then puts( "1/3" )
  when 3 then puts( "1/2" )
  when 4 then puts( "2/3" )
  when 5 then puts( "5/6" )
end


s = 6 - gets.split.map(&:to_i).max + 1
case s
  when 1
    puts '0/1'
  when 2, 3
    puts "#{1}/#{6 / s}"
  when 4
    puts '2/3'
  when 5
    puts '5/6'
  when 6
    puts '1/1'
end


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <iostream>
#include <cstdlib>
#include <cctype>
#include <stack>

using namespace std;

#define INIT(range, val) memset(range, val, sizeof(range))
#define inject(x) { cerr << "Fuction: " << __FUNCTION__ << ", Line: " << __LINE__ << ", " << #x << ": " << (x) << endl; }
#define mp make_pair
#define pb push_back

inline void __CIN__() { ios::sync_with_stdio(false); cin.tie(0); }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

char buf;
inline int xint() { while (buf = getchar(), buf < '0' || buf > '9'); int x = buf - '0'; for (; buf = getchar(), buf >= '0' && buf <= '9'; x = x * 10 + buf - '0'); return x; }
inline ll xll() { while (buf = getchar(), buf < '0' || buf > '9'); ll x = buf - '0'; for (; buf = getchar(), buf >= '0' && buf <= '9'; x = x * 10 + buf - '0'); return x; }
inline string xstring() { while (buf = getchar(), buf == ' ' || buf == '\n'); string x = ""; for (x += buf; buf = getchar(), buf != ' ' && buf != '\n'; x += buf); return x; }

int main() {
	return 0;
}


a, b = gets.split.map &:to_i
total = a
while a != 1
  total += a % b == 0 ? a / b : a / b + 1
  a /= b
end
puts total


a=gets.chomp.bytes{|e|57-e}
a[0]=9 if a[0]==0
puts a*''


# http://codeforces.com/contest/514/problem/A

digits = gets.chomp.chars.map(&:to_i)
digits.map! { |n| (9 - n) < n ? 9 - n : n }

puts digits.join.to_i


s = gets.to_i
h, m = gets.split.map(&:to_i)
res = []
min = [7,17,27,37,47,57]
m += 60 if m<7
min.each do |i|
  res<<(m-i)/s if (m>i && (m-i)%s==0)
end
p res.min


s = gets.to_i
h, m = gets.split.map(&:to_i)
res = 0
ti = h*60+m
until /7/.match?("#{ti / 60 % 24}#{ti % 60}")
  ti-=x
  res+=1
end
p res


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

ans = 0
while true
	if h.to_s.include? '7' or m.to_s.include? '7'
		break
	end
	m += x
	if m > 60
		h = (h+1)%24
		m -= 60
	end
	ans += 1
end
puts ans


s,t = gets,gets

if t == s.reverse
  puts "YES"
else
  puts "NO"
end


number=gets.chomp.split
n=number[0].to_i
k=number[1].to_i
#puts n,k
zeros=0
non_zeros=0
digits=0
while n>0
	if zeros==k
		break
	elsif n%10==0
		zeros+=1
	else
		non_zeros+=1
	end
	digits+=1
	n=n/10
end
#puts "zeros=#{zeros}"
#puts "digits=#{digits}"
if zeros==k
	puts non_zeros
elsif zeros<k
	#只剩下一个0
	puts digits-1
else
	puts 0
end


s, k=gets.split
l, k, d=s.split, k.to_i, 0
while k and !l.empty? do
  if l.pop.to_i
    d+=1
  else
    k-=1
  end
end
p k==k ? d : s.size-1


digits = STDIN.readline.strip.split('').map {|s| s.to_i }.reverse

pos = 0
while pos < digits.length
  digit = digits[pos]
  if digit == 4 or digit == 7
    pos += 1
    next
  end
  (0..pos-1).each {|i| digits[i] = 4 }
  if digit < 4
    digits[pos] = 4
  elsif digit < 7
    digits[pos] = 7
  else
    digits[pos] = 4
    seek = pos+1
    while seek < digits.length and digits[seek] == 9
      digits[seek] = 0
      seek += 1
    end
    if seek < digits.length
      digits[seek] += 1
    else
      digits = (digits.length + 1).times.map { 4 }
      break
    end
  end
  pos += 1
end
puts digits.reverse.map {|i| i.to_s }.join

while digits.count(4) != digits.count(7)
  pos = 0
  while pos < digits.length and digits[pos] == 7
    digits[pos] = 4
    pos += 1
  end
  if pos < digits.length
    digits[pos] = 7
  else
    digits.push(4)
  end
end

puts digits.reverse.map {|i| i.to_s }.join


n = gets.to_i

ary = [47, 74,
       4477, 4747, 4774, 7447, 7474, 7744]
ary += [4,4,4,7,7,7].permutation(6).collect{|a| a.join.to_i}.uniq
ary += [4,4,4,4,7,7,7,7].permutation(8).collect{|a| a.join.to_i}.uniq

ary.each do |i|
  if i >= n
    puts i
    break
  end
end


def answer(num)
  ret = []
  counts = Hash.new(0)
  num.each_char.with_index do |c, index|
    i = c.to_i
    case i
    when 4,7
      if counts[c] == num.size / 2 && c == '4'
        c = '7'
      end
      if counts[c] < num.size / 2
        ret << c
        counts[c] += 1
        next
      end
    when 0..3
      if counts['4'] == num.size / 2
        ret << '7'
        counts['7'] += 1
      end
      ret << '4' * (num.size / 2 - counts['4'])
      ret << '7' * (num.size / 2 - counts['7'])
      return ret.join
    when 5,6
      if counts['7'] < num.size / 2
        ret << '7'
        counts['7'] += 1
        ret << '4' * (num.size / 2 - counts['4'])
        ret << '7' * (num.size / 2 - counts['7'])
        return ret.join
      end
    when 8,9
      if index == 0
        size = (num.size + 2) / 2
        return ('4' * size) + ('7' * size)
      end
    end
    if n = ret.slice(0...index).rindex('4')
      ret[n] = '7'
      ret << '4'
      counts['4'] += 1
    else
      size = (num.size + 2) / 2
      return ('4' * size) + ('7' * size)
    end
  end
  ret.join
end

num = gets.strip
if num.size % 2 == 1
  size = (num.size + 1) / 2
  puts '4' * size + '7' * size
else
  puts answer num
end


def answer(num)
  ret = []
  counts = Hash.new(0)
  num.each_char.with_index do |c, index|
    i = c.to_i
    case i
    when 4,7
      if counts[c] == num.size / 2 && c == '4'
        c = '7'
      end
      if counts[c] < num.size / 2
        ret << c
        counts[c] += 1
        next
      end
    when 0..3
      if counts['4'] == num.size / 2
        ret << '7'
        counts['7'] += 1
      end
      ret << '4' * (num.size / 2 - counts['4'])
      ret << '7' * (num.size / 2 - counts['7'])
      return ret.join
    when 5,6
      if counts['7'] < num.size / 2
        ret << '7'
        counts['7'] += 1
        ret << '4' * (num.size / 2 - counts['4'])
        ret << '7' * (num.size / 2 - counts['7'])
        return ret.join
      end
    when 8,9
      if index == 0
        size = (num.size + 2) / 2
        return ('4' * size) + ('7' * size)
      end
    end
    while n = ret.pop
      counts[n] -= 1
      if n == '4'
        ret << '7'
        counts['7'] += 1
        ret << '4' * (num.size / 2 - counts['4'])
        ret << '7' * (num.size / 2 - counts['7'])
        return ret.join
      end
    end
    size = (num.size + 2) / 2
    return ('4' * size) + ('7' * size)
  end
  ret.join
end

num = gets.strip
if num.size % 2 == 1
  size = (num.size + 1) / 2
  puts '4' * size + '7' * size
else
  puts answer num
end


a,b,c = gets.split.map(&:to_i)
puts [a*b*c, a+b+c, (a+b)*c, a+b*c, a*(b+c), a*b+c].max


(a,b,c) = gets.chomp.to_i,gets.chomp.to_i,gets.chomp.to_i
puts [a+b*c , (a+b)*c , a*(b+c) , a*b*c].max


a = gets.to_i
b = gets.to_i
c = gets.to_i
best = [a+[b+c,b*c].max,a*b*c,(a+b)+c].max
puts best


def solve
  a,b=read_ints;
  b.times do
      if(a%10!=0)
          a-=1
      else
        a=a/10
      end
  end
  puts a
end

def read_int
  gets.split(" ");
end

def read_ints
  gets.split.map(&:to_i);
end
100000000.times do
end
solve


puts "enter n"
n=gets.chomp().to_i
puts "enter k"
k=gets.chomp().to_i
i=1
while i<=k

  if n%10==0
     n=n/10
  else
      n=n-1
  end
    i=i+1
end
puts(n)


input = gets
n, k = input.split(" ")
k.times do
    if n % 10 == 0
        n = n / 10
    else
        n -= 1
    end
end
puts n


$a = gets.chomp
$a = $a.to_i
$b = gets.chomp
$b = $b.to_i

(0...$b).each do |i|
	if $a%10 == 0
		$a = $a/10
	else
		$a -= 1
	end
end
print $a;


def subtract(n, k)
  result = 0
  (1..k).each do |number|
    if n % 10 != 0
      n -= 1
    else
      n /= 10 if n % 10 == 0
    end
    result = n
  end
  puts result
end

a = gets
n = a.split(' ').first
k = a.split(' ').last
subtract(n, k)


c=gets.chomp.split(" ").map {|i| i.to_i}
n=c[0]
a=c[1]
b=c[2]
ans=0
if b==0
puts "#{a}"
elsif b>0
ans=((b%n)+a)%n
if ans==0
puts "#{n}"
else
puts "#{ans}"
end
elsif b<0
ans=(6-(b.abs%n)+a)%n

if ans==0
puts "#{n}"
else
puts "#{ans}"
end
end


n,a,b=gets.chomp.split(" ").map(&:to_i)
c=a+b-1
if c>n
  c=c%n
elsif c<0
  while c<0
    c+=n
  end
end
puts c+1


n, a, b = gets.split(" ").map(&:to_i)
puts (b % n + a) % n


#include <map>
#include <set>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <bitset>
#include <fstream>
#include <sstream>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define li        long long int
#define rep(i,to) for(li i=0;i<((li)(to));++i)
#define pb        push_back
#define sz(v)     ((li)(v).size())
#define bit(n)    (1ll<<(li)(n))
#define all(vec)  (vec).begin(),(vec).end()
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define MP        make_pair
#define F         first
#define S         second

int main(){
	for(li pos=2;pos<120;pos+=2){ cout<<pos<<" "; } cout<<endl;
}


l,b,r = gets.split(" ").map(&:to_i)
d = r * 2
ans = true
ans = false if r > [l,b].min
# x = 0
# y = 0

# count = 0
# left_x = d
# right_x = l - d
# top_y = d
# bottom_y = b - d

# while true
# 	while x + d <= l
# 		break if (x >= left_x && x <= right_x && y >=top_y && y <= bottom_y)
# 		count += 1
# 		x += d
# 	end
# 	y += d
# 	break if y + d > b
# 	x = 0
# end
# puts "#{count}"
puts ans ? "First" : "Second"


a = gets
min=a[2]>a[0]?a[0]:a[2]
puts a[4]*2>min ? "Second":"First"


p = gets
s, e, t = p.split.map
a = s.to_i
b = e.to_i
r = t.to_i
r *= 2
if a >= r && b >= r
puts "First"
else
puts "Second"
end


n = gets.to_i
fs = [1,1,1,1,1]
(n-1).times do
  t = []
  f = 0
  (0..4).each do |i|
    f += fs[i]
    t << f
  end
  fs = t
end
puts fs.max


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

cut = Array.new(n*2+1, 0)
cut[a] = 1
cut[b] = 1
cut[c] = 1

for i in 1..n
  if cut[i] != 0
    cut[a+i] = [cut[a+i], cut[i]+1].max
	cut[b+i] = [cut[b+i], cut[i]+1].max
	cut[c+i] = [cut[c+i], cut[i]+1].max
  end
end

puts cut[n]


n, a, b, c, = gets.chomp.split(/ /).map(&:to_i)
cuts = [a, b, c]
dp = Array.new(4000, 0)
cuts.each do |cut|
    dp[cut] = [dp[cut], 1].max
    ((cut + 1)..n).each do |j|
        if dp[j - cut] > 0
            dp[j] = [dp[j], 1 + dp[j - cut]].max
        end
    end
end
puts dp[n]


n, A, B, C = gets.split(' ').map { |x| x.to_i }
H = Hash.new
f = ->(n) {
  if n <= 0 then return n end
  if H[n] != nil then return H[n] end
  t = [f[n-A], f[n-B], f[n-C]].max
  if t >= 0 then H[n] = t + 1 else return -1 end
  return H[n]
}
p f[n]


n,a,b,c = gets.split(' ').map(&:to_i)
A = [a,b,c].sort {|x,y| y <=> x}
H = Hash.new
def solve(k)
  if k <= 0 then return k end
  if H[k] != nil then return H[k] end
  t = A.map {|x| solve(k-x)}.select {|x| x >= 0}
  if t.size > 0 then return H[k] = t.max+1 else return -1 end
end
puts solve(n)


n = ARGV[0].to_i
pieces = ARGV.slice(1, 4).map(&:to_i).sort

def count2(n, pieces)
	i = 0
	while pieces[i] && n != 0 && n >= pieces[i]
		piece = pieces[i]
		i += 1
		return 1 if (n - piece == 0)
		next if (n - piece < piece)

		c = count(n - piece, pieces)
		next if c == 0
		return c + 1
	end
	return 0
end

p count2 n, pieces


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

def count2(n, pieces)
	i = 0
	while pieces[i] && n != 0 && n >= pieces[i]
		piece = pieces[i]
		i += 1
		return 1 if (n - piece == 0)
		next if (n - piece < piece)

		c = count2(n - piece, pieces)
		next if c == 0
		return c + 1
	end
	return 0
end

p count2 n, pieces.sort


# Extract valid 2 element summations
def get_valid_pairs(dpa, i)
    pairs = []
    for j in 0..((i/2).floor) do
        if dpa[j] != -1 && dpa[i-j] != -1
            pairs.push([j, i-j])
        end
    end
    return pairs
end

# Find the best solution for i
def get_result(dpa, i)
    pairs = get_valid_pairs(dpa, i)
    best = -1
    for j in 0..(pairs.length - 1) do
        ans = dpa[pairs[j][0]] + dpa[pairs[j][1]]
        best = ans if ans > best
    end
    return best
end

# Read Input
n, a, b, c = gets.strip.split.map{|s| s.to_i}

# Initialize params
dpa = Array.new(n+1,-1); dpa[0] = 0; dpa[a] = 1; dpa[b] = 1; dpa[c] = 1;

# Iterate over values 0 to n to fill dp array
for i in 0..(n) do
    dpa[i] = get_result(dpa, i)
end

# Return solution
puts dpa.last


n, a, b, c = gets.split.map(&:to_i)
max = 1
arr = [a, b, c].sort.uniq
if n % arr[0] == 0
  p n/arr[0]
else
  arr[2] ||= 0
  i = n/arr[2]
  j = n/arr[1]
  (0..i).each do |i|
    (0..j).each do |j|
      temp = n - i*arr[2] - j*arr[1]
      next if temp < 0
      if temp % arr[0] == 0
        max = (i + j + temp/arr[0]) if (i + j + temp/arr[0]) > max
      else
        next
      end
    end
  end
  p max
end


n = gets.to_i
t = 1
while n%t==0
    t *= 3
end
ans = n/t+n%t
puts ans


red, green, blue = gets.split.map(&:to_i)

answer = (red + green + blue) / 3

puts answer


PLAYERS = %w[F M S]
RANKS   = %w[rock paper scissors]

def winner?(g1, g2)
  r1 = RANKS.rindex(g1)
  r2 = RANKS.rindex(g2)
  return true  if r1 == 0 and r2 == 2
  return false if r1 == 2 and r2 == 0
  return true  if r1 > r2
  false
end

gestures = []
3.times { gestures << STDIN.gets.chomp }
winners = []

gestures.each_index do |i|
  gestures.each_index do |j|
    g1, g2 = gestures[i], gestures[j]
    next if g1 == g2
    winners << PLAYERS[i] if winner?(g1, g2)
  end
end

p winners
puts (winners.uniq.count == 1) ? winners[0] : "?"


mappings = {"paper" => 0, "scissors" => 1, "rock" => 2}
names = ["F", "M", "S"]
g = []
3.times do
  g << mappings[gets.strip]
end
sum = eval g.join('+')
puts case sum
  when 0, 2, 3, 5, 6
    "?"
  when 1
    names[g.index(1)]
  when 4
    names[g.index(0)]
end


def rps a, b, c
	h = {:rock => :scissor, :scissor => :paper, :paper => :rock}
	return 1 if h[a] == b && h[a] == c
	return 2 if h[b] == a && h[b] == c
	return 3 if h[c] == a && h[c] == b
	return 0
end

a, b, c = STDIN.read.split("\n").map(&:to_sym)
p = %w{? F M S}

print p[rps(a, b, c)]


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

week = [a / 3, b / 2, c / 2].min

la = a - 3 * week
lb = b - 2 * week
lc = c - 2 * week

list = %w(a a b c a c b) * 2
max_remain = 0

(1..6).each do |d|
  ((7 - d)..7).each do |s|
    counter = Hash.new(0)

    (s...(s + d)).each do |t|
      counter[list[t]] += 1
    end

    if counter['a'] <= la && counter['b'] <= lb && counter['c'] <= lc
      max_remain = d
    end
  end
end

puts 7 * week + max_remain


n,d=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)
m=gets.to_i
res=0
a.each{|v| res+=v }
puts res-d*[0,m-n].max


n,d=gets.split.map(&:to_i)
a=gets.split.map(&:to_i).sort
m=gets.to_i
res=0
m.times {|i| res+=a[i] }
puts res-d*[0,m-n].max


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)
notfound = true
for i in [x-1000000, 0].max..x
  if i**2 + s(i)*i - n == 0
    print i
    notfound = false
    break
  end
end

print -1 if notfound


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


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


s = gets.chomp.split

if s[2] == "month"
	if s[0].to_i == 30
		print 11
	elsif s[0].to_i == 31
		print 7
	elsif s[0].to_i == 29
		print 11
	else
		print 12
	end
else
	if s[0].to_i != 5 && s[0].to_i != 6
		print 52
	else
		print 53
	end
end


class Solver
	def main
		f = gets.split
		x = f[0].to_i
		type = f[-1]
		if type == "week"
			if x.between? 5, 6
				puts 53
			else
				puts 52
			end
		else
			ans = 12
			ans -= 1 if x > 28
			ans -= 4 if x > 30
			puts ans
		end
	end
end
Solver.new.main


#! /usr/bin/ruby

n = gets.to_i
cards = gets.split(" ")

def card_compare( a, b )
  if a[0] == b[0] or a[1] == b[1]
    return true
  end
  return false
end

def f( a )
  if a.length == 1
    return true
  end
  ###------------------------------------
  if card_compare( a[0], a[1] )
    b = a
    b[1] = b[0]
    b.shift
    if f( b )
      return true
    end
  end
  ###------------------------------------
  if a.length >= 3
    if card_compare( a[0], a[3] )
      b = a
      b[3] = b[0]
      b.shift
      if f( b )
	return true
      end
    end
  end
  return false
end

if f( cards.reverse! )
  puts "YES"
else
  puts "NO"
end


#! /usr/bin/ruby

$n = gets.to_i
$cards = gets.split(" ")

def card_compare( a, b )
  a[0] == b[0] or a[1] == b[1]
end

def ff( a, i )
  a[i] = a[0]
  a.shift
  return a
end

def f( a )
  if a.length == 1
    return true
  #####################
  if card_compare( a[0], a[1] )
    b = a.clone
    b = ff( b, 1 )
    if f( b )
      return true
    end
  end
  #####################
  if a.length > 3
    if card_compare( a[0], a[3] )
      b = a.clone
      b = ff( b, 3 )
      if f( b )
	return true
      end
    end
  end
  #####################
  return false
end

if f( $cards.reverse! )
  puts "YES"
else
  puts "NO"
end


#! /usr/bin/ruby

$n = gets.to_i
$cards = gets.split(" ")

def card_compare( a, b )
  a[0] == b[0] or a[1] == b[1]
end

def ff( a, i )
  a[i] = a[0]
  a.shift
  return a
end

def f( a )
  if a.length == 1
    return true
  end
  #####################
  if card_compare( a[0], a[1] )
    b = a.clone
    b = ff( b, 1 )
    if f( b )
      return true
    end
  end
  #####################
  if a.length > 3
    if card_compare( a[0], a[3] )
      b = a.clone
      b = ff( b, 3 )
      if f( b )
	return true
      end
    end
  end
  #####################
  return false
end

if f( $cards.reverse! )
  puts "YES"
else
  puts "NO"
end


#f = File.open("b.in")
@n = gets.to_i
@a = gets.split

def doit(b, k, c)
   return true if c == 1
   return false if c == 0
   r = false

   (k - 1).downto(0) { |i|
      if b[k][0] == b[i][0] or b[k][1] == b[i][1]
         d = b.dup
         d[i] = d[k]
         r = r | doit(d, k - 1, c - 1)
      end
   }

   return r
end

r = doit(@a, @n - 1, @n)
puts "YES" if r
puts "NO" if not r


vp,vd,t,f,c=gets.to_i,gets.to_i,gets.to_i,gets.to_i,gets.to_i
if vp>vd then
        puts 0
        exit
end
time=Rational(t,1)
for ans in 0..100000
        #t*vp+time*vp=(vd-vp)*t
        #t*(vp-vd)=-vp*time
        tmp=Rational(-vp*time,vp-vd)
        #p [tmp,vp,vd]
        if tmp+time>=Rational(c,vp) then
                puts ans
                exit
        end
        time+=tmp*2+f
end


u, v, t, f, c = 5.times.map{gets.to_f}
d, ans = u * t, 0

if v > u
    loop do
        d += d / (v - u) * u
        break if d >= c
        d += (d / v + f) * u
        k += 1
    end
end
p ans