def run
  h, n = $stdin.gets.split.map(&:to_i)
  answer = solve(h, n, 0, true)
  puts answer
end

def solve(h, n, sum, is_move_left)
  return sum if h == 0

  left_all_nodes  = (2 ** h) - 1
  left_leaf_nodes = 2 ** (h - 1)

  if n > left_leaf_nodes && is_move_left == true
    solve(h - 1, n - left_leaf_nodes, sum + left_all_nodes + 1, true)
  else
    solve(h - 1, n, sum + 1, !is_move_left)
  end
end

run if $0 == __FILE__


k, n = gets.chomp.split.map{|i| i.to_i}
m, ans, offset, flag = 2 ** k, 0, 0, false
while m != 1
  m /= 2
  if flag ^ (offset + m >= n)
    ans += 1
    flag != flag
    offset += m unless flag
  else
    ans += 2 * m
    offset += m unless flag
  end
end
puts ans


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

n.times.each do |_|
	a << gets.chomp.to_i
end

puts "#{(((a.reduce(&:+) + m) * 1.0)/n).ceil} #{a.max + m}"


n = gets.to_i
m = gets.to_i

maxa = 0
suma = 0

n.times do
    ai = gets.to_i
    maxa = ai if ai > maxa
    suma += ai
end

mink = ((suma + m).to_f / n).ceil
maxk = maxa + m

puts "#{mink} #{maxk}"


def matches(a,b,dx,dy,ft,gt)
  if dx == 0
    return false unless a - ft == 0
  end

  if dy == 0
    return false unless b - gt == 0
  end
  return true if dx == 0 and dy == 0

  if dx != 0
    l1 = (a - ft) % dx
    l3 = ((a - ft)/dx > 0)
    x5 = (a - ft)/dx
  else
    l1 = (a - gf == 0)
    l3 = l3
    x5 = 0
  end

  if dy != 0
    l2 = (b - gt) % dy
    l4 = ((b - gt)/dy > 0)
    x6 = (b - gt)/dy
  else
    l2 = (b - gt == 0)
    l4 = l4
    x6 = 0
  end
  return (l1 and l2 and l3 and l4 and (x5 == x6))
end

def pair(x)
  return [0,1] if x == "U"
  return [0,-1] if x == "D"
  return [-1,0] if x == "L"
  return [1,0] if x == "R"
  return [0,0]
end

def build(mov)
  moves = [[0,0]]
  mov.split(//).each_with_index do |x|
    p = pair(x)
    moves << [moves.last[0] + p[0], moves.last[1] + p[1]]
  end
  {:dx => moves.last[0] - 0, :dy => moves.last[1] - 0, :moves => moves}
end

def run(mov,a,b)
  f = build(mov)
  dx = f[:dx]
  dy = f[:dy]
  f[:moves].each do |x|
    return "Yes" if matches(a,b,dx,dy,x[0],x[1])
  end
  return "No"
end

pairs = []
STDIN.read.split("\n").each_with_index do |line,i|
  pairs = line.split(" ") if i % 3 == 0
  puts run(line,pairs[0].to_i,pairs[1].to_i) if i % 3 == 1
end


n,m=gets.split(' ')
k=n
days=0
while k>0
  days+=1
  k=k-1
  if days % m == 0
    k=k+1
  end
end
puts days


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

x=(m*n)/(m-1)
if (x==n+x/m)
    puts x
else
    puts x-1
end


n = gets.to_i
d = []
n.times do |i|
    d.push(gets.split.map(&:to_i))
end
foo = []
1.upto((1 << n)-1) do |i|
    hoge = []
    n.times do |j|
        if (i & (1 << j)) > 0
            hoge.push(j)
        end
    end
    hoge.permutation.to_a.each do |arr|
        (6 ** arr.size).times do |j|
            tmp = 0
            arr.size.times do |k|
                idx = j % 6
                j /= 6
                tmp *= 10
                tmp += d[arr[k]][idx]
            end
            foo.push(tmp)
        end
    end
end
foo.uniq!.sort!
if foo[0] == 0
    foo.shift
end
ans = 0
idx = 0
loop {
    if foo[idx] == ans + 1
        ans += 1
        idx += 1
    else
        break
    end
    }
puts ans


def pos(n)
  bbt = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
  i = 1
  while n > 5*i
    n -= 5*i
    i*= 2
  end
  return bbt[-(-n / i) - 1]
end

n = gets.split.map &:to_i;
p pos(n)


#n = 10010
n = gets.to_i

#1 => Sheldon
#5 => Howard
#10 => Penny
#534 => Rajesh
#1802 => Penny
#5033 => Howard
#10010 => Howard

line = ['Sheldon', 'Leonard', 'Penny', 'Rajesh', 'Howard']

res = nil
i = 1
#puts i
k = n
#puts k
if n > 5
  i_n = 5
  until i_n <= n
    i += 1
    i_n += (2**i)*5
  end
  new_line = line.map{|a| [a]*(i + 1)}.flatten
  #puts new_line
  #puts n, i_n
  k = n - i_n
  k.times do
    res = current = new_line.shift
    2.times {new_line.push current}
  end
else
  res = line[k - 1]
end

puts res


def f(n)
	s = "01234"
	for i in (1...n)
		s = s[1..-1] + s[0] * 2
	end

	return s[0]
end

case f(gets.to_i).to_i
	when 0
		puts "Sheldon"
	when 1
		puts "Leonard"
	when 2
		puts "Penny"
	when 3
		puts "Rajesh"
	when 4
		puts "Howard"
end


m = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
n = gets.to_i
x = ""; rate = 1
while x.size <= n do
    5.times do |i|
        x += i.to_s * rate
    end
    rate *= 2
end
puts m[x[n-1].to_i]


m = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
n = gets.to_i
num = 5
count = 0
i = 0
while true
    i += 1
    break if i >= n
    if count+1 == num
        count = 0
        num *= 2
    else
        count += 1
    end
end
puts m[count / (num/5)]


n = gets.to_i
a = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
z = []
t = 1
c = 0
loop do
	5.times do |i|
		t.times do
			z.push a[i]
			c += 1
		end
	end
	t *= 2
	break if c >= n
end
puts z[n-1]


a = gets.to_i
names = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
i = 1
while i < a
	names.push(names.first)
	names.push(names.first)
	names.shift
	i += 1
end

puts names.first


n = gets.chomp.to_i

if (n <= 5)
  puts ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"][n - 1]
else
  i = 5
  while n >= i do
    n -= i
    i = i << 1
  end
end
puts ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"][(n/(i/5))]


class Integer
  def divisers
    n=self
    res = []
    res << 1
    i=1
    while i*i <= n
      if n%i==0
        res << i
        res << n/i if i*i!=n
      end
      i+=1
    end
    res.sort!
  end
end

def solve n,m,k
  ds = n.divisers
  if n-1+m-1<k
    return -1
  end
  ans=0
  for w1 in ds
    k1=n/w1-1
    k2=k-k1
    if 0<=k1 && k1<=k && 0<=k2 && k2<=k
      w2=m/(k2+1)
      ans = [ans, w1*w2].max
    end
  end
  ans
end

n,m,k = gets.chomp.split.map{|i|i.to_i}
puts [solve(n,m,k),solve(m,n,k)].min


a = gets.split.map(&:to_i)
ans = 0
i = 0
3.times do
  ans += a[i] * a[i + 1] * 2
  i += 2
end
b = a.uniq.sort
ans += (b[1] - b[0]) * (b[1] - b[0]) unless b.size == 1 || a[0] == a[3]
puts ans


n, k = gets.split.map(&:to_i)
arr = gets.split.map(&:to_i)
if arr[k] == 0
  p 0
else
  t = arr[k]
  num = 0
  arr.each do |arr|
    if arr >= t
      num += 1
    end
  end
  p num
end


n = gets.split(' ')
array = gets.split(' ')
countof = 0
array.each do
  |i|
  if ((i.to_i > 0) && (i.to_i > array[n[1].to_i]))
    countof += 1
  end
end
puts countof


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

i = 0
while i < n do
  a[i] = gets.to_i
  i += 1
end

i = 0
ans = 0
while i < n do
  if a[i] >= a[k - 1] && a[i] > 0
    ans += 1
  end
  i += 1
end

puts ans


temp = gets.split
n = temp[0].to_i
k = temp[1].to_i
temp = gets.split
temp.sort!{|x, y| y.to_i <=> x.to_i}
t = temp[k-1].to_i
puts temp {|x| x.to_i >= t && x.to_i > 0}


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

arr = arr.select { |n| n >= arr[k] }
arr = arr.reject { |n| n <= 0 }

puts arr.length


input1 = gets.chomp
input2 = gets.chomp

int_input1 = input1.split(" ").map(&:to_i)
int_input2 = input2.split(" ").map(&:to_i)

num = int_input2[int_input1[1]]
count = 0
int_input2.each do |i|
  if i >= num && i>0
    count= count+1
  end
end

puts count


conf = gets.split(' ').collect &:to_i
vars = gets.split(' ').collect &:to_i
k = vars[conf[1]]

k = 1 if k < 1
result = vars.select{|v|
    true if v >= k
}
puts result.size


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

goal = a[k - 1]
i = 0
while a[i] >= goal && a[i] > 0
  i += 1
end

puts i


n, k = gets.chomp.split(' ').map(&:to_i)
a = gets.chomp.split(' ').map(&:to_i)
a_k = a[k]

count = 0
a.each do |a_i|
  count += 1 if a_i > 0 && a_i >= a_k
end
puts count


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

# binary search
# puts (0...n).bsearch { |i| arr[i] < arr[k] && arr[i]}

arr.select! { |i| i >= arr[k] && i > 0}

puts arr.size


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

count = 0
series.each do |number|
  count += 1 if number > 0 && number >= series[numbers.last]
end
puts count


n,limit = gets.chomp().split(" ")
pass = 0
limit = limit.to_i
score = gets.chomp.split(" ")
score.each { |x|
  if x.to_1 >= limit
    pass = pass+1
  end
}
puts pass


k = gets.split[1].to_i
scores = gets.split.map{|e| e.to_i }

t = scores[k]
t = 1 if t == 0

puts scores.count{|e| e >= t}


def ptstr(x, y, h)
	p = x.to_s + " " + y.to_s
	if h.key?(p)
		h[p] += 1
	else
		h[p] = 1
	end
end

ret = true
ar = Array.new(4)
h = Hash.new
xlcnt = 0
ylcnt = 0
for i in 0..3
	a = gets.chomp.split(/ /).map!{|x| x.to_i}
	a.each{|x| ret = false if x < 0 }
	ret = false if a[0] == a[2] && a[1] == a[3]

	if a[0] == a[2]
		xlcnt += 1
	elsif a[1] == a[3]
		ylcnt += 1
	else
		ret = false
	end
	ptstr(a[0],a[1], h)
	ptstr(a[2],a[3], h)
	ar[i] = a
end

ret = false if xlcnt != 2 || ylcnt != 2
ret = false if h.count != 4
h.each{|key, val| ret = false if val != 2 }

if ret
	puts "YES"
else
	puts "NO"
end


def ptstr(x, y, h)
	p = x.to_s + " " + y.to_s
	if h.key?(p)
		h[p] += 1
	else
		h[p] = 1
	end
end

ret = true
ar = Array.new(4)
h = Hash.new
xlcnt = 0
ylcnt = 0
for i in 0..3
	a = gets.chomp.split(/ /).map!{|x| x.to_i}
	a.each{|x| ret = false if x < 0 }
	ret = false if a[0] == a[2] && a[1] == a[3]

	if a[0] == a[2]
		xlcnt += 1
	elif a[1] == a[3]
		ylcnt += 1
	else
		ret = false
	end
	ptstr(a[0],a[1], h)
	ptstr(a[2],a[3], h)
	ar[i] = a
end

ret = false if xlcnt != 2 || ylcnt != 2
ret = false if h.count != 4
h.each{|key, val| ret = false if val != 2 }

if ret
	puts "YES"
else
	puts "NO"
end


def same(pos, p)
  4.times do | i |
    if pos[i] == p then return i end
    if pos[i] == (p[2..3] + p[0..1]) then return i end
  end
  return -1
end
def solve(pos , xmin, xmax, ymin, ymax)
  ans = Array.new
  ans[0] = same(pos, [xmin, ymin, xmin, ymax])
  ans[1] = same(pos, [xmin, ymin, xmax, ymin])
  ans[2] = same(pos, [xmin, ymax, xmax, ymax])
  ans[3] = same(pos, [xmax, ymin, xmax, ymax])
#  p ans
  ans.sort!
  4.times do |i|
    if ans[i] != i then return false end
  end
  return true
end
xmin = 1000000000
ymin = 1000000000
xmax = 0
ymax = 0
pos = Array.new
4.times do
  data = gets.split.map(&:to_i)
  pos.push(data)
  if xmin > data[0] then xmin = data[0] end
  if xmin > data[2] then xmin = data[2] end
  if xmax < data[0] then xmax = data[0] end
  if xmax < data[2] then xmax = data[2] end
  if ymin > data[1] then ymin = data[1] end
  if ymin > data[3] then ymin = data[3] end
  if ymax < data[1] then ymax = data[1] end
  if ymax < data[3] then ymax = data[3] end
end

if solve(pos, xmin, xmax, ymin, ymax) then
  puts "YES"
else
  puts "NO"
end


def solve?
    rec = []
    hen,shu = 0,0
    xx,yy = [],[]
    4.times{
        x1,y1,x2,y2 = gets.split.map(&:to_i)
        if x1 == x2 then
            shu += 1
            xx << x1
        end
        if y1 == y2 then
            hen += 1
            yy << y1
        end
        rec << [x1,y1,x2,y2]
    }
    return false if shu != 2 || hen != 2
    4.times do |i|
        return false if rec[i][0] == rec[i][2] &&\
        (![rec[i][1],rec[i][3]].include?(yy[0]) ||\
        ![rec[i][1],rec[i][3]].include?(yy[1]))
        return false if rec[i][1] == rec[i][3] &&\
        (![rec[i][0],rec[i][2]].include?(xx[0]) ||\
        ![rec[i][0],rec[i][2]].include?(xx[1]))
    end
    return true
end

puts solve? ? 'YES' : 'NO'


x,y=gets.split.map(&:to_i)
if x > 0 and y > 0
    puts "0 #{x+y} #{x+y} 0"
elsif x > 0 and y < 0
    puts "0 #{x-y} #{x-y} 0"
elsif y > 0
    puts "#{-(y-x)} 0 0 #{y-x}"
else
    puts "#{x+y} 0 0 #{x+y}"
end


$n = gets.to_i - 1
$a = gets.split.map(&:to_i)
$nodes = []

def explode(lv, dir, x, y)
  return if lv > $n
  case dir
  when 'U'
    x1, x2 = x, x
    y1, y2 = y, y
    $a[lv].times do
      x1 -= 1
      y1 += 1
      x2 += 1
      y2 += 1
      $nodes.push([x1, y1])
      $nodes.push([x2, y2])
    end
    explode(lv + 1, 'UL', x1, y1)
    explode(lv + 1, 'UR', x2, y2)

  when 'R'
    x1, x2 = x, x
    y1, y2 = y, y
    $a[lv].times do
      x1 += 1
      y1 += 1
      x2 += 1
      y2 -= 1
      $nodes.push([x1, y1])
      $nodes.push([x2, y2])
    end
    explode(lv + 1, 'UR', x1, y1)
    explode(lv + 1, 'DR', x2, y2)

  when 'D'
    x1, x2 = x, x
    y1, y2 = y, y
    $a[lv].times do
      x1 -= 1
      y1 -= 1
      x2 += 1
      y2 -= 1
      $nodes.push([x1, y1])
      $nodes.push([x2, y2])
    end
    explode(lv + 1, 'DL', x1, y1)
    explode(lv + 1, 'DR', x2, y2)

  when 'L'
    x1, x2 = x, x
    y1, y2 = y, y
    $a[lv].times do
      x1 -= 1
      y1 += 1
      x2 -= 1
      y2 -= 1
      $nodes.push([x1, y1])
      $nodes.push([x2, y2])
    end
    explode(lv + 1, 'UL', x1, y1)
    explode(lv + 1, 'DL', x2, y2)

  when 'UR'
    x1, x2 = x, x
    y1, y2 = y, y
    $a[lv].times do
      y1 += 1
      x2 += 1
      $nodes.push([x1, y1])
      $nodes.push([x2, y2])
    end
    explode(lv + 1, 'U', x1, y1)
    explode(lv + 1, 'R', x2, y2)

  when 'UL'
    x1, x2 = x, x
    y1, y2 = y, y
    $a[lv].times do
      y1 += 1
      x2 -= 1
      $nodes.push([x1, y1])
      $nodes.push([x2, y2])
    end
    explode(lv + 1, 'U', x1, y1)
    explode(lv + 1, 'L', x2, y2)

  when 'DR'
    x1, x2 = x, x
    y1, y2 = y, y
    $a[lv].times do
      y1 -= 1
      x2 += 1
      $nodes.push([x1, y1])
      $nodes.push([x2, y2])
    end
    explode(lv + 1, 'D', x1, y1)
    explode(lv + 1, 'R', x2, y2)

  when 'DL'
    x1, x2 = x, x
    y1, y2 = y, y
    $a[lv].times do
      y1 -= 1
      x2 -= 1
      $nodes.push([x1, y1])
      $nodes.push([x2, y2])
    end
    explode(lv + 1, 'D', x1, y1)
    explode(lv + 1, 'L', x2, y2)

  end
end

x, y = 0, 0
$a[0].times do
  y += 1
  $nodes.push([x, y])
end
explode(1, 'U', x, y)

p $nodes.uniq.size


$n = gets.to_i - 1
$a = gets.split.map(&:to_i)
s = $a.inject(:+)
$map = Array.new(s * 2){Array.new(s * 2)}

def explode(lv, dir, x, y)
  return if lv > $n
  # p "#{lv} #{dir} #{x} #{y}"
  dir_to = [(dir + 1) % 8, (dir - 1) % 8]
  dir_to.each do |d|
    x1, y1 = x, y
    $a[lv].times do |i|
      x1 -= 1 if d > 4 && d != 0
      x1 += 1 if d < 4 && d != 0
      y1 -= 1 if d < 6 && d > 2
      y1 += 1 if d > 6 || d < 2
      $map[x1][y1] = [lv, d, i] if i != $a[lv] - 1
    end
    if $map[x1][y1].nil? || $map[x1][y1] != [lv, d, $a[lv] - 1]
      $map[x1][y1] = [lv, d, $a[lv] - 1]
      explode(lv + 1, d, x1, y1)
    end
  end
  # p $map.inject(0){|sum, x| sum + x.count{|x| !x.nil?}}
end

x, y = s - 1, s
$a[0].times do |i|
  y += 1
  $map[x][y] = [0, 0, i]
end
explode(1, 0, x, y)

p $map.inject(0){|sum, x| sum + x.count{|x| !x.nil?}}


$n = gets.to_i - 1
$a = gets.split.map(&:to_i)
s = $a.inject(:+)
$map = Array.new(s * 2){Array.new(s * 2, nil)}
$dir_from = {
  'U' => ['UR', 'UL'],
  'L' => ['UL', 'DL'],
  'D' => ['DR', 'DL'],
  'R' => ['UR', 'DR'],
  'UR' => ['U', 'R'],
  'UL' => ['U', 'L'],
  'DR' => ['D', 'R'],
  'DL' => ['D', 'L']
}

def explode(lv, dir, x, y)
  return if lv > $n
  $dir_from[dir].each do |d|
    x1, y1 = x, y
    $a[lv].times do |i|
      x1 -= 1 if d.include?('L')
      x1 += 1 if d.include?('R')
      y1 += 1 if d.include?('U')
      y1 -= 1 if d.include?('D')
      $map[x1][y1] = [lv, d] unless i + 1 == $a[lv]
    end
    if $map[x1][y1].nil? || $map[x1][y1] != [lv, d]
      $map[x1][y1] = [lv, d]
      explode(lv + 1, d, x1, y1)
    end
  end
end

x, y = s - 1, s
$a[0].times do
  y += 1
  $map[x][y] = [1, 'U']
end
explode(1, 'U', x, y)

p $map.inject(0){|s, x| s + x.count{|x| !x.nil?}}


gets
arr=gets.split.map(&:to_i)
stack=[]
ans=0
arr.each do |i|
  if stack.size>=2&&stack[-1]<=stack[-2]&&stack[-1]<=i
    if(stack[-2]<i)
      ans+=stack[-2]
    else
      ans+=i
    end
    stack.pop
  end
  stack.push i
end
stack.sort!
stack.pop
stack.pop
stack.each do |i|
  ans+=i
end
p ans


gets
arr=gets.split.map(&:to_i)
stack=[]
ans=0
arr.each do |i|
  while stack.size>=2&&stack[-1]<=stack[-2]&&stack[-1]<=i
    ans+=[stack[-2],i].min
    stack.pop
  end
  stack.push i
end
stack.sort!
stack.each do |i|
  ans+=i
end
p ans-stack[-1]-stack[-2]


n = gets.strip.to_i
a = gets.strip.split.map(&:to_i)
ans = "YES"
i = 0
visited = Array.new(3, false)
while i < n - 1
    prev = a[i]
    i += 1
    curr = a[i]
    if prev < curr
        if !visited[0]
            visited[0] = true
        else
            if visited[1] || visited[2]
                ans = "NO"
                break
            end
        end
    elsif prev == curr
        visited[0] = true if !visited[0]
        if !visited[1]
            visited[1] = true
        else
            if !visited[0] || visited[2]
                ans = "NO"
                break
            end
        end
    else
        visited[1] = true if !visited[1]
        if !visited[2]
            visited[2] = true
        else
            if !visited[0] || !visited[1]
                ans = "NO"
                break
            end
        end
    end
end
puts ans


#!/usr/bin/env ruby

n, m, i, j, a, b = gets.split.map(&:to_i)
best = nil
[[1,m], [n,1], [n,m], [1,1]].each do |corner|
  dx = (i - corner[0]).abs
  dy = (j - corner[1]).abs
  if dx % a == 0 and dy % b == 0
    tx = dx / a
    ty = dy / b
    if tx % 2 == ty % 2
      turn = [tx, ty].max
      if best.nil? or turn < best
        best = turn
      end
    end
  end
end

if best
  puts best
else
  puts "Poor Inna and pony!"
end


a=gets.chomp.split('')
s=0
len=a.length
for i in 0..len-1
	if a[i]=='^'
		break
	end
end
for j in 0..len-1
	if a[j]!='='
		s+=a[j].to_i*(i-j)
	end
end
puts s>0? "left" : s==0? "balance" : "right"


n,m,i,j,a,b = gets.split(" ").map(&:to_i)
corners = [[n,1],[1,m],[n,m],[1,1]]
res = []
# puts "#{corners}"
corners.each do |c|
	dist_a,dist_b = (i - c[0]).abs, (j - c[1]).abs
	if (dist_a % a) == 0 && (dist_b % b) == 0
		turn_a = dist_a / a
		turn_b = dist_b / b
		if (turn_a == turn_b) || ((turn_b - turn_a).abs % 2 == 0)
			if turn_a != turn_b
				if turn_a < turn_b
					next if i + a > n
				else
					next if j + b > m
				end
			end
			res << [turn_a,turn_b].max
		end
	end
end

if res.empty?
	puts "Poor Inna and pony!"
else
	puts res.min
end

# 2,2
# 4,4
# 6,6
# 4,8

# dist_a = 2
# dist_b = 6

# turn_a = 1
# turn_b = 3

# 1,3
# 1,1

# dist_a = 0
# dist_b = 2
# turn_a = 0
# turn_b = 1


(a,b,c) = gets.split.map(&:to_i)
result = ((a-b)*c)/b
puts result.ceil


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


a, b = gets.split.map &:to_i
s = []
while b > a do
	s << b
	if b % 2 == 0 then
		b /= 2
	elsif b % 10 == 1 then
		b /= 10
	end
end
if b == a then
	s << b
	puts 'YES'
	puts (s.reverse.map &:to_s) * ' '
elsif
	puts 'NO'
end


a, b = gets.split.map &:to_i
s = []
while b > a do
	s << b
	if b % 2 == 0 then
		b /= 2
	elsif b % 10 == 1 then
		b /= 10
	end
end
if b == a then
	s << b
	puts 'YES'
	puts s.size
	puts (s.reverse.map &:to_s) * ' '
elsif
	puts 'NO'
end


a = gets.chomp
b = gets.chomp
cnt = Array.new
10.times do |i|
  cnt[i] = a.count(i.to_s)
#  p cnt[i]
end
n = 1
for i in 1..9 do
  if cnt[i] > 0 then
    n = i
    break
  end
end
ans = n.to_s
cnt[n] -= 1
10.times do |i|
  if cnt[i] > 0 then
    cnt[i].times do ans += i.to_s end
  end
end
#p b
#p ans
puts b == ans ? "OK" : "WRONG_ANSWER"


def main
	n=gets.chomp.to_s;
	anss=gets.chomp.to_s;
	ans=anss.to_i;
	ar=[]
	for i in 0...(n.length)
		ar << n[i].chr
	end
	ar=ar.map {|i| i.to_i}
	ar=ar.sort
	i=0;
	while ar[i]==0
		i+=1;
	end
	if ar[0]==0
		ar[0]=ar[i];
		ar[i]=0;
	end
	ca=ar.join("").to_i;
	if n=="0" and ans==0
		puts "OK"
	elsif anss[0].chr=="0"
		puts "WRONG_ANSWER"
	elsif ans==0
		puts "WRONG_ANSWER"
	elsif ca==ans
		puts "OK"
	else
		puts "WRONG_ANSWER"
	end
end

main


count=0
a = gets().chomp().split("").each {|x| (x=='0') ? count+=1 : x.to_i }
a.sort!{|x,y| x<=>y};str=""+a[count].to_s;a.delete(a[count])
a.each {|x| str+=x.to_s}
b=gets().chomp()
#p a,"   ",b
if(str==b)
  print 'OK'
  else print 'WRONG_ANSWER'
end


#!/usr/local/rvm/rubies/ruby-2.3.0/bin/ruby

class Task1
  attr_accessor :phases, :n, :result

  def initialize()
    @n = 0
    @phases = []
    @result = []
  end

  def getData()
    tmp = []
    $stdin.each { |x| (x!="\n") ? tmp.push(x.chomp.split.map { |y| y.to_i }) : nil }
    @n = tmp[0][0]
    @phases = tmp[1]
  end

  def getFileData()
    tmp = []
    file = File.new("test.txt","r")
    file.each { |x| (x!="\n") ? tmp.push(x.chomp.split.map { |y| y.to_i }) : nil }
    file.close
    @n = tmp[0][0]
    @phases = tmp[1]
  end

  def getResult()
    if @phases[@n-1]==0
      puts "UP"
    elsif @phases[@n-1]==15
      puts "DOWN"
    elsif @n==1
      puts -1
    elsif @phases[@n-1]==14 && @phases[@n-2]==15
      puts "DOWN"
    elsif @phases[@n-1]>@phases[@n-2]
      puts "UP"
    elsif
      puts "DOWN"
    end

  end

  # def putsResult()
  #   puts @result.join(' ')
  # end

  def run()
    # getData
    getFileData
    getResult
    # putsResult
  end

end
if __FILE__ == $0
  pc = Task1.new
  pc.run
end


n=gets.to_i
a=gets.split(" ").map(&:tp_i)
if n==1 then
	if a[0]==15
		puts "DOWN"
	elsif a[0]==0
		puts "UP"
	else
		puts "-1"
	end
else
	if a[-2]>a[-1]
		if a[-1]==0
			puts "UP"
		else
			puts "DOWN"
		end
	else
		if a[-1]==15
			puts "DOWN"
		else
			puts "UP"
		end
	end
end


# CodeForces 3C MegaShow 2017.2.12

$arr = [[]]
first_x = second_0 = 0
$first_x_win = $second_0_win = 0

for i in 0..2
    $arr[i] = gets
end

for i in 0..2
    for j in 0..2
        if $arr[i][j] == 'X'
            first_x += 1
        elsif $arr[i][j] == '0'
            second_0 += 1
        end
    end
end

def check_win
    for i in 0..2
        if $arr[i][0] != '.' and $arr[i][0] == $arr[i][1] and $arr[i][0] == $arr[i][2]
            if $arr[i][0] == 'X'
                $first_x_win += 1
            else
                $second_0_win += 1
            end
        end
    end
    for i in 0..2
        if $arr[0][i] != '.' and $arr[0][i] == $arr[1][i] and $arr[0][i] == $arr[2][i]
            if $arr[0][i] == 'X'
                $first_x_win += 1
            else
                $second_0_win += 1
            end
        end
    end
    if $arr[0][0] != '.' and $arr[0][0] == $arr[1][1] and $arr[0][0] == $arr[2][2]
        if $arr[0][0] == 'X'
            $first_x_win += 1
        else
            $second_0_win += 1
        end
    end
    if $arr[0][2] != '.' and $arr[0][2] == $arr[1][1] and $arr[0][2] == $arr[2][0]
        if $arr[0][2] == 'X'
            $first_x_win += 1
        else
            $second_0_win += 1
        end
    end
end

check_win

if $first_x_win > 1 or $second_0_win > 1 or ($first_x_win == 1 and $second_0_win == 1) or
                        first_x - second_0 > 1 or first_x < second_0
    print "illegal\n"
elsif $first_x_win == 1 and $second_0_win == 0
    print "the first player won\n"
elsif $first_x_win == 0 and $second_0_win == 1
    print "the second player won\n"
elsif first_x + second_0 == 9
    print "draw\n"
elsif first_x == second_0
    print "first\n"
elsif first_x - second_0 == 1
    print "second\n"
end


a, b, c = gets.split(" ").map { |s| s.to_i }
x1 = 0
for x2 in 0..10000
	x1_a = c - b * x2
	z = x1_a + x2 *b
	if x1_a % a == 0
		puts "YES"
		f = true
		break
	end
end
unless f
	puts "NO"
end


@a, @b, c = STDIN.read.split(' ').map(&:to_i)

@cache = {}

def is_ok(cc)
  @cache[cc] ||= begin
    if cc == 0
      true
    elsif cc < 0
      false
    elsif @a.even? && @b.even? && cc.odd?
      false
    else
      is_ok(cc - @a) || is_ok(cc - @b)
    end
  end
end

puts(is_ok(c) ? 'Yes' : 'No')


@a, @b, c = STDIN.read.split(' ').map(&:to_i)

@cache = {}

def is_ok(cc)
  return @cache[cc] unless @cache[cc].nil?
  @cache[cc] = begin
    if cc == 0
      true
    elsif (cc < 0) || (@a.even? && @b.even? && cc.odd?) || (cc < @a && cc < @b)
      false
    else
      is_ok(cc - @a) || is_ok(cc - @b)
    end
  end
end

puts(is_ok(c) ? 'Yes' : 'No')


ebony = ARGV[0].to_i
ivory = ARGV[1].to_i
shield = ARGV[2].to_i

for i in 0..shield / ebony
	for j in 0..shield / ivory
		if i * ebony + j * ivory == shield
			puts "Yes"
			exit
		end
	end
end

puts "No"


def maybe(nmk)
	if nmk[1] >= nmk[0] || nmk[2] >= nmk[0]
		return "Yes"
	else
		return "No"
	end
end

nmk = gets.chomp.gsub(" ", "")
puts(maybe(nmk))


n, m, k = gets.chomp.split(" ").map(&:to_i)
puts n < m  || n < k ? "No" : "Yes"


n, v = gets.split.map(&:to_i)
ans = fuel = 0
(1..n).each do |i|
    if fuel == 0
        fuel = n >= v ? v : n - 1
        ans += fuel * i
        next
    end
    if n - i >= v
        fuel += 1
        ans += i
    end
    fuel -= 1
end
puts ans


n,v = gets.split.map(&:to_i)
ans = v
(n-v-1).times do |i|
    ans += i+2
end
puts ans


def run target, left, right, result
  median = [left[0] + right[0], left[1] + right[1]]

  if fract_compare(median, target) == 0
    if median[0] != target[0]
      puts "Impossible"
      return false
    end
    puts string_compress result
    return true
  end

  if median[0] > target[0] || median[1] > target[1]
    puts "Impossible"
    return false
  end

  if fract_compare(median, target) > 0
    result << 'B'
    right[0] = median[0]
    right[1] = median[1]
  else
    result << 'A'
    left[0] = median[0]
    left[1] = median[1]
  end

  run target, left, right, result
end

def fract_compare a, b
  return a[0] * b[1] - a[1] * b[0]
end

def string_compress s
  current_total = 0
  prev = ""
  size = s.size
  result = []
  s.each_with_index do |cur, i|
    if prev == cur
      current_total += 1
    else
      if prev != ""
        result << current_total
        result << prev
      end
      current_total = 1
      prev = cur
    end
    if i == (size - 1)
      result << current_total
      result << prev
    end
  end
  return result.join
end

target = gets.chomp.split(" ").map{ |i| i.to_i }
left = [0, 1]
right = [1, 0]
result = []
run target, left, right, result


def run target, left, right, result
  if target[0] == 1
    print (target[1] - 1), 'B'
    puts
    return true
  end
  if target[1] == 1
    print (target[0] - 1), 'A'
    puts
    return true
  end
  if target[0].gcd(target[1]) > 1
    puts "Imposible"
    return false
  end
  if (target[0] - target[1]).abs == 1
    result = []
    num  = target[0] > target[1] ? target[1] : target[0]
    char = target[0] > target[1] ? 'B' : 'A'
    print 1, (char == 'A' ? 'B' : 'A')
    if num > 1
      print (num - 1), char
    end
    puts
    return true
  end
  while true
    median = [left[0] + right[0], left[1] + right[1]]

    if fract_compare(median, target) == 0
      if median[0] != target[0]
        puts "Impossible"
        return false
      end
      puts string_compress result
      return true
    end

    if median[0] > target[0] || median[1] > target[1]
      puts "Impossible"
      return false
    end

    if fract_compare(median, target) > 0
      result << 'B'
      right[0] = median[0]
      right[1] = median[1]
    else
      result << 'A'
      left[0] = median[0]
      left[1] = median[1]
    end
  end
end

def fract_compare a, b
  return a[0] * b[1] - a[1] * b[0]
end

def string_compress s
  current_total = 0
  prev = ""
  size = s.size
  result = []
  s.each_with_index do |cur, i|
    if prev == cur
      current_total += 1
    else
      if prev != ""
        result << current_total
        result << prev
      end
      current_total = 1
      prev = cur
    end
    if i == (size - 1)
      result << current_total
      result << prev
    end
  end
  return result.join
end

target = gets.chomp.split(" ").map{ |i| i.to_i }
left = [0, 1]
right = [1, 0]
result = []
run target, left, right, result


def run target, left, right, result
  if target[0] == 1
    print (target[1] - 1), 'B'
    puts
    return true
  end
  if target[1] == 1
    print (target[0] - 1), 'A'
    puts
    return true
  end
  if (target[0] - target[1]).abs == 1
    result = []
    num  = target[0] > target[1] ? target[1] : target[0]
    char = target[0] > target[1] ? 'B' : 'A'
    print 1, (char == 'A' ? 'B' : 'A')
    if num > 1
      print (num - 1), char
    end
    puts
    return true
  end
  while true
    median = [left[0] + right[0], left[1] + right[1]]

    if fract_compare(median, target) == 0
      if median[0] != target[0]
        puts "Impossible"
        return false
      end
      puts string_compress result
      return true
    end

    if median[0] > target[0] || median[1] > target[1]
      puts "Impossible"
      return false
    end

    if fract_compare(median, target) > 0
      result << 'B'
      right[0] = median[0]
      right[1] = median[1]
    else
      result << 'A'
      left[0] = median[0]
      left[1] = median[1]
    end
  end
end

def fract_compare a, b
  return a[0] * b[1] - a[1] * b[0]
end

def string_compress s
  current_total = 0
  prev = ""
  size = s.size
  result = []
  s.each_with_index do |cur, i|
    if prev == cur
      current_total += 1
    else
      if prev != ""
        result << current_total
        result << prev
      end
      current_total = 1
      prev = cur
    end
    if i == (size - 1)
      result << current_total
      result << prev
    end
  end
  return result.join
end

target = gets.chomp.split(" ").map{ |i| i.to_i }
left = [0, 1]
right = [1, 0]
result = []
run target, left, right, result


// Problem site: http://codeforces.com/contest/585/problem/C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define INPUT_MAX_LENGTH 16

int max(int a, int b);
void string_compress(char *string);
int fract_compare(char *a[2], char *b[2]);
char *big_sum(char *a, char *b);
char *big_multiply(char *a, char *b);
int big_compare(char *a, char *b);
char *string_reverse(char *a);
char *string_append_zero(char *a, int total);
void try(char *left[2], char *right[2], char *targets[2], char *result);

int main() {
  char *targets[2];
  targets[0] = malloc(INPUT_MAX_LENGTH * sizeof(char));
  targets[1] = malloc(INPUT_MAX_LENGTH * sizeof(char));

  scanf("%s", targets[0]);
  scanf("%s", targets[1]);

  char *left[2];
  left[0] = malloc(INPUT_MAX_LENGTH * sizeof(char));
  left[1] = malloc(INPUT_MAX_LENGTH * sizeof(char));
  strcpy(left[0], "0");
  strcpy(left[1], "1");

  char *right[2];
  right[0] = malloc(INPUT_MAX_LENGTH * sizeof(char));
  right[1] = malloc(INPUT_MAX_LENGTH * sizeof(char));
  strcpy(right[0], "1");
  strcpy(right[1], "0");

  char *result = malloc(max(strlen(targets[0]), strlen(targets[1])) * sizeof(char));
  strcpy(result, "");

  try(left, right, targets, result);

  return 0;
}

char *big_sum(char *a, char *b) {
  int length_a = strlen(a), length_b = strlen(b);
  int i = 0, over = 0, result_length = 0;
  char *result = malloc((length_a + length_b) * sizeof(char));

  while (i < length_a || i < length_b) {
    int current_a = 0, current_b = 0;
    if (i < length_a) {
      current_a = a[length_a - 1 - i] - '0';
    }
    if (i < length_b) {
      current_b = b[length_b - 1 - i] - '0';
    }
    int current = current_a + current_b + over;
    over = current / 10;
    current = current % 10;
    result[result_length] = current + '0';
    result_length++;
    i++;
  }
  if (over > 0) {
    result[result_length] = over + '0';
    result_length++;
  }
  result[result_length] = '\0';

  return string_reverse(result);
}

char *big_multiply(char *a, char *b) {
  int length_a = strlen(a), length_b = strlen(b);
  int i;
  char *total = "0";
  for (i = 0; i < length_b; i++) {
    // Multiply a with b[length_b - 1 - i]
    int current_b = b[length_b - 1 - i] - '0';
    int j, over = 0, sum_length = 0;
    char *sum = malloc((length_a + 1) * sizeof(char));
    for (j = 0; j < length_a; j++) {
      int current_a = a[length_a - 1 - j] - '0';
      int current = current_a * current_b + over;
      over = current / 10;
      current = current % 10;
      sum[sum_length] = current + '0';
      sum_length++;
    }
    if (over > 0) {
      sum[sum_length] = over + '0';
      sum_length++;
    }
    sum[sum_length] = '\0';
    sum = string_reverse(sum);
    sum = string_append_zero(sum, i);
    total = big_sum(total, sum);
  }
  return total;
}

int big_compare(char *a, char *b) {
  if (strlen(a) == strlen(b)) {
    return strcmp(a, b);
  }
  return (strlen(a) > strlen(b)) ? 1 : -1;
}

char *string_append_zero(char *a, int total) {
  int length_a = strlen(a);
  char *result = malloc((length_a + total) * sizeof(char));
  int i;
  for (i = 0; i < length_a; i++) {
    result[i] = a[i];
  }
  for (; i < length_a + total; i++) {
    result[i] = '0';
  }
  return result;
}

char *string_reverse(char *a) {
  int length = strlen(a);
  int middle = length / 2;
  int i;
  char temp;

  for (i = 0; i < middle; i++) {
    temp = a[i];
    a[i] = a[length - 1 - i];
    a[length - 1 - i] = temp;
  }

  return a;
}

void try(char *left[2], char *right[2], char *targets[2], char *result) {
  while (1) {
    char *sum[2] = {big_sum(left[0], right[0]), big_sum(left[1], right[1])};

    if (fract_compare(sum, targets) == 0) {
      if (big_compare(sum[0], targets[0]) != 0) {
        printf("Impossible\n");
      } else {
        string_compress(result);
      }

      return;
    }

    if (big_compare(sum[0], targets[0]) > 0 || big_compare(sum[1], targets[1]) > 0) {
      printf("Impossible\n");

      return;
    }

    long long length = strlen(result);
    if (fract_compare(sum, targets) > 0) {
      result[length] = 'B';
      result[length + 1] = '\0';
      strcpy(right[0], sum[0]);
      strcpy(right[1], sum[1]);
    } else {
      result[length] = 'A';
      result[length + 1] = '\0';
      strcpy(left[0], sum[0]);
      strcpy(left[1], sum[1]);
    }
    result[length + 1] = '\0';
  }
}

int max(int a, int b) {
  return (a > b) ? a : b;
}

void string_compress(char *string) {
  long long length = strlen(string);
  long long i, current_total = 1;
  char prev = string[0], current;
  for (i = 1; i < length; i++) {
    current = string[i];
    if (current == prev) {
      current_total++;
    } else {
      printf("%llu%c", current_total, prev);
      prev = current;
      current_total = 1;
    }
  }
  printf("%llu%c", current_total, prev);
  printf("\n");
}

int fract_compare(char *a[2], char *b[2]) {
  return big_compare(big_multiply(a[0], b[1]), big_multiply(a[1], b[0]));
}


require 'bigdecimal'
a = BigDecimal(gets).to_s('f')

puts (a%1 == 0? a.to_i : a)


input = gets
output = ""
e_index = input.index("e")
d_index = input.index(".")
factor = input[(e_index + 1)..-1].to_i
output = input[0..(e_index-1)]
output[d_index] = ""
factor.times do |i|
  unless output[d_index + i]
    output[d_index + i] = "0"
  end
end
output.insert(d_index + factor, ".") if (d_index + factor) < output.length
puts output


require "byebug"
input = gets
output = ""
e_index = input.index("e")
d_index = input.index(".")
factor = input[(e_index + 1)..-1].to_i
output = input[0..(e_index-1)]
output[d_index] = ""
factor.times do |i|
  unless output[d_index + i]
    output[d_index + i] = "0"
  end
end
output.insert(d_index + factor, ".") if (d_index + factor) < output.length
puts output


Matcher = /(?<int>\d{1})\.(?<float>\d+)e(?<exp>\d+)/
def solve(string)
  res = Matcher.match(string)
  i = res[:int].split("")
  f = res[:float].split("")
  e = res[:exp].to_i
  buf1 = i + f.take(e)
  buf2 = f.drop(e)
  if(buf2.empty?)
    buf4 = buf1.drop_while{|x| x == "0"}
    if(e > f.length)
      buf3 = (0..(e-f.length - 1)).map{ "0" }
      "#{buf4.join("")}#{buf3.join("")}"
    else
      "#{buf4.join("")}"
    end
  else
    buf4 = buf1.drop_while{|x| x == "0"}
    if(buf4.empty?)
      "0.#{buf2.join("")}"
    else
      "#{buf4.join("")}.#{buf2.join("")}"
    end
  end
end

s = gets
# s = "0.01392e2"
puts solve(s)


n = gets.to_i
a = gets.split.map &:to_i
l = a[0]
ans = 0
(1...n).each do |i|
  if l == a[i]
    ans = -1
    break
  end
  case l
  when 1 # circle
    case a[i]
    when 2 # triangle
      ans += 3
    when 3 # square
      ans += 4
    end
  when 2 # triangle
    case a[i]
    when 1 # circle
      ans += 3
    when 3 # square
      ans = -1
      break
    end
  when 3 # square
    case a[i]
    when 1 # circle
      ans += 4
    when 2 # triangle
      ans = -1
      break
    end
  end
  l = a[i]
end
if ans < 0
  puts "Infinite"
else
  puts "Finite"
  puts ans
end


#!/usr/bin/ruby
hodnoty = "6789TJQKA"
trumf = gets.chop.to_s
//puts trumf
cards = gets.chop
//puts cards
c1h = cards[0].chr
c1b = cards[1].chr
c2h = cards[3].chr
c2b = cards[4].chr
if c1b == c2b
	then
		if hodnoty.index(c1h) > hodnoty.index(c2h)
			then
				puts "YES"
			else
				puts "NO"
			end
	end
if c1b != c2b
	then
		if c1b == trumf
			then
				puts "YES"
			else
				puts "NO"
			end
	end


ranks = ["6", "7", "8", "9", "T", "J", "Q", "K", "A"]
trump = $stdin.readline.chop
cards = $stdin.readline.chop.split(' ')
a = cards[0]; b = cards[1]

if cards[0][1] == trump and cards[1][1] != trump then
  puts "YES"
  exit
end

if cards[1][1] == trump and cards[0][1] != trump then
  puts "NO"
  exit
end

if ranks.index(cards[0][0]) > ranks.index(cards[1][0]) then
  puts "YES"
  exit
end

puts "NO"


#!/usr/bin/env ruby

tramp = gets.chomp
first, second = *gets.chomp.split(/ /)

arr = %[6 7 8 9 T J Q K A]

if first[1] == tramp
    puts "YES"
elsif arr.index(first[0]) > arr.index(second[0])
    puts "YES"
else
    puts "NO"
end


def is_able?(n)
  xc = n / $x
  yc = n / $y
  bc = n / $x.lcm($y)
  a_left = [$a - yc - bc, 0].max
  b_left = [$b - xc - bc, 0].max
  a_left + b_left <= n - xc - yc + bc
end

def magic(l, r)
  return l if l == r
  m = (l + r) / 2
  is_able?(m) ? magic(l, m) : magic(m + 1, r)
end

$a, $b, $x, $y = gets.split.map(&:to_i)
p magic(0, 1e10.to_i)


cnt1, cnt2, x, y = gets.chomp.split.map(&:to_i)
a = []
b = []
for i in 1...1000000000
  if i % x != 0 && i % y != 0
    da = cnt1 - a.size
    db = cnt2 - b.size
    if da > db
      a << i
    else
      b << i
    end
  elsif i % x != 0 && a.size < cnt1
    a << i
  elsif i % y != 0 && b.size < cnt2
    b << i
  end
  ans = i
  break if a.size == cnt1 && b.size == cnt2
end
p ans


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

puts '1'+'0'*s.count('0')


n,m,k=gets.split.map(&:to_i)
ans=0
MOD=1000000007
if k==1 || k>n then
        ans=1
        n.times{ ans=(ans*m)%MOD}
        p ans
elsif k % 2==0 then
        p m
elsif k % 2==1
        p m*m
end


Mod = (10**9)+7

def solve n,m,k
  if n == k
    ans = 1
    for i in 0 ... ((n+1)/2)
      ans = ans * m
      ans = ans%Mod
    end
    ans
  elsif k == 1 || n < k
    ans = 1
    for i in 0 ... n
      ans = ans * m
      ans = ans % Mod
    end
    ans
  else
    m
  end
end

while line = gets
  a = line.split
  puts solve(a[0].to_i,a[1].to_i,a[2].to_i)
end


n,x,*a=$<.read.split.map &:to_i
b=[*0...x]-a
p b.size+(a.include?(n)?1:0)


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

set = [[]]
set << gets.split.map(&:to_i) if set[0].size != a
set.flatten!
set.sort!

counter = 0
test = 0
if set.include? q
  for i in set[0]...q
    counter += 1 unless set.include? i
  end
  counter += 1
else
  set << q
  set.sort!
  for i in set[0]...q
    counter += 1 unless set.include? i
  end
end

puts counter


# codeforce#122(Div2.A)
n, k = gets.chomp.split(" ").map{|e| e.to_i}

n.downto(0) do |i|
  if (i * 2 + 5 * (n - i)) >= k and (i * 2 + 3 * (n - i)) <= k
    puts i
    break
  end
end


n, k = gets.split.map(&:to_i)
puts max*3(n-k, 0)


n, k = gets.split.map(&:to_i)
puts max(3*n-k, 0)


n = gets.split
x = n[0].to_i
y = n[1].to_i

loop{
  c = 0
  h = 0

  loop{
    break if x == 0 || c == 200
    c += 100
    x -= 1
  }

  loop{
    break if y == 0 || c == 220
    c += 10
    y -= 1
  }

  if c != 220
    puts "Hanako"
    break
  end

  loop{
    break if x == 0 || h == 200
    h += 100
    x -= 1
  }

  loop{
    break if y == 0 || h == 220
    h += 10
    y -= 1

  }

  if h != 220
    puts "Ciel"
    break
  end

}


cn = gets.split
x = n[0].to_i
y = n[1].to_i

loop{
  c = 0
  h = 0

  loop{
    break if x == 0 || c == 200
    c += 100
    x -= 1
  }

  loop{
    break if y == 0 || c == 220
    c += 10
    y -= 1
  }

  if c != 220
    puts "Hanako"
    break
  end

  loop{
    break if y == 0 || h == 220
    h += 10
    y -= 1
  }

  loop{
    break if x == 0 || h == 200
    h += 100
    x -= 1
  }

  if h != 220
    puts "Ciel"
    break
  end

}


m=[0,0,0]
m[0],m[1],m[2],k=gets.split.map(&:to_i)
ans=[1,1,1]
t=0
tk=k*3
loop {
        break unless k>0
        break unless tk>t

        k-=1 if ans[t%3]<m[t%3]
        ans[t%3]+=1 if ans[t%3]<m[t%3]
        t+=1
}
p ans[0]*ans[1]*ans[2]


m=[0,0,0]
m[0],m[1],m[2],k=gets.split.map(&:to_i)
ans=[1,1,1]
t=0
tk=k*3
tmp=0
loop {
        break unless k>0
        break unless tk>t
        if ans[t%3]<m[t%3] then
                tmp=0
                k-=1
                ans[t%3+=1]
        else
                tmp+=1
        end
        if tmp>4 then break end
        t+=1
}
p ans[0]*ans[1]*ans[2]


def f(v, a, b)
  v<<b if a>0
  f v,a+1,b*10+4 if a<10
  f v,a+1,b*10+7 if a<10
end
k,r,a,b = [],0,gets.split.collect{|x| x.to_i }
f(k,0,0)
k.sort!
0.upto(k.length) do |i|
    if a<=b && a<=k[i]
        r+=([b,k[i]].min-a+1)*k[i]
        a=k[i]+1
    end
end
puts r


n, m = gets.split.map{ |i| i.to_i }
$a = []
def doit(n)
	return if n.to_s.size == 9
	($a << n) if n > 0
	doit(n * 10 + 4)
	doit(n * 10 + 7)
end
doit(0)
c, r = n - 1, 0
$a = $a.sort
$a.each { |i|
	if i >= n
		if i < m
			r += (i - c) * i
		else
			r += (m - c) * i
			break
		end
		c = i
	end
}
puts r


def pow(x, y)
  md = 1000000007;
  if y == 0
    1
  else
    t = pow(x, y/2);
    t = (t * t) % md;
    if y % 2 == 1 then (x * t) % md else t end
  end
end

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

if k == 1
  ans = 0;
else
  ans = ((pow(k, k - 2) * k)% md * pow(n - k, n - k)) % md
end

p ans


n = gets.to_i;
while n > 0
	if n >= 5
		n -= 5;
	elsif n >= 4
		n -= 4;
	elsif n >= 3
		n -= 3;
	elsif n >= 2
		n -= 2;
	else
		n -= 1;
	end;
	c += 1;
end;
print c, "\n";


input = STDIN.read

input =~ /^(\d+) (\d+) (\d+) (\d+)/
a, b, m, r0  = $1.to_i, $2.to_i, $3.to_i, $4.to_i

$values = Array.new

def get_next_value(a, b, m, r)
  (a * r + b) % m
end

$values << get_next_value(a, b, m, r0)

result = 0

while true
  next_value = get_next_value a, b, m, $values.last
  found_index = $values.find_index next_value
  unless found_index.nil?
    result = $values.length - found_index
    break
  end
  $values << next_value
end

puts result


line = $stdin.gets.strip.split(/\s+/)
a = line[0].to_i
b = line[1].to_i
m = line[2].to_i
r0 = line[3].to_i
r = (a*r0+b)%m
while r <= m
  r = a*r + b
end
r = r % m
rr = r
i = 0
loop do
  i += 1
  rr = (a*rr + b) % m
  if rr == r
    puts i
    exit 0
  end
end


t = gets.split.collect{|x| x.to_i}
a,b,m,r0 = t[0], t[1], t[2], t[3]

t = [r0]

while true
	r0 = (a*r0+b)%m

	i = t.find_index(r0)
	if i != nil
		puts (t.size - i)
		break
	end
	t << r0
end


a = Complex(gets.split.map{ |x| Integer(x) })
b = Complex(gets.split.map{ |x| Integer(x) })
c = Complex(gets.split.map{ |x| Integer(x) })

case(((c-a)/(b-a)).polar[1] <=> 0)
when -1
	puts 'RIGHT'
when 0
	puts 'STRAIGHT'
when 1
	puts 'LEFT'
end


a = Complex(*gets.split.map{ |x| Integer(x) })
b = Complex(*gets.split.map{ |x| Integer(x) })
c = Complex(*gets.split.map{ |x| Integer(x) })

case(((c-a)/(b-a)).polar[1] <=> 0)
when -1
	puts 'RIGHT'
when 0
	puts 'STRAIGHT'
when 1
	puts 'LEFT'
end


xa, ya = gets.split.map &:to_i
xb, yb = gets.split.map &:to_i
xc, yc = gets.split.map &:to_i

s = (xb - xa) * (yc - ya) - (yb - ya) * (xc - xa)
puts s==0 ? "TOWARDS" :
  s > 0 ? "LEFT" :
      "RIGTH"


c,v0,v1,a,n=gets.split.map &:to_i
v=v0
i=0
while n>0
n-=v
i+=1
v=v[v+a,v1].min
end
p i


c,v0,v1,a,n=gets.split.map &:to_i
v=v0
i=0
while n>0
n-=v
i+=1
v=[v+a,v1].min
end
p i


c, v0, v1 , a, l = gets.strip.split(' ').map(&:to_i)

cnt = 0
i = 0
total = 0
while true
  break if cnt >= c
  if i == 0
      x = 0
  else
      x = l
  end
  cnt += [(v0 + (i * a) - x), v1].min
  i += 1
end

puts i


puts "/"+gets.strip.split("/").reject!{|str| str== ""}.join("/")


path = gets
while /\/\// =~ path
  path.sub! '/', '/'
end
if path.length > 1 and path[-1] == '/'
  path = path[0..-2]
end
puts path


path = gets
while /\/\// =~ path
  path.sub! '//', '/'
end
if path.length > 1 and path[-1] == '/'
  path = path[0..-2]
end
puts path


(1+gets.to_i).upto(10000)) { |i| if i.to_s.split(//).uniq.length == 4; puts i; break; end; }


n = gets.to_i
ar = (1...n).to_a
puts n + ar.reverse.zip(ar).map{|x,y| x*y}.inject(:+)


x,y,m=gets.split.map(&:to_i)
x,y = y,x if x > y
res = 0
if x < 0 and y > 0 and m > 0
    t = (-x+y-1)/y
    x += t*y
    res += t
end
cnt=0
while y < m
    x,y = y,x+y
    cnt+=1;
    break if cnt > 100
end
puts cnt > 100 ? -1 : res+cnt


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

if x <= 0 and y <= 0
  if [x,y].max < m
    puts -1
  else
    puts 0
  end

  exit
end

res = 0

x = [x,y].min
y = [x,y].max

if x < 0
  res = (x/y).abs
  x += res * y
end

while y < m
  res += 1

  x, y = y, x+y
end

puts res


n,k,x,*a=$<.read.split.map &:to_i
k=n if k>n
p a[0...-k].reduce(:+)+k*x


n, k, x = gets.split.map &:to_i
a = gets.split.map &:to_i
puts (a[0...n-k].inject &:+) + k * x


print 19
exit
a,b = *gets.split.map( &:to_i)

print a + b


a,b = STDIN.readline.split.map{ |x| x.to_i }
print (a+b)%1000


def is_prime( n )

	return false if n % 2 == 0 && n != 2

	div = 3
	while( div * div <= n )
		return false if n % div == 0
		div += 2
	end

	return true;
end

n = gets.chomp.to_i

if is_prime( n )
	puts 1
elsif n % 2 == 0
	puts 2
else
	puts 3
end


MOD = 998_244_353

def edge(v, u)
	cv = cu = 1
	res = 1
	[u, v].min.times do |i|
		cv = cv * (v - i)
		cv %= MOD
		cu = cu * (u - i) / (i + 1)
		cu %= MOD
		res += (cu * cv) % MOD
		res %= MOD
	end
	res
end

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

p (edge(a, b) * edge(b, c) * edge(a, c)).modulo(MOD)


MOD = 998_244_353

def edge(v, u)
	cv = cu = 1
	res = 1
	[u, v].min.times do |i|
		cv = cv * (v - i)
		cu = cu * (u - i) / (i + 1)
		res += (cu * % MOD * cv % MOD) % MOD
		res %= MOD
	end
	res
end

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

p (edge(a, b) * edge(b, c) * edge(a, c)).modulo(MOD)


a,b,c=gets.split.map &:to_i
r=[a,b].min
a-=r
b-=r
r*=2
a+=b
r+=[a,c].min
a-=r
c-=r
p r+c/2*2


l,r,a=gets.split.collect!{|t|t.to_i}
ttl=(l+r+a)
res=0
if l<r
  if l+a<r
    ttl=(l+a)*2
  end
else
  if l>r+a
    ttl=(r+a)*2
  end
end
puts ttl


l, r, a = gets.split.map(&:to_i);
x = [l, r].max;
y = [l, r].min;

if x <= a
  a = a/2 * 2;
  a += y * 2;
  puts (a);
else
  puts ((y+a)*2) if a <= (x-y)
  puts (x*2) if a > (x-y)
end


l, r, a = gets.split.map(&:to_i)
x = [(l - r).abs, a].min
l += x if l < r
r += x if l > r
a -= x
puts 2 * (l + a / 2)


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

input1 = gets.chomp
input2 = gets.chomp

if input1 == input2
  puts "NO"
else
  if input1 == input2.reverse
    puts "YES"
  else
    puts "NO"
  end
end


puts gets.chomp == gets.chomp.reverse ? :NO : :YES


p, q = gets.split.map(&:to_i)

if p**q == q**p
   puts "="
elsif p**q >= q**p
      puts ">"
elsif p**q <= q**p
      puts "<"
end


x,y = gets.split ' '
x = x.to_f
y = y.to_f
if x == y
  puts '='
elsif y/x < Math.log10(y)/Math.log10(x)
  puts '<'
else
  puts '>'
end


input = STDIN.gets.chomp.split(" ")

x = input[0].to_i
y = input[1].to_i

if(x**y == y**x)
	puts "="

elsif(x**y < y**x)
	puts "<"
elsif(x**y > y**x)
	puts ">"
end


a, b = gets.split.map(&:to_i)
aBiggerThanB = a > b
while a != 0 && b != 0
  a -= 2*b if a >= 2*b
  b -= 2*a if b >= 2*a
  break if (a < 2*b && b < 2*a)
end
puts [a, b].join(" ")


#!/usr/bin/ruby
T=[
	'O-|-OOOO',
	'O-|O-OOO',
	'O-|OO-OO',
	'O-|OOO-O',
	'O-|OOOO-',
	'-O|-OOOO',
	'-O|O-OOO',
	'-O|OO-OO',
	'-O|OOO-O',
	'-O|OOOO-',
]
gets.chomp.reverse.chars{|e|puts T[e]}


gets.chomp.split('').map { |x| x.to_i }.reverse.each { |x|
  left = x < 5 ? '0-' : '-0'
  m = x % 5
  right = '0' * m + '-' + '0' * (4 - m)
  puts left + '|' + right
}


n = gets.chomp.to_i
minutes = gets.split.map(&:to_i)
result = 0
if minutes[0] > 15
  result = 15
else
  (0..minutes.size).each do |index|
    if minutes[index] - minutes[index-1] > 15
      result = minutes[index-1] + 15
      break
    end
    #brek if minutes[i] - minutes[i-1] > 15

  end
  result = minutes.last + 15 if result == 0
  result = 90 if result > 90
end

puts result


n, k = gets.strip.split.map(&:to_i)
a = gets.strip.split.map(&:to_i)
ans = curr = 0
n.times do |i|
    curr += a[i]
    given = [curr, 8].min
    curr -= given
    k -= given
    ans += 1
end
ans = -1 if k > 0
puts ans


N, K = gets.split.map &:to_i
A = gets.split.map &:to_i
c = 0
N.times do |i|
  c += A[i]
  K -= [c, 8].min
  c -= [c, 8].min
  (p i + 1; exit) if k <= 0
end
p -1


def calc(n, k, arr)
	total = 0
	count = 0
	arr.each do |x|
		if x <= 8
			total += x
		else
			total += 8
		end
		count += 1
	end
	if total >= k
		return count
	else
		return -1
	end
end
n, k = gets.chomp.split(" ").map(&:to_i)
arr = gets.chomp.split(" ").map(&:to_i)
puts calc(n, k, arr)


n,d=gets.split.map &:to_i
mas=gets.split.map &:to_i
c= (mas.length-1)*10
f=mas.inject(:+)
if c+f >= d
  puts -1
  exit
else
  puts (d-f)/5
end


n, d = gets.split.map &:to_i
t = gets.split.map &:to_i
free_time = d - (t.size - 1) * 10 - t.inject(:+)
puts free_time > 0 ? (t.size - 1) * 2 + free_time / 5 : -1


nd = gets.chomp
nd = nd.split
n = nd[0].to_i
d = nd[1].to_i
songs = gets.chomp
songs = songs.split

song_sum = 0
for i in (0..songs.size-1)
	song_sum += songs[i].to_i
end
if d <= 20 || ((songs.size - 1) * 10) + song_sum > d
	print -1
else
	print (d - song_sum) / 5
end


n,d=gets.split.map(&:to_i)
a=gets.split.map(&:to_i).reduce(&:+)+(n-1)*10
#p a
if a>d
 p -1
else
 p (d-a)/5
end


# Utility
def factorial(n)
  (1..n).inject(:*) || 1
end

# Input
n, m, k = *(gets.split.map { |i| i.to_i })

# Processing
f = factorial(n - 1) / factorial(n - 1 - k)
g = m * (m - 1)**k

result = f * g % 998244353

# Output
puts result


n, l, r, x = gets.split.collect{|i| i.to_i}
c = gets.split.collect{|i| i.to_i}.sort
ans = 0
(2..n).each do |i|
    c.combination(i).each do |cc|
        sum = cc.inject{|sum,ccc| sum+=ccc}
        if sum > r
            break
        elsif sum >= l and cc[-1]-cc[0] >= x
            ans += 1
        end
    end
end
puts ans


x,y,n = gets.split(' ').map{ |e| e.to_i }
if y > n
	z = x.to_f / y
	(1..n).each do |i|
		aa = (i+0.5) * x / y
		diff = (aa / i - z).abs
		if (!min_diff || min_diff > diff)
			min_diff = diff
			a = aa
			b = i
		end
		if min_diff == 0
			break
		end
	end
else
	a = x
  b = y
end

puts "#{a}/#{b}"


x,y,n = gets.split(' ').map{ |e| e.to_i }
a = x
b = y
if y > n
	z = x.to_f / y
	min_diff = nil
	(1..n).each do |i|
		aa = -((-i.to_f * x / y - 0.5).floor) - 1
		diff = (aa.to_f / i - z).abs
		if (!min_diff || min_diff > diff)
			min_diff = diff
			a = aa
			b = i
		end
		if min_diff == 0
			break
		end
	end

end

puts "#{a}/#{b}"


x, y, n = gets.split(' ').collect!{|i| i.to_i}

k = x.to_f/y
# p k
a = 0
b = 0
min = 100000

(1..n).each do |i|
	j = (k*i).round.to_i
	cur = (k - j/i.to_f).abs
	# p j if j == 38236
	# p i if j == 38236
	# p j/i.to_f if j == 38236
	if cur < min
		a = j
		b = i
		min = cur
	end

end

print a, "/", b


x,y,n = gets.split(" ").map(&:to_i)
if y <= n
	puts "#{x}/#{y}"
else
	min_diff = n
	given_div = x/y.to_f
	val1 = nil
	val2 = nil
	(0..(n)).each do |a|
		n.downto(0) do |b|
			div = (a/b.to_f)
			# puts "a #{a} b #{b} #{div} #{min_diff}"
			if  (given_div - div).abs < min_diff
				val1 = a
				val2 = b
				min_diff = (given_div - div).abs
			end
		end
	end
	puts "#{val1}/#{val2}"
end


n, m, k = gets.strip.split.map(&:to_i)
pos = k.odd? ? "L" : "R"
col_sum = m * 2
mod = k % col_sum
mod += 1 if k.odd?
desk = (mod / 2).ceil
desk = m if mod == 0
lane = (k + mod) / col_sum
puts "#{lane} #{desk} #{pos}"


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

puts res


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


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


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


intended = STDIN.readline.strip
received = STDIN.readline.strip
target = intended.count('+') - intended.count('-')
origin = received.count('+') - received.count('-')
steps = received.count('?')
location = { origin => 1.0 }
steps.times do
	next_location = Hash.new(0.0)
	location.each do |x, p|
		next_location[x-1] += p/2
		next_location[x+1] += p/2
	end
	location = next_location
end
puts location[target]


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


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


PEARL = 'o'
LINK = '-'

necklace = STDIN.gets.chomp

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

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


PEARL = 'o'
LINK = '-'

necklace = STDIN.gets.chomp

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

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


n = gets.chomp.to_i
sum, sign = 0, false
n.times do |t|
	sign ? sum += (t+1) : sum -= (t+1)
	sign = !sign
end
puts sum


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

sum = 0
for i in 1..n
 if i%2 == 0
     p[i] = i
 else
     p[i] = -i
 end
 sum = sum + p[i]
end
puts sum


n = gets.chop.to_i
i = 1
count = 0
sum = 0
while i<=n do
    if count==0
        sum = sum-i
        count =1
    elsif count ==1
        sum+= i
        count =0

    end
    i+=1
end
puts sum


n = gets.to_i
sum = 0
(1..n).step(1) do |x|
  sum += (-1) ** x * x
end
puts sum


input = gets.chomp
n = input.to_i
f = 0
(1..n).each do |i|
  f += ((-1) ** i) * i
end
puts f


n = gets.chomp.to_i

i = 1
count = 0
while i <= n
	if i%2 == 0
		count += i
	else
		count-= i
	end
	i += 1
end

puts count


#!/usr/bin/ruby

n = gets.chomp.to_i

sum = 0
(1..n).each do |i|
    i *= -1 if i % 2 != 0
    sum += i
end
puts sum


#puts "Enter any number\n"
n =  gets.to_i
s = 0
for i in 1..n do
    if i%2 == 0
        s += i
    else
        s -= i
    end
end
puts s


n=gets.strip.chomp.to_i
def func(n)
  s=0
  for i in 1..n
    s+=((-1)**i)*i
  end
  s
end
puts func(n)


res = 0
inputNum = gets.chomp.to_i
for i in 1..inputNum.to_i
  res = res + (((-1) ** i)*i)
end
print res


lengths = gets.chomp!.split(/[ ]+/)
max = 0
for i in (0..3) do
  sticks = []
  for j in (0..3) do
    if j != i then sticks << lengths[j] end
  end
  sticks.sort!
  max = sticks[0].to_i + sticks[1].to_i - sticks[2].to_i
  if max > 0 then
     puts "TRIANGLE"
     break
  end
end
if max == 0 then
  puts "SEGMENT"
  break
elsif max < 0 then
  puts "IMPOSSIBLE"
  break
end


#!/usr/bin/evn ruby

def radians_to_degrees(radians)
	radians * 180.0 / Math::PI
end

def calc_area(a, b, c)
	p = (a + b + c) * 0.5
	argument = p * (p - a) * (p - b) * (p - c)
	unless argument < 0
		Math::sqrt(argument)
	else
		-1
	end
end

input = gets.to_s.split(' ')

a = input[0].to_i
b = input[1].to_i
c = input[2].to_i
d = input[3].to_i

if calc_area(a, b, c) >= 0
	if calc_area(a, b, c) > 0
		puts "TRIANGLE"
	else
		puts "SEGMENT"
	end
elsif calc_area(a, b, d) >= 0
	if calc_area(a, b, d) > 0
		puts "TRIANGLE"
	else
		puts "SEGMENT"
	end
elsif calc_area(a, c, d) >= 0
	if calc_area(a, c, d) > 0
		puts "TRIANGLE"
	else
		puts "SEGMENT"
	end
elsif calc_area(b, c, d) >= 0
	if calc_area(b, c, d) > 0
		puts "TRIANGLE"
	else
		puts "SEGMENT"
	end
else
	puts "IMPOSSIBLE"
end


size=gets.split.map(&:to_i)
d=gets.to_i
ans=0
size[0].times{|x|
        size[1].times{|y|
                if (x+y)%2==1 then
                        next
                end
                dd=[x+1,y+1,size[0]-x,size[1]-y].min
                if dd==d then
                        ans+=1
                end
        }
}
puts ans


sfriends = gets.chomp
sfingers = gets.chomp

friends = sfriends.to_i
fingers = sfingers.split(" ").map{|x| x.to_i}
totalFingers = fingers.reduce{|a,b| a+b}

(1..5).each do |x|
	if (((totalFingers + x)) % (friends+1)) != 1 then
		puts x
		break
	end
end


class Count
  def initialize
    @friend = $stdin.gets.chomp.to_i
    @fingers = $stdin.gets.chomp.split(' ').map(&:to_i)
    @total = @friend + 1
    @sum = @fingers.inject(:+)
  end

  def calc
  1.upto(5) do |n|
      d = n + @sum
      while d % @total != 1
          return n
      end
    end
  end
end

c = Count.new
puts c.calc


n = gets.chomp.to_i + 1
total = 0
gets.chomp.split(' ').each { |t| total += t.to_i }

ways = 0

5.times do |i|
	ways += 1 if (i+2) % n != 0
end

puts ways


n = gets.chomp.to_i
t = STDIN.readlines.map { |x| x.chomp.to_i }.reduce(:+)
puts Array(1..5).reduce(0) { |s, x| s + ((t + x) % (n + 1) != 1 ? 1 : 0)}


def isinside(ax, ay)
  half = $a/2.0
  return false if ax - half >= $x || ax + half <= $x
  return false if ay - half >= $y || ay + half <= $y
  return true
end
$a,$x,$y = gets.chomp.split(/ /).map!{|x| x.to_i}
ret = -1
ret = 1 if isinside(0, $a*(0.5))
ret = 2 if isinside(0, $a*(1.5))
ret = 3 if isinside(-$a*(0.5), $a*(2.5))
ret = 4 if isinside( $a*(0.5), $a*(2.5))
ret = 5 if isinside(0, $a*(3.5))
ret = 6 if isinside(-$a*(0.5), $a*(4.5))
ret = 7 if isinside( $a*(0.5), $a*(4.5))
puts ret.to_s


#!/usr/bin/env ruby

a,x,y = $stdin.readline.split().collect {|x| x.to_i}
p [a,x,y]

row = y / a

if y % a == 0
	puts -1
	exit 0
end

def cells_in_row(n)
	return 1 if n == 0
	return 1 if n % 2 == 1
	return 2
end

def first_cell_in_row(n)
	return 1 if n == 0
	return (n+1)/2*3 - 1 if n % 2 == 1
	return n/2*3
end

case cells_in_row(row)
when 1
	if x < a.to_f/2 && x > -a.to_f/2
		puts first_cell_in_row(row)
	else
		puts -1
	end
when 2
	if x < 0 && x > -a
		puts first_cell_in_row(row)
	elsif x > 0 && x < a
		puts first_cell_in_row(row)+1
	else
		puts -1
	end
end


puts "Enter first day"
a = gets.chomp
puts "Enter second day"
b = gets.chomp

if a == "monday"
	n1 = 1
end
if (a == "tuesday")
	n1 = 2
end
if (a == "wednesday")
	n1 = 3
end
if (a == "thursday")
	n1 = 4
end
if (a == "friday")
	n1 = 5
end
if (a == "saturday")
	n1 = 6
end
if (a == "sunday")
	n1 = 7
end

if (b == "monday")
	n2 = 1
end
if b == "tuesday"
	n2 = 2
end
if (b == "wednesday")
	n2 = 3
end
if (b == "thursday")
	n2 = 4
end
if (b == "friday")
	n2 = 5
end
if (b == "saturday")
	n2 = 6
end
if (b == "sunday")
	n2 = 7
end

dif = n2 - n1

if (dif < 0)
f = dif + 7
else
f = dif
end

if (f == 3)
	puts "YES"
elsif (f == 0)
	puts "YES"
elsif (f == 2)
	puts "YES"
else
	puts "NO"
end

puts "Enter third day"
a = gets.chomp
puts "Enter fourth day"
b = gets.chomp

if a == "monday"
	n1 = 1
end
if (a == "tuesday")
	n1 = 2
end
if (a == "wednesday")
	n1 = 3
end
if (a == "thursday")
	n1 = 4
end
if (a == "friday")
	n1 = 5
end
if (a == "saturday")
	n1 = 6
end
if (a == "sunday")
	n1 = 7
end

if (b == "monday")
	n2 = 1
end
if b == "tuesday"
	n2 = 2
end
if (b == "wednesday")
	n2 = 3
end
if (b == "thursday")
	n2 = 4
end
if (b == "friday")
	n2 = 5
end
if (b == "saturday")
	n2 = 6
end
if (b == "sunday")
	n2 = 7
end

dif = n2 - n1

if (dif < 0)
f = dif + 7
else
f = dif
end

if (f == 0)
	puts "YES"
elsif (f == 2)
	puts "YES"
elsif (f == 3)
	puts "YES"
else
	puts "NO"
end

puts "Enter fifth day"
a = gets.chomp
puts "Enter sixth day"
b = gets.chomp

if a == "monday"
	n1 = 1
end
if (a == "tuesday")
	n1 = 2
end
if (a == "wednesday")
	n1 = 3
end
if (a == "thursday")
	n1 = 4
end
if (a == "friday")
	n1 = 5
end
if (a == "saturday")
	n1 = 6
end
if (a == "sunday")
	n1 = 7
end

if (b == "monday")
	n2 = 1
end
if b == "tuesday"
	n2 = 2
end
if (b == "wednesday")
	n2 = 3
end
if (b == "thursday")
	n2 = 4
end
if (b == "friday")
	n2 = 5
end
if (b == "saturday")
	n2 = 6
end
if (b == "sunday")
	n2 = 7
end

dif = n2 - n1

if (dif < 0)
f = dif + 7
else
f = dif
end

if (f == 0)
	puts "YES"
elsif (f == 2)
	puts "YES"
elsif (f == 3)
	puts "YES"
else
	puts "NO"
end


class Matrix2x2
  attr_accessor :a, :b, :c, :d
  def initialize(a=0,b=0,c=0,d=0)
    @a = a
    @b = b
    @c = c
    @d = d
  end
end

def mult(x, y)
  z = Matrix2x2.new
  z.a = x.a*y.a + x.b*y.c
  z.b = x.a*y.b + x.b*y.d
  z.c = x.c*y.a + x.d*y.c
  z.d = x.c*y.b + x.d*y.d
  z
end

def expt(a, p)
  if p == 1
    a.clone
  elsif p % 2 == 1
    t = expt(a, p-1)
    mult(a, t)
  else
    t = expt(a, p/2)
    mult(t, t)
  end
end

n = gets.to_i
a = Matrix2x2.new(0, 3, 1, 2)
an = expt(a, n)
puts an.a


  na=gets.chomp.to_i
  i=2
  x=0
  while i<=na
   if (i%2)
    x=(x+1)*3
   else
    x=(x-1)*3
   end
  x= x % 1000000007
  i+=1
  end
  puts x


tx, ty = gets.strip.split(" ").collect{|v| v.to_i}
s = []
idx = 0
dx = dy = 0
gets.strip.split("").collect do |c|
  s[idx] = [1, 0] if c == 'R'
  s[idx] = [-1, 0] if c == 'L'
  s[idx] = [0, 1] if c == 'U'
  s[idx] = [0, -1] if c == 'D'
  dx += s[idx][0]
  dy += s[idx][1]
  idx += 1
end

if tx == 0 and ty == 0 then
  puts "Yes"
  exit
end

if dx == 0 and dy == 0 and (tx != 0 or ty != 0) then
  puts "No"
  exit
end

x = y = 0
s.size.times do |i|
  x += s[i][0]
  y += s[i][1]
  k = 10**10
  k = (tx - x) / dx if dx != 0
  k = [k, (ty - y) / dy].min if dy != 0
  k = 0 if k < 0
  if k * dx + x == tx and k * dy + y == ty then
    puts "Yes"
    exit
  end
end

puts "No"


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

if a < 0
  a = -a
  s.tr! 'LR', 'RL'
end

if b < 0
  b = -b
  s.tr! 'UD', 'DU'
end

minx = maxx = miny = maxy = x = y = 0

def step(x, y, c)
  if c == 'U' then
    y += 1
  elsif c == 'D' then
    y -= 1
  elsif c == 'R' then
    x += 1
  elsif c == 'L' then
    x -= 1
  end
  [x, y]
end

s = "0#{s}"
s.each_char do |c|
  x, y = step x, y, c
  maxx = x if x > maxx
  minx = x if x < minx
  maxy = y if y > maxy
  miny = y if y < miny
  if x == a and y == b
    puts 'Yes'
    exit
  end
end

dx = x
dy = y

if dx < 0 or dy < 0 or (dx == 0 and dy == 0)
  puts 'No'
  exit
end

startx = a - maxx - 1
endx = a - minx + 1
starty = b - maxy - 1
endy = b - miny + 1

iter = 0
iter = startx / dx if dx > 0
iter = [iter, starty / dy].min if dy > 0

x = iter * dx
y = iter * dy

begin
  s.each_char do |c|
    x, y = step x, y, c
    if x == a and y == b
      puts 'Yes'
      exit
    end
  end
end while x <= endx and y <= endy

puts 'No'


foo = 0
bar = 0
baz = 0
quz = 0
tux = gets.to_i
while tux!=0
pur =gets.to_i
foo = foo + pur
bar = bar + 1
#if bar*baz==foo*quz
 baz = foo
 quz = bar
#end
tux -=1
end

puts baz*1.0/quz


nlines = gets.to_i

sum = 0
nlines.times do
  sum = sum + gets.to_i
end

puts sum.to_f / nlines


$n = gets.to_i

$counter = 0
$len = Math.log10($n).to_i + 1

def solve(num, depth)
	if depth == $len
		$counter += 1 if num < $n
		return
	end

	[0, 1].each do |i|
		solve(num*10 + i, depth+1)
	end
end

solve(0, 0)

puts $counter


n = gets.to_i
res = 0
(1..n).each do |i|
  s = i.to_s
  res += 1 if s=~/^[01]+\Z/
end
puts res


def findIfOne(n,str1,str2)
  for i in 0..n.length-1
    if ((n[i]!=str1) && (n[i]!=str2))
       return false
    end
  end
  return true
end
n=gets.chomp
n=Integer(n)
count=0
str1=0.to_s
str2=1.to_s
for i in 1..n
  flag=findIfOne(i.to_s,str1,str2)
  if (flag==true)
    count+=1
  end
end
puts(count)


$n = 0
$res = 0
def go(x)
  if x <= $n then
    $res += 1
    go(10 * x + 0)
    go(10 * x + 1)
  end
end
$n = gets.slice.to_i
go(1)
p $res


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

rem = 240 - k

ans = 0
(1..n).each do |i|
  rem -= i * 5
  if rem <= 0
    break
  end
  ans += 1
end
puts ans


total_time = 4 * 60
n, k = gets.strip.split.map(&:to_i)
total_time -= k
time = 5
ans = 0
(1..n).each do |i|
    curr_time = 5 * i
    ans += 1
    break if time + curr_time > total_time
    time += curr_time
end
puts ans


n, k = gets.split.map(&:to_i)
c = 0
t = 60 * 4 - k
while t > (c + 1) * 5 && c < n
  c += 1
  t -= c * 5
end
puts c


def gao(s)
	s.each do |x|
		print x
		if x == 'H' or x == 'Q' or x == '9'
			"YES"
		end
	end
	"NO"
end

puts gao(gets)


x = raw_input()
n = "NO"
for i in x:
	if i=='H' or i== 'Q' or i== '9' or i== '+':
		n = "YES"
print n


n = gets.to_i

a = n / 2
b = n - a

if n.even?
	a -= 1
	b += 1
end

printf "%d %d", a, b


n = gets.strip.to_i

denominator = n - 1
numerator = 1.0
max = 0
max_numerator = 0
max_denominator = 0
while (numerator < denominator)
    if (numerator % denominator != 0 && numerator/denominator > max && denominator % numerator != 0)
        max = numerator/denominator
        max_numerator = numerator
        max_denominator = denominator
    end
    numerator += 1
    denominator -= 1
end
puts "#{max_numerator.to_i} #{max_denominator.to_i}"


def func(x)
    y = x+(x-1)
    return y
end

n = gets.to_i

result = n
i = n-1
while i > 0 do
    result += func(i)
    i -= 1
end

puts result


n = gets.to_i
puts (1...n).map { |x| (n - x) * x }.reduce(:+) + n


n = gets.to_i
i = 1
ans = 0
for i in 1..n:
    ans = ans + (i * (n-i))
end
puts ans+n


require 'prime'
n = gets.to_i
if n%2 == 0
  if n == 2
    print 1
  else
    print 2
  end
else
  a = Prime.prime?(n)
  if(a)
    print 1
  else
    print 3
  end
end


n, m = gets.split.map(&:to_i)
minv = [n - 2 * m, 0].max
ng = 0
ok = n
while ok - ng > 1
    mid = (ng + ok) / 2
    if mid * (mid - 1) >= 2 * m
        ok = mid
    else
        ng = mid
    end
end
maxv = n - ok
puts "#{minv} #{maxv}"


#!/usr/bin/ruby

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

matches = []
m.times do
  a, b = gets.chomp.split.map{|e| e.to_i}
  matches.push [a, b]
end

matches.sort! {|l, r|
  r[1] <=> l[1]
}

rest = n
cur_box = 0
acc = 0
while (true)
  break if cur_box > m
  if (matches[cur_box][0] <= rest)
    acc += matches[cur_box][0] * matches[cur_box][1]
    rest -= matches[cur_box][0]
    cur_box += 1
    next
  else
    acc += matches[cur_box][1] * rest
    break
  end
end
puts acc


#!/usr/bin/ruby

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

matches = []
m.times do
  a, b = gets.chomp.split.map{|e| e.to_i}
  matches.push [a, b]
end

matches.sort! {|l, r|
  r[1] <=> l[1]
}

rest = n
cur_box = 0
acc = 0
while (true)
  break if cur_box > =m
  if (matches[cur_box][0] <= rest)
    acc += matches[cur_box][0] * matches[cur_box][1]
    rest -= matches[cur_box][0]
    cur_box += 1
    next
  else
    acc += matches[cur_box][1] * rest
    break
  end
end
puts acc


n,m=gets().chomp().split(' ').map(&:to_i) ;h=Hash.new
m.times { a,b=gets().chomp().split(' ').map(&:to_i); h[a]=b; }
(h=h.sort_by {|_key, value| value}).reverse! ;count=0
h.each do |key, value|
  count+=(key>n)?((n)*value):(key*value) ;n-=key ;break if (n<=0)
end
p count


require 'date'
puts -(Date.parse(gets.gsub(':','-')) - Date.parse(gets.gsub(':','-'))).to_i


require "date"

m = Date.new(*gets.split(":").map(&:to_i))
n = Date.new(*gets.split(":").map(&:to_i))

p (n - m).to_i


require "date"

ss1 = gets.split(":").map{|s| s.to_i}
ss2 = gets.split(":").map{|s| s.to_i}
d1 = Date.new(ss1[0],ss1[1],ss1[2])
d2 = Date.new(ss2[0],ss2[1],ss2[2])
sa = d2 - d1
puts sa.abs


import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;

public class B {
	public static void main(String[] args) {
		doIt2();
	}
	static void doIt(){
		Calendar gc1, gc2;
		int fyear, fmonth, fday, tyear, tmonth, tday;
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String[] ss = s.split(":");
		fyear = Integer.parseInt(ss[0]);
		fmonth = Integer.parseInt(ss[1]);
		fday = Integer.parseInt(ss[2]);
		s = sc.next();
		ss = s.split(":");
		tyear = Integer.parseInt(ss[0]);
		tmonth = Integer.parseInt(ss[1]);
		tday = Integer.parseInt(ss[2]);
		Calendar calBefore = Calendar.getInstance();
		Calendar calAfter = Calendar.getInstance();

//		// 2011.06.01
//		calBefore.set(1996, Calendar.MARCH, 9, 0, 0, 0);
//
//		// 2011.06.30
//		calAfter.set(1991, Calendar.NOVEMBER, 12, 0, 0, 0);
		// 2011.06.01
				calBefore.set(1900, Calendar.FEBRUARY, 1, 0, 0, 0);

				// 2011.06.30
		calAfter.set(2038, Calendar.DECEMBER, 31, 0, 0, 0);
		// 2つの日付の差を求める(ミリ秒)
		long result = Math.abs(calAfter.getTime().getTime() - calBefore.getTime().getTime());
		result /= 1000 * 60 * 60 * 24;

		System.out.println(result);
	}
	static void doIt2(){
		GregorianCalendar gc1, gc2;
		int fyear, fmonth, fday, tyear, tmonth, tday;
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String[] ss = s.split(":");
		fyear = Integer.parseInt(ss[0]);
		fmonth = Integer.parseInt(ss[1]);
		fday = Integer.parseInt(ss[2]);
		s = sc.next();
		ss = s.split(":");
		tyear = Integer.parseInt(ss[0]);
		tmonth = Integer.parseInt(ss[1]);
		tday = Integer.parseInt(ss[2]);
		gc1 = new GregorianCalendar(fyear-1, fmonth, fday);
		gc2 = new GregorianCalendar(tyear-1, tmonth, tday);
		long result = Math.abs(gc1.getTimeInMillis() - gc2.getTimeInMillis());
		long div = 24 * 60 * 60 * 1000;
		result /= div + ((0 < result % div)? 1 : 0);
		System.out.println(result);
	}
}


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

def f(v, a, b)
  if (a < 10)
    v << b if b > 0
    f(v, a+1, b*10+4)
    f(v, a+1, b*10+7)
  end
end

v = []
f(v, 0, 0)
v.sort!

res = 0
prev = l-1
v.each do |x|
  if x >= l && x <= r || prev < r && x >= r
    res += ([r,x].min - prev)*x
#    p x-prev
    prev = x
  end
end

puts res


def C(n, k)
	res = 1
	for i in 1...n + 1
		res = res * i
	end
	for i in 1...k + 1
		res = res / i
	end
	for i in 1...n - k + 1
		res = res / i
	end
	return res
end

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

cn = Array.new(33, 0)
cm = Array.new(33, 0)

for i in 4...n + 1
	cn[i] = C(n, i)
end
for i in 1...m + 1
	cm[i] = C(m, i)
end
ans = 0;
for i in 4...t
	ans += cn[i] * cm[t-i]
end
puts ans


n, m, t = gets.split.collect{|i| i.to_i}
ans = 0
b = 4
while b <= n and t-b >= 1 and t-b <= m
    ans += Array.new(n).combination(b).size * Array.new(m).combination(t-b).size
    b += 1
end
puts ans


begin
n = gets.chomp.to_i
m = gets.chomp.to_i
t = gets.chomp.to_i

def fak(i)
    i > 1 ? i*fak(i - 1) : 1
end

r = 0
(4..t-1).each do |i|
    next if (i > n or t-i > m)
    r += (fak(n) / fak(i) / fak(n-i)) * (fak(m) / fak(t-i) / fak(m-t+i))
end

puts r
end


a = gets.chomp.split(" ").map{|i| i.to_i}
result = 0

GT = []
GT[1] =1

(2..30).each do |i|
    GT[i] = GT[i-1]*i
end

def tohop k,n
    kq = GT[n]/(GT[k]*GT[n-k])
    return kq
end

def min a,b
    kq = a
    if b < a
        kq = b
    end
    return kq
end

c = min a[1],(a[2]-4)

(1..c).each do |i|
    m = tohop i,a[1]
    n = tohop a[2]-i,a[0]
    result += m*n
end

puts result


#可以看出来，这个作者喜欢简洁！
#这里的&代表map中的元素！
#c是方砖的大小
#a，b分别是广场的长和宽！
#这里加负号的作用是什么，为了让他人看不懂？
a_add=0
if a%c!=0
	a_add+=1
end
b_add=0
if b%c!=0
	b_add+=1
end

a,b,c=gets.split.map &:to_i;p (a/c+a_add)*(b/c+b_add)


# 1A. Theater Square
# ======================================
# time limit per test:   2 seconds
# memory limit per test: 64 megabytes
# input:                 standard input
# output:                standard output
# ======================================
# Theatre Square in the capital city of Berland has a rectangular shape with the
# size n x m meters. On the occasion of the city's anniversary, a decision was
# taken to pave the Square with square granite flagstones. Each flagstone is of
# the size a x a.
#
# What is the least number of flagstones needed to pave the Square? It's allowed
# to cover the surface larger than the Theatre Square, but the Square has to be
# covered. It's not allowed to break the flagstones. The sides of flagstones
# should be parallel to the sides of the Square.
#
# Input
# The input contains three positive integer numbers in the first line: n, m and
# a (1 <= n, m, a <= 10^9).
#
# Output
# Write the needed number of flagstones.
# ======================================
n= gets.chomp.to_i
m= gets.chomp.to_i
a= gets.chomp.to_i

r= (m / a.to_f).ceil * (n / a.to_f).ceil

puts r


#!/usr/bin/ruby

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

count_n = 0;
count_m = 0;
if n % a == 0
  count_n = n / a;
else
  count_n = n / a + 1
end

if m % a == 0
  count_m = m / a
else
  count_m = m / a + 1
end
ans = count_n + count_m
puts ans


m, n, a = gets.chomp.split(' ')
x = (m*1.0/a).ceil
y = (n*1.0/a).ceil
puts x*y


n,m,a = gets.split(' ').map(&:to_i)
w = n+a-1)/a
h = (m+a-1)/a
puts w*h


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

square = a * b

flagstone = c * c
d = flagstone / 2

minimi = square/d

p minimi


x, y, z, k = gets.chomp.split.map{|s| s.to_i}

a = [x, y, z]
ans = 0
k.times do |i|
  cut = false
  a.each_with_index do |n, i|
    if n > 1
      a[i] -= i
      ans += 1
      cut = true
      break
    end
  end
  break unless cut
end

puts 2 ** ans


x, y, z, k = gets.chomp.split.map{|s| s.to_i}

a = { :x => x, :y => y, :z => z}
cut_num = { :x => 0, :y => 0, :z => 0}
r = { :x => 1, :y => 1, :z => 1}

k.times do |i|
  cut = false
  cut_num.sort_by{|n| n.last}.each do |n|
    i = n[0]
    if a[i] > 1
      r[i] += 1
      cut_num[i] += 1
      a[i] -= 1
      cut = true
      break
    end
  end
  break unless cut
end

ans = 1
r.each_value{|i| ans *= i}
puts ans


a=gets.comp.to_i
a=a-10
if a<=0 || a>=12
puts "0"
elsif a==10
puts "15"
else
puts "4"
end


def blackjack
  c = { }
  1.upto(11) { |i| c[i] = 4 }
  c[10] = 15

  goal = gets.to_i
  if goal-10 < 1
    puts 0
  else
    puts c[goal-10]
  end
end

blackjack


#!/usr/bin/env ruby

def solve n
  return 0 if n < 11
  diff = n - 10
  if 1 < diff and diff < 10
    return 4
  end
  if diff == 1
    return 4
  end
  if diff >= 10
    return 4*3+3
  end
end

#n = STDIN.gets.split.map {|i| i.to_i }

puts solve(STDIN.gets.to_i)


str = gets.strip
str.downcase!
puts str.gsub!(/[aeouiAEOUI]/, "").gsub!(/./){|char| ".#{char}"}


gets.strip.gsub!(/[aoyeui]/i, '').downcase.each_char{|c| print ".#{c}"}
puts


n = gets.to_i

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

res = a.first

a.each do |x|
  b = res < x ? x % res : res % x
  if 0 == b
    b = [res, x].min
  end
  res = b
end

puts res * n


n = gets.to_i

numbers = gets.split.map(&:to_i)

while(numbers.uniq.count != 1) do
	numbers.sort!.reverse!
	numbers.each_with_index do |n, i|
		numbers[i] = (numbers[i] - numbers[i + 1]) if numbers[i + 1]
	end
end

puts numbers.sum


n = gets.to_i

numbers = gets.split.map(&:to_i)

while(numbers.uniq.count != 1) do
	numbers.sort!.reverse!
	numbers.each_with_index do |n, i|
		numbers[i] = (numbers[i] - numbers[i + 1]) if numbers[i + 1]
	end
end

puts numbers.inject(&:+)


n = gets.to_i
s = gets.split.map(&:to_i).sort
loop do
  s[n - 1] -= s[n - 2]
  s.sort!
  break if s.count(s[0]) == n
end
puts s[0] * n


#!/usr/bin/ruby
n=gets.to_i-1
p gets.index('0')||n


gets
a = gets.chomp
b = (a.reverse.to_i(2) + 1).to_s(2).reverse[0...a.size]
puts b.count("0") + a.size - b.size


gets
a = gets.chomp
puts (a.reverse.to_i(2) + 1).to_s(2)[-a.size..-1].count("0")


n = gets.to_i

a = gets.split.map(&:to_i)
b = []

while (0 < a.size)
  current = a.shift
  flag = false
  for i in (0..(b.size-1)) do
    if (b[i] <= current)
      b[i]+=1
      flag = true
      break
    end
  end
  b << 1 unless flag
end
puts b.size


s = gets.chomp
c = s.chars.to_a
r = ""
i = j = 0
m = ""
n = "z"
loop do
    m = c.max
    break if m < n
    n = m
    i = c.index m
    j = c.rindex m
    break if j - i <= 1
    r += m
    c = c[(i+1)..(j-1)]
end
puts r + (i == j ? m : m + m) + r.reverse


import sys
import math
import itertools

if __name__ == '__main__':
  points = []

  s = [int(i) for i in raw_input().rstrip().split(" ")]
  x1 = s[0]
  y1 = s[1]
  x2 = s[2]
  y2 = s[3]

  min_x = min([x1, x2])
  max_x = max([x1, x2])
  min_y = min([y1, y2])
  max_y = max([y1, y2])

  for x in range(min_x, max_x + 1):
    points.append((min_y, x))
    points.append((max_y, x))

  for y in range(min_y, max_y + 1):
    points.append((y, min_x))
    points.append((y, max_x))

  points = list(set(points))

  n = int(raw_input().rstrip())

  while n > 0:
    s = [float(i) for i in raw_input().rstrip().split(" ")]
    x = s[0]
    y = s[1]
    r = s[2]

    tmp = []
    for p in points:
      if math.sqrt((float(p[0]) - y) ** 2 + (float(p[1]) - x) ** 2) > r:
        tmp.append(p)
    points = tmp

    n -= 1

  print len(points)


# codeforce#127(Div2.A)
s = gets.chomp.split("")
max = s.max

p max * s.count(max)


N, M = gets.split.map(&:to_i)
ast = gets.split.map(&:to_i)
bst = gets.split.map(&:to_i)
as, bs = [], []
N.times do |i|
    as[i] = ast.shift(2)
end
M.times do |i|
    bs[i] = bst.shift(2)
end

acand = []
as.each do |a|
    cand = []
    bs.each do |b|
        ab = a & b
        if ab.length == 1
            cand.push(ab[0])
        end
    end
    if cand.length > 1
        puts -1
        exit
    else
        acand.concat(cand)
    end
end

bs.each do |b|
    cand = []
    as.each do |a|
        ab = a & b
        if ab.length == 1
            cand.push(ab[0])
        end
    end
    if cand.length > 1
        puts -1
        exit
    end
end

if acand.length == 1
    puts acand[0]
elsif acand.length > 1
    puts 0
else
    puts -1
end


n, m = gets.split(' ').map {|x| x.to_i}
arr_true = Array.new(n, 0)
arr = Array.new
arr = gets.split(' ').map {|x| x.to_i}
for i in 0..m-1
	for j in arr[i]..n
		if (arr_true[j-1] == 0)
			arr_true[j-1] = arr[i]
		end
	end
end

p arr_true


n,m=gets.split.map &:to_i
s=gets.chomp
c=i=0
while c<n-1
	c=[c+m,n-1].max.downto(c+1){|j|s[j]==?1}
	if !c
		p -1
		exit
	end
	i+=1
end
p i


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

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

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

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

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

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

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

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

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

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

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

require 'prime'

n = inp[0]
t = inp
t = t.sort.reverse
h = {}
ans = 0
t.each do |d|
   ((t.min)..100).each do |i|
    if(d%i == 0)
      h[i] = true
      break
    end
  end
end

p ((h.to_a.size))


n=gets.to_i
r=1
k=2
loop{
	x=(2**k-1)*(2**~-k)
	break if n<x
	r=x if n%x==0
}
p r


#!/usr/bin/ruby
n=gets.to_i
s=0
i=0
loop{
	break if s+i*(i+1)/2>n
	s+=i*(i+1)/2
}
p i


#!/usr/bin/ruby
n=gets.to_i
s=0
i=0
loop{
	break if s+i*(i+1)/2>n
	s+=i*(i+1)/2
	i+=1
}
p i


n = gets.to_i
ans = 1
sum = 0
while (sum + ans * (ans + 1) / 2 <= n)
	ans+=1
	sum+=ans * (ans + 1) / 2
end
puts (ans - 1)


a = ARGV[0].to_i

if a == 0
	puts 0
else
	res = a
	i = 1
	while res > 0
		j = i + 1
		sn = j * (j - 1) / 2

		k = j + 1
		sn_next = k * (k - 1) / 2
		res -= sn

		if (res < sn_next)
			puts i
			break
		end
		i += 1
	end
end


board = gets.split(' ')
board_a = board.first.to_i
board_b = board.last.to_i
p1 = gets.split(' ')
p2 = gets.split(' ')
p1.map!{|x| x.to_i}
p2.map!{|x| x.to_i}
possible = false
p1.each do |dim1|
    p2.each do |dim2|
        if (dim1+dim2) <= board_a
            l1 = p1.reject{|a| a == dim1}.first
            l2 = p2.reject{|a| a == dim2}.first
            possible = true if [l1, l2].max <= board_b
        end
        if (dim1+dim2) <= board_b
            l1 = p1.reject{|a| a == dim1}.first
            l2 = p2.reject{|a| a == dim2}.first
            possible = true if [l1, l2].max <= board_a
        end
    end
end
if possible
    puts 'YES'
else
    puts 'NO'
end


k = gets.chomp.to_i
all = gets.chomp.to_i
count = 0
tmp = k
while tmp <= all
    if tmp == all
        PUTS "YES"
        puts count
        exit
    end
    tmp = tmp * k
    count += 1
end
puts "NO"


k = gets.to_i
l = gets.to_i
if l % k == 0
  a = 0
  while l != k
    l /= k
    a += 1
  end
  puts 'YES'
  puts a
else
  puts 'NO'
end


require 'prime'
k = gets.to_i
l = gets.to_i
a = k.prime_division
b = l.prime_division
ans = true
t = b[0][1] / a[0][1]
a.size.times do |i|
  ans = false if a[i][0] != b[i][0] || b[i][1] != a[i][1] * t || a.size != b.size
end
puts ans ? "YES\n#{t - 1}" : 'NO'


a=gets.chomp.to_i
b=gets.chomp.split(" ")
0.upto(11) {|i|  b[i]=b[i].to_i}
b.sort!
b.reverse!
i=0
ans=0
loop do
break if a<=0
a-=b[i]
i+=1
ans+=1
end
puts "#{ans}"


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

a.sort!.reverse!

i = -1
s = 0
while s < n and i <a.size - 1
  i += 1
  s += a

i = -1 if s < n
puts i


def main()
	k=gets.chomp.to_i
	ar=gets.chomp.split(" ").map{|y| y.to_i}
	ar=ar.sort.reverse
	j=0
	i=0
	while(j<k)
		j+=ar[i]
		i+=1
	end
	puts i
end
main()


minimum_value = gets.chomp
string_input = gets.chomp
array = string_input.split(' ').map(&:to_i)
array.sort!.reverse!
sum = 0
count = 0
13.times do
  if sum >= minimum_value.to_i
  	puts count
  	break
  end
	sum += array[count]
	count += 1
end
if count == 13
 puts '-1'
end


k = gets.to_i
d = gets.split.map(&:to_i).sort
count = 0
while k>0
    x = d.pop()
    k -= x
    count += 1
end
p count


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

s = 0
while s < k
  s += a.shift
end

puts 12 - a.size


targetCenti = gets.chomp.to_i
grow = gets.chomp.split(' ').map {|item| item.to_i}
grow.sort! {|a,b| b <=> a}
ans, index = 0, 0

until targetCenti <= 0
	targetCenti -= grow[index]
	index += 1
	ans += 1
end

puts ans


a = gets.split.map &:to_i
a.permutation.each do |p|
  if p[0] + p[1] == p[2] + p[3]
    puts 'YES'
    exit
  end
end
puts 'NO'


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


n,m=gets.split.map{|e| e.to_i}
ans=1
n=n%10
a=n
while n>m
	ans+=1
	n=(n+a)%10
end
puts ans


k,r=gets.split.map &:to_i
(1..10).each{|i|(p i;exit)if k*i%10%r<1}


x,y = gets.chomp.split.map(&:to_i)
r = 1
while((x*c)%10 != y && (x*c)%10 != 0)
  r = r + 1
end
puts r


n, k = gets.strip.split(' ').map(&:to_i)
s = gets.strip
j = -1
0.upto(s.length - 1) do |i|
  if s[i] == 'G'
    j = i
    break
  end
end

i1 = j
i2 = j
found = false
while(1)
  i1 -= k
  i2 += k
  if i1 >= 0
    if s[i1] == 'T'
      found = true
      break
    elsif s[i1] == '#'
      i1 = -1
    end
  end
  if i2 < s.length
    if s[i2] == 'T'
      found = true
      break
    end
    if s[i2] == '#'
      i2 = s.length
    end
  end
  if i1 < 0 && i2 >= s.length
    break
  end
end

printf("%s\n", found ? "YES" : "NO")


n = gets.to_i - 1
s = gets.chomp
max = 0
for i in 0..n / 2
	max = s[s[0..i] * 2] != nil ? i : max
end
puts n - max + 1


s1, s2 = gets.split
len = [s1.size, s2.size].max
s1 = s1.rjust(len, "0")
s2 = s2.rjust(len, "0")
p s1.to_i + s2.reverse.to_i


n,m = gets.chomp.split(/ /).map!{|x| x.to_i}
puts 1


include Math

def calculate(s1, s2, s3)
  a = sqrt(s1*s3/s2)
  b = sqrt(s1*s2/s3)
  c = sqrt(s2*s3/s1)

  puts 4*(a+b+c)
end

n,m,p = gets.chomp.split(/\s/).map(&:to_i)
calculate(n,m,p)


=begin
(define (hoge a b c)
  (sqrt (/ (* a c) b)))

(let ((a (read))
      (b (read))
      (c (read)))
  (print (* 4 (+ (hoge a b c)
                 (hoge b c a)
                 (hoge c a b)))))

=end

def hoge(a, b, c)
  return Math.sqrt(a * c / b)
end

a, b, c = $stdin.readline.split.map {|x| x.to_i }

puts(4 * (hoge(a, b, c) + hoge(b, c, a) + hoge(c, a, b)))


y = 3.times.map{gets.split.map(&:to_i)}.inject(&:concat)
(1..9).each do |a|
    (1..9).each do |b|
        (1..9).each do |c|
            (1..9).each do |d|
                x = [a + b, c + d, a + c, b + d, a + d, b + c]
                if x == y
                    puts "#{a} #{b}\n#{c} #{d}"
                    exit
                end
            end
        end
    end
end
p -1


r1,r2=gets.chomp.split.map(&:to_i)
c1,c2=gets.chomp.split.map(&:to_i)
d1,d2=gets.chomp.split.map(&:to_i)
a,b,c,d=0,0,0,0
for i in 0..9
	for j in 0..9
		for k in 0..9
			for l in 0..9
				if i!=j && i!=k && i!=l && j!=k && j!=l && k!=l && i+j==r1 && k+l==r2 && i+l==d1 && j+k==d2 && i+k==c1 && j+l==c2
					puts "#{i} #{j}"
					puts "#{k} #{l}"
					exit
				end
			end
		end
	end
end
puts "-1"


ar = []
3.times do
  ar << gets.split.map(&:to_i)
end

f = false
ans = []

1.upto 20 do |a|
  1.upto 20 do |b|
    next if a + b != ar[0][0]
    1.upto 20 do |c|
      next if a + c != ar[1][0]
      next if b + c != ar[2][1]
      1.upto 20 do |d|
        next if a + d != ar[2][0]
        next if b + d != ar[1][1]
        next if c + d != ar[0][1]
        f = true
        ans = [a, b, c, d]
        break
      end
    end
  end
end

if f && ans.uniq.size == 4
  print ans[0] , " " , ans[1], "\n"
  print  ans[2] , " " , ans[3], "\n"
else
  puts -1
end


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

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

print result


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

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

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

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

print result


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

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


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

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

  puts num


k, a, b = gets.strip.split.map(&:to_i)
max_score = [a, b].max
if max_score % k == 0
    puts max_score / k
else
    puts "-1"
end


#很多来回：赢了一个来回的1分，输了没有分！
#赢了k分就赢了1局
#最大的局数
#第一局：如果misha赢，则可能的比分是
#k:0
#k:1
#...
#k:k-1
#如果vanya赢，
#0:k
#1:k
#...
#k-1:k
#a/k表示misha最多可以赢多少局！
#b/k表示vanya最多可以赢多少局！
kab=gets.chomp.split.map{ |x| x.to_i }
k=kab[0]
a=kab[1]
b=kab[2]
if a/k+b/k==0
	puts -1
else
	puts a/k+b/k
end


n = gets.strip.to_i
atleast_half = ((1.0 * n)/2.0).ceil

def get_eaten(n, k)
  eaten = 0
  rem = n
  # puts rem if @d1
  # puts "---" if @d1
  while rem > 0 do
    # puts rem if @dbg
    if rem >= k
      eaten += k
      rem -= k
    else
      eaten += rem
      rem = 0
    end
    # puts rem if @d1
    rem -= (0.1 * rem).floor
    # puts rem if @d1
    # puts eaten if @d1
    # puts "eod" if @d1
  end
  eaten
end

lo = 1
hi = n
k = (lo  + hi)/2
while lo+1 < hi do
  k = (lo + hi) >> 1
  # puts "#{lo}:#{k}:#{hi}"
  if get_eaten(n, k) >= atleast_half
    hi = k
  else
    lo = k
  end
end
# while lo <= hi do
#   k = (lo  + hi)/2
#   # puts "#{lo}:#{k}:#{hi}"
#   if get_eaten(n, k) >= (n/2.0).ceil
#     hi = k-1
#   else
#     lo = k+1
#   end
# end
# puts k
# puts "..."
mk = [1, k-1000].max
(mk).upto(k+1000).each do |ki|
  # puts ki
  # @dbg = true
  if get_eaten(n, ki) >= atleast_half
    # puts get_eaten(n, ki)
    puts ki
    break
  end
end
# puts k

# # puts "---"
# 1.upto(n).each do |ki|
#   if get_eaten(n, ki) >= (n/2.0).ceil
#     # @d1 = true
#     # puts get_eaten(n, ki)
#     puts ki
#     break
#   end
# end


pokemons=['vaporeon', 'jolteon', 'flareon', 'espeon',
          'umbreon', 'leafeon', 'glaceon', 'sylveon']
gets
name=gets.strip
puts pokemons.select{|x| x =~ /#{name}/}[0]


a = gets.split.map(&:to_i)
if a[2] == 0 and a[3] != 0
  puts "Ron"
else
  puts(a[0]*a[2]*a[4] < a[1]*a[3]*a[5] ? "Ron" : "Hermione")
end


a, b, c, d, e, f = gets.split.map {|n| n.to_f }
conv_ratio = (a/b)*(c/d)*(e/f)

if d == 0
  puts "Hermione"
elsif c == 0
  puts "Ron"
elsif b == 0 or f == 0
  puts "Hermione"
elsif conv_ratio < 1
  puts "Ron"
else
  puts "Hermione"
end


a, b, c, d, e, f = gets.split(' ').map{|s| s.to_i}
ab, cd, ef = [[a, b], [c, d], [e, f]].map{|aa, bb|bb/aa.to_f}
g = ab*cd*ef
m = [cd.infinite?, ab.infinite?&&!cd.nan?, ef.infinite?&&!ab.nan?&&!cd.nan?]
puts (m.any?||g>1.0) ? 'Ron' : 'Hermione'


#!/usr/bin/ruby
s=gets.chomp
k=gets.to_i
l=s.size
m=l+k
m=m-m%2
if k>=l
	p m
else
	ma=0
	l.times{|i|
		1.step(l-i){|j|
			if 2*(i+j)>ma && i.step(i+j-1).all?{|k|(o+j>=l&&o+j<l+k)||a[o]==a[o+j]}
				ma=2*(i+j)
			end
		}
	}
	p ma
end


x = gets.chomp
n = gets.chomp.to_i

(n..x.size).each_with_index do |l, i|
  y = x + x[-l..-i-1]

  1.upto(y.length/2).each do |k|
    max = k*2 if y[-k..-1] == y[-2*k..-k-1] && max < k*2
  end
end


#! /usr/bin/env ruby
x = gets.chomp
n = gets.to_i

x << '*'*n
max = 0
(0..(x.size-1)).each do |st|
  en = st + 1

  while en < x.size
    len = en-st+1
    half_en = st + (len)/2
    # puts [x[st..en], st, en, len, half_en, x[st..half_en-1], x[half_en..en]].inspect
    flag = true
    (st..(len/2-1)).each do |i|

      # puts [x[st+i], x[half_en+i]].inspect
      flag = false if x[st+i] != x[half_en+i] && x[half_en+i] != '*'
    end

    max = len if flag && max < len
    en +=2
  end
end

puts max


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

if k == n
	print "0 0"
else
	print 1, " ", (n + 2) / 3 <= k ? n - k : 2 * k
end


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

if n == k
    puts "0 0"
else
    if k*3 < n
        puts "1 #{k*2}"
    else
        puts "1 #{n-k}"
    end
end


n,k=gets.split.map(&:to_i)
if n == k
    puts "0 0"
else
    if n % 3 == 0
        if k > n / 3
            k -= n / 3
            ans = n / 3 * 2 - k
        else
            ans = 2 * k
        end
    elsif n % 3 == 1
        if k > n / 3
            k -= n / 3
            ans = n / 3 * 2 - k + 1
        else
            ans = 2 * k
        end
    else
        if k > n / 3
            k -= n / 3 + 1
            ans = n / 3 * 2 + 1 - k
        else
            ans = 2 * k
        end
    end
    puts "1 #{ans}"
end


gets
b=$_.each_char.max.to_i+1
x,y=split.map{|i|i.to_i(b)}
p (x+y).to_s(b).size


x, y, *rest = STDIN.read.split(" ")

puts (2..16).inject { |acc, b| [acc, (x.to_i(b) + y.to_i(b)).to_s(b).length].max }


require 'date'
a, b = 2.times.map{gets.split('.').map(&:to_i).reverse}
a[0] += 1800
puts b.permutation.map{|c|
	c[0] += 1818
	begin
		Date.new(*a) >= Date.new(*c)
	rescue ArgumentError
		nil
	end
}.any? ? :YES : :NO


a = gets.split(".").map!{|t| t.to_i}
b = gets.split(".").map!{|t| t.to_i}
dates = []
d = Date.new(a[2]+2000,a[1],a[0])
def valid y,m,d
    return Date.valid_date?(y,m,d)

end
dates << Date.new(b[0]+2000,b[1],b[2]) if valid(b[0]+2000,b[1],b[2])
dates << Date.new(b[0]+2000,b[2],b[1]) if valid(b[0]+2000,b[2],b[1])
dates << Date.new(b[1]+2000,b[0],b[2]) if valid(b[1]+2000,b[0],b[2])
dates << Date.new(b[1]+2000,b[2],b[0]) if valid(b[1]+2000,b[2],b[0])
dates << Date.new(b[2]+2000,b[0],b[1]) if valid(b[2]+2000,b[0],b[1])
dates << Date.new(b[2]+2000,b[1],b[0]) if valid(b[2]+2000,b[1],b[0])
(0...dates.size).each do |i|
    18.times do |t|
        if dates[i].leap?
            dates[i] += 366
        else
            dates[i] += 365
        end
    end
end
fl = false
(0...dates.size).each do |i|
    if(dates[i] <= d)
        puts "YES"
        fl = true
        break
    end
end
if(!fl)
    puts "NO"
end


require 'date'
a = gets.split(".").map!{|t| t.to_i}
b = gets.split(".").map!{|t| t.to_i}
dates = []
d = Date.new(a[2]+2000,a[1],a[0])
def valid y,m,d
    return Date.valid_date?(y,m,d)

end
dates << Date.new(b[0]+2000,b[1],b[2]) if valid(b[0]+2000,b[1],b[2])
dates << Date.new(b[0]+2000,b[2],b[1]) if valid(b[0]+2000,b[2],b[1])
dates << Date.new(b[1]+2000,b[0],b[2]) if valid(b[1]+2000,b[0],b[2])
dates << Date.new(b[1]+2000,b[2],b[0]) if valid(b[1]+2000,b[2],b[0])
dates << Date.new(b[2]+2000,b[0],b[1]) if valid(b[2]+2000,b[0],b[1])
dates << Date.new(b[2]+2000,b[1],b[0]) if valid(b[2]+2000,b[1],b[0])
(0...dates.size).each do |i|
    18.times do |t|
        if dates[i].leap?
            dates[i] += 366
        else
            dates[i] += 365
        end
    end
end
fl = false
(0...dates.size).each do |i|
    if(dates[i] <= d)
        puts "YES"
        fl = true
        break
    end
end
if(!fl)
    puts "NO"
end


require 'date'

def check_age(today, birthday)
  if today[2] - birthday[2] < 18
    return false
  end
  if today[1] == 2 && today[0] == 29
    today[0] = 28
  end
  if birthday[1] == 2 && birthday[0] == 29
    birthday[0] = 28
  end
  begin
    DateTime.new(today[2], today[1], today[0], 0, 0, 0)
    DateTime.new(today[2], birthday[1], birthday[0], 0, 0, 0)
  rescue ArgumentError
    return false
  end
  if today[2] - birthday[2] > 18
    return true
  end
  if today[2] - birthday[2] == 18
    DateTime.new(today[2], today[1], today[0], 0, 0, 0) - DateTime.new(today[2], birthday[1], birthday[0], 0, 0, 0) >= 0
  end
end

today = gets.strip.split('.').map { |val| val.to_i }
d2, m2, y2 = gets.strip.split('.').map { |val| val.to_i }

today[2] += 2000

answer = 'NO'

answer = 'YES' if check_age today, [d2, m2, y2 + 2000]
answer = 'YES' if check_age today, [d2, y2, m2 + 2000]
answer = 'YES' if check_age today, [m2, d2, y2 + 2000]
answer = 'YES' if check_age today, [m2, y2, d2 + 2000]
answer = 'YES' if check_age today, [y2, m2, d2 + 2000]
answer = 'YES' if check_age today, [y2, d2, m2 + 2000]

puts answer
exit 0


route = gets.chomp
visited = {[0, 0] => 1}
x, y = 0, 0
bug = false
value = 1

route.each_char do |direction|
	case direction
	when "R" then x += 1
	when "L" then x -= 1
	when "U" then y += 1
	when "D" then y -= 1
	end

	(bug = true and break) if visited[[x, y]] && visited[[x, y]] > 0

	value += 1
	(-1..1).each do |i|
		(-1..1).each do |j|
			next unless i ** 2 + j ** 2 == 1
			if visited[[x + i, y + j]] && visited[[x + i, y + j]] > 0
				bug = true if visited[[x + i, y + j]] != value - 1
			end
		end
	end
	visited[[x + a, y + b]] = value
end

if bug then
	puts "BUG"
else
	puts "OK"
end


p = gets.strip
x = 0
y = 0
i = 0
while i < p.length
  case p[i]
  when ?L then x-=1
  when ?R then x+=1
  when ?U then y-=1
  when ?D then y+=1
  end
  i += 1
end

if (x == 0 and y.abs == 1) ||
   (y == 0 and x.abs == 1)
  if p.length > 1
    puts "BUG"
  else
    puts "OK"
  end
else
  if x == 0 && y == 0
    puts "BUG"
  else
    puts "OK"
  end
end


s = gets.chomp!

mas = Hash.new()
for i in -101..101
  mas[i] = Hash.new()
  for j in -101..101
    mas[i][j] = 999999;
  end
end

step = 0
x,y = 0,0
mas[x][y] = 0
s.chars { |c|
  mas[x+1][y] = [mas[x+1][y],mas[x][y] + 1].min
  mas[x-1][y] = [mas[x-1][y],mas[x][y] + 1].min
  mas[x][y-1] = [mas[x][y-1],mas[x][y] + 1].min
  mas[x][y+1] = [mas[x][y+1],mas[x][y] + 1].min

  case c
  when "R"
    x += 1
  when "L"
    x -= 1
  when "U"
    y += 1
  when "D"
    y -= 1
  end

  if mas[x][y] < step + 1
    puts "BUG"
    exit
  end
}

puts "OK"


def solve(a, b, s)
  dx = dy = 0
  dp = [[0, 0]]
  s.split("").each do |ch|
    dx += 1 if ch == 'R'
    dx -= 1 if ch == 'L'
    dy += 1 if ch == 'U'
    dy -= 1 if ch == 'D'
    dp << [dx, dy]
  end

  dx, dy = dp[-1]
  dp.each do |cur|
    x = a - cur[0]
    y = b - cur[1]
    chk = 0
    mul = x / dy if dy != 0
    mul = y / dy if dy != 0
    next if mul < 0
    return true if dx * mul == x && dy * mul == y
  end
  return false
end

a, b = gets.split.map { |i| i.to_i }
s = gets.chomp

if solve(a, b, s)
  puts "Yes"
else
  puts "No"
end


a,b,c,d,e=gets.split.map &:to_i
a=[a,c].max
b=[b,d].min
p b-a+1-(a<=e&&e<=b ? 1 : 0)


input = gets.strip.split(" ").map(&:to_i)
l1 = input[0]
r1 = input[1]
l2 = input[2]
r2 = input[3]
k = input[4]

a = [l1,l2].max
b = [r1,r2].min

if b > a
  c = b - a + 1
  if k >= a and k <= b
    puts c-1
  else
    puts c
  end
else
  puts 0
end


l1, r1, l2, r2, k = gets.chomp.split(' ').map(&:to_i)

range = (l1..r1).to_a & (l2..r2).to_a
res = range.length

res = res - 1 if range.include? k

p res


smin, smax, fmin, fmax, p = gets.chomp.split(' ').map(&:to_i)

ans = 0
if smin <= fmin
	ans = smax - fmin + 1
	if p >= fmin && p <= smax
		ans -= 1
	end
else
	ans = fmax - smin + 1
	if p >= smin && p <= fmax
		ans -= 1
	end
end

ans = 0 if ans < 0
puts ans


a,b,c,d,e,f = gets.split.map(&:to_i)
puts (a+b+c)*(a+b+c)-a*a-b*b-e*e


def main()
	gf=gets.chomp.split(" ")
	gf=gf.map{|i| i.to_i}
	gl=gf[0]
	gr=gf[1]
	bf=gets.chomp.split(" ")
	bf=bf.map{|i| i.to_i}
	bl=bf[0]
	br=bf[1]
	if checkcomfort(gl,br) || checkcomfort(gr,bl)
		puts "YES"
	else
		puts "NO"
	end
end
def checkcomfort(g,b)
	if b>=g-1 && g>=b-2
		return true;
	end
	return false;
end
main()


num = [ 6 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 ]

a, b = gets.split(' ').map(&:to_i)
sum = 0
for i in a..b do
  aux = a
  while aux > 0 do
    sum += num[ aux%10 ]
    aux /= 10
  end
end
puts res


#! usr/bin/env ruby
n,k=gets.split.map &:to_i
a = Array.new
a = gets.split(" ").map &:to_i
a.sort
i=0

count = 0
while i<n
        if a[i] >= a[k] and a[i]>0
                count+=1
        end
i+=1
end
p count


x = gets.chomp.split
y = gets.chomp.split

index = x[1].to_i
cutoff = y[index]

count = 0
until y[index] < cutoff
  index += 1
  count += 1
end

puts (count + x[1].to_i)


n, k = gets.chomp.split.map! { |e| e.to_i }

numbers = gets.chomp.split.map! { |e| e.to_i }
kth = numbers[k]

next_round = numbers.select { |e| e > 0 and e >= kth }.size
puts "#{next_round}"


nk = gets.chomp.split(" ").map { |x| x.to_i}
a = gets.chomp.split(" ").map { |x| x.to_i}
n = nk[0]
k = nk[1]

score = a[k]
c = 0

if (score == 0)
    puts "0"
    exit
end

current = a[0]

while current >= score do
    c++
    current = a[c]
end
puts c


nk = gets.chomp.split(" ").map { |x| x.to_i}
a = gets.chomp.split(" ").map { |x| x.to_i}
n = nk[0]
k = nk[1]

score = a[k]
c = k

if (score == 0)
    puts "0"
    exit
end

current = a[c]

while current >= score do
  c += 1
  current = a[c]
  if c >= n
    break
  end
end
puts c


res = 0

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

(n, k)  = l[0].split(" ").map(&:to_i)

if n != 0
  num     = l[1].split(" ").map(&:to_i)

  for i in 0..(n-1)
    if num[i] >= num[k] && num[i] > 0
      res = res + 1
    end
  end
end

puts res


s1 = gets.chomp
p1 = s1.split(' ')
n=p1[0].to_i-1
k=p1[1].to_i
s2 = gets.chomp
p = s2.split(' ')
ball = p[k-1].to_i
k=0
for i in 0..n
    if (p[i].to_i>=ball and p[i]>0)
        k=k+1
    end
    end
puts k


#!/usr/bin/ruby

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

a = Array.new

i = 0
a = gets.chomp.split(" ").map(&:to_i)

ind = a[k]
i = 0
count = 0

a.each do |j|
    if (j >= a[k] && j != 0)
        count += 1
    end
end

puts count


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

score = a[k]
if score > 0
    puts a.select{ |x| x >= score }.size
else
    puts '0'
end


#Progressing to the next round
n1,k1=gets.chomp.split(" ")
n=Integer(n1)
k=Integer(k1)
a=gets.chomp.split(" ")
temp=Integer(a[k-1])
if temp<=0
	while Integer(a[k])>=0 && k>0
		k=k-1
	end
	print k
else
	count=k
	while a[k-1]==a[count]
		count=count+1
	end
	print count
end


input = gets

conds, points = input.split("\n")

conds = conds.split(" ")
n = conds[0].to_i
k = conds[1].to_i

points = points.split(" ").map{|x| x.to_i}

threshold = [1, points.sort.reverse[k-1]].max
winners = points.filter{|x| x >= threshold}.length
puts winners