require 'scanf'

(n, k) = scanf("%d%d")
if n == 1
  puts "0"
elsif k * (k-1) / 2 < n - 1
  puts "-1"
else
  low, up = 1, k-1
  while low < up do
    m = (low + up + 1) / 2
    if (m + k - 1) * (k - 1 - m + 1) / 2 < n - 1
      up = m - 1
    else
      low = m
    end
  end
  puts k - up
end

N, K = gets.split.map &:to_i
l = -1
u = K
while l + 1 < u
  m = l + u >> 1
  (K - 1 + K - m) * m / 2 + 1 >= N ? u = m : l = m
end
p u == K ? -1 : u

N, K = gets.split.map &:to_i
lb, ub = -1, K
until lb + 1 == ub
  mb = lb + ub >> 1
  (K - 1 + K - mb) * mb / 2 + 1 >= N ? ub = mb : lb = mb
end
p (ub == K ? -1 : ub)

def howMany(low , high , k ,n )
    minn = k
    while low <= high
        mid = (low+high)/2
        lowerBound =(mid*(mid+1)) / 2 + 1
        comp = k-mid-1
        upperBound = 0
        if comp == 1
            upperBound = k*(k-1 ) / 2
        else
            summ= comp*(comp+1) /2 + 1
            upperBound = k*(k-1) / 2 +1 -summ +1
        end
        if n < lowerBound
            high = mid-1
        elsif n > upperBound
            low = mid +1
        else
            minn = [mid,minn].min
            high = mid - 1
        end
    end
    minn

end

n , k =gets.split.map(&:to_i)
lower = 2
upper = (k*(k-1) / 2 )+ 1

if n < lower || n > upper
    puts n==1?0:-1
else
    if n <= k
        puts 1
    elsif n == upper
        puts k-1
    else
        puts howMany(2,k-1,k,n)
    end
end

#!/usr/bin/ruby1.9

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

need = n-1
max = k-1

if need == 0
	puts 0
	exit
end

if (max+1)*max/2 < need
	puts -1
	exit
end

low, high = 1, max
while low < high
	mid = (low+high)/2
	sum = (mid+max)*(max-mid+1)/2
	if sum == need
		break
	elsif sum < need
		high = mid
	else
		low = mid+1
	end
end

mid = (low+high)/2
if (mid+max)*(max-mid+1)/2 >= need
	puts max-mid+1
else
	puts max-mid+2
end

class B
  def initialize
    n, k = $stdin.gets.chomp.split(' ').map(&:to_i)

    if n == 1
      puts 0
      exit
    elsif k >= n
      puts 1
      exit
    end

    left = 2
    right = k

    while(left < right)
      m = (left+right)/2

      if(m*(2*k-m-1)/2+1<n)
        left = m+1
      else
        right = m
      end
    end

    #p k*(k-1)/2-(right-2)*(right-1)/2 + 1

    if (right*(2*k-right-1)/2+1<n)
      puts -1
    else
      puts right
    end
  end
end

b = B.new

#!/usr/bin/ruby1.9

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

need = n-1
max = k-1

if (max+1)*max/2 < need
	puts -1
	exit
end

low, high = 1, max
while low < high
	mid = (low+high)/2
	sum = (mid+max)*(max-mid+1)/2
	if sum == need
		break
	elsif sum < need
		high = mid
	else
		low = mid+1
	end
end

mid = (low+high)/2
if (mid+max)*(max-mid+1)/2 >= need
	puts max-mid+1
else
	puts max-mid+2
end

#!/usr/bin/ruby1.9

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

need = n-1
max = k-1

if (max+1)*max/2 < need
	puts -1
	exit
end

c = 2*need - max*max - max
p = ((-1 + (1-4*c)**0.5) / 2).floor

puts max-p

#!/usr/bin/ruby1.9

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

need = n-1
max = k-1

if (max+1)*(max/2) < need
	puts -1
	exit
end

c = 2*need - max*max - max
p = ((-1 + (1-4*c)**0.5) / 2).floor

puts max-p

class B
  def initialize
    n, k = $stdin.gets.chomp.split(' ').map(&:to_i)

    if k >= n
      puts 1
      exit
    end

    left = 2
    right = k

    while(left < right)
      m = (left+right)/2

      if(m*(2*k-m-1)/2+1<n)
        left = m+1
      else
        right = m
      end
    end

    #p k*(k-1)/2-(right-2)*(right-1)/2 + 1

    if (right*(2*k-right-1)/2+1<n)
      puts -1
    else
      puts right
    end
  end
end

b = B.new

class B
  def initialize
    n, k = $stdin.gets.chomp.split(' ').map(&:to_i)

    if k >= n
      puts 1
      exit
    end

    sum = 0
    p = (k+2)/2
    left = 2
    right = k

    while( (right-left).abs > 1 || sum < n) do
      now_p = p
      break if (left >= right)
      if (p == 2)
        sum = 2
      else
        sum = p*(p-1)*0.5+1
      end

      if(sum >= n)
        right = p
        p = (left+right)/2
      else
        left = p
        if (left+right)/2 > p
          p = (left+right)/2
        else
          p += 1
        end
      end
    end

    if sum < n
      puts -1
    else
      puts (now_p-1)
    end
  end
end

b = B.new

class B
  def initialize
    n, k = $stdin.gets.chomp.split(' ').map(&:to_i)

    if k >= n
      puts 1
      exit
    end

    total_sum = k*(k-1)*0.5+1
    left = 2
    right = k

    while(left < right)
      m = (left+right)/2

      #if(1+(k-1+k-m)*m/2<n)
      if((k*(k-1)-m*(m-1))/2<n)
        right = m - 1
      else
        left = m
      end
    end

    #p k*(k-1)/2-right*(right-1)/2 + 1
    if (k*(k-1)/2-right*(right-1)/2 + 1<n)
      puts -1
    else
      puts k-right
    end
  end
end

b = B.new

class B
  def initialize
    n, k = $stdin.gets.chomp.split(' ').map(&:to_i)

    if k >= n
      puts 1
      exit
    end

    sum = 0
    p = (k+2)/2
    left = 2
    right = k

    while( (right-left).abs > 1 || sum < n) do
      if (p == 2)
        sum = 2
      else
        sum = p*(p-1)*0.5+1
      end

      if(sum > n)
        right = p
        p = (left+right)/2
      else
        left = p
        if (left+right)/2 > p
          p = (left+right)/2
        else
          p += 1
          break if right <= left
        end
      end
    end

    if sum < n
      puts -1
    else
      puts (left-1)
    end
  end
end

b = B.new

class B
  def initialize
    n, k = $stdin.gets.chomp.split(' ').map(&:to_i)

    if k >= n
      puts 1
      exit
    end

    sum = 0
    p = (k+2)/2
    left = 2
    right = k

    while((right-left).abs > 0) do
      r_v = right*(right-1)*0.5
      l_v = left*(left-1)*0.5

      if l_v < n && n <= r_v && (right-left).abs <= 1
        break
      elsif l_v == n
        break
      elsif l_v > r_v
        break
      end

      if (p == 2)
        sum = 2
      else
        sum = p*(p-1)*0.5+1
      end

      if(sum < n)
        left = p
        if (left+right)/2 > p
          p = (left+right)/2
        else
          p += 1
        end
      else
        right = p
        if (left+right)/2 < p
          p = (left+right)/2
        else
          p -= 1
        end
        break if p <= left
      end
    end

    if sum < n
      puts -1
    else
      puts (right-1)
    end
  end
end

b = B.new

class B
  def initialize
    n, k = $stdin.gets.chomp.split(' ').map(&:to_i)

    if k >= n
      puts 1
      exit
    end

    sum = 0
    p = (k+2)/2
    left = 2
    right = k

    while((right-left).abs > 0) do
      r_v = right*(right-1)*0.5
      l_v = left*(left-1)*0.5

      if l_v < n && n <= r_v
        break
      elsif l_v == n
        break
      elsif l_v > r_v
        break
      end

      if (p == 2)
        sum = 2
      else
        sum = p*(p-1)*0.5+1
      end

      if(sum < n)
        left = p
        if (left+right)/2 > p
          p = (left+right)/2
        else
          p += 1
        end
      else
        right = p
        if (left+right)/2 < p
          p = (left+right)/2
        else
          p -= 1
        end
        break if p <= left
      end
    end

    if sum < n
      puts -1
    else
      puts (right-1)
    end
  end
end

b = B.new

class B
  def initialize
    n, k = $stdin.gets.chomp.split(' ').map(&:to_i)

    if k >= n
      puts 1
      exit
    end

    total_sum = k*(k-1)*0.5+1
    sum = 0
    p = (k+2)/2
    left = 2
    right = k

    while((right-left).abs > 0) do
      r_v = total_sum - right*(right-1)*0.5+1
      l_v = total_sum - left*(left-1)*0.5+1

      if l_v >= n && n > r_v && (right-left).abs <= 1
        sum = l_v
        break
      elsif l_v < r_v
        break
      end

      if (p == 2)
        sum = 2
      else
        sum = total_sum - p*(p-1)*0.5+1
      end

      if(sum < n)
        right = p
        if (left+right)/2 < p
          p = (left+right)/2
        else
          p -= 1
        end
      else
        left = p
        if (left+right)/2 > p
          p = (left+right)/2
        else
          p += 1
        end
        break if p >= right
      end
    end

    if sum < n
      puts -1
    else
      puts k-left+1
    end
  end
end

b = B.new

class B
  def initialize
    n, k = $stdin.gets.chomp.split(' ').map(&:to_i)

    if k >= n
      puts 1
      exit
    end

    sum = 0
    p = (k+2)/2
    left = 2
    right = k

    while((right-left).abs > 0) do
      r_v = right*(right-1)*0.5
      l_v = left*(left-1)*0.5

      if l_v < n && n <= r_v && (right-left).abs <= 1
        sum = p*(p-1)*0.5+1
        break
      elsif l_v == n
        break
      elsif l_v > r_v
        break
      end

      if (p == 2)
        sum = 2
      else
        sum = p*(p-1)*0.5+1
      end

      if(sum < n)
        left = p
        if (left+right)/2 > p
          p = (left+right)/2
        else
          p += 1
        end
      else
        right = p
        if (left+right)/2 < p
          p = (left+right)/2
        else
          p -= 1
        end
        break if p <= left
      end
    end

    if sum < n
      puts -1
    else
      puts (right-1)
    end
  end
end

b = B.new

class B
  def initialize
    n, k = $stdin.gets.chomp.split(' ').map(&:to_i)

    if k >= n
      puts 1
      exit
    end

    left = 2
    right = k

    while(left < right)
      m = (left+right)/2

      if(m*(2*k-m-1)/2+1<n)
        left = m+1
      else
        right = m
      end
    end

    #p k*(k-1)/2-(right-2)*(right-1)/2 + 1

    if (m*(2*k-m-1)/2+1<n)
      puts -1
    else
      puts m
    end
  end
end

b = B.new

class B
  def initialize
    n, k = $stdin.gets.chomp.split(' ').map(&:to_i)

    if k >= n
      puts 1
      exit
    end

    sum = 0
    p = (k+2)/2
    left = 2
    right = k

    while((right-left).abs > 0) do
      r_v = right*(right-1)*0.5
      l_v = left*(left-1)*0.5

      if l_v < n && n <= r_v && (right-left).abs <= 1
        sum = right*(right-1)*0.5+1
        break
      elsif l_v == n
        sum = l_v
        break
      elsif l_v > r_v
        break
      end

      if (p == 2)
        sum = 2
      else
        sum = p*(p-1)*0.5+1
      end

      if(sum < n)
        left = p
        if (left+right)/2 > p
          p = (left+right)/2
        else
          p += 1
        end
      else
        right = p
        if (left+right)/2 < p
          p = (left+right)/2
        else
          p -= 1
        end
        break if p <= left
      end
    end

    if sum < n
      puts -1
    else
      puts (right-1)
    end
  end
end

b = B.new

class B
  def initialize
    n, k = $stdin.gets.chomp.split(' ').map(&:to_i)

    if k >= n
      puts 1
      exit
    end

    total_sum = k*(k-1)*0.5+1
    sum = 0
    p = (k+2)/2
    left = 2
    right = k

    while((right-left).abs > 0) do
      r_v = total_sum - right*(right-1)*0.5+1
      l_v = total_sum - left*(left-1)*0.5+1

      if l_v >= n && n > r_v && (right-left).abs <= 1
        sum = l_v
        break
      elsif l_v < r_v
        break
      end

      if (p == 2)
        sum = 2
      else
        sum = total_sum - p*(p-1)*0.5+1
      end

      if(sum < n)
        right = p
        if (left+right)/2 < p
          p = (left+right)/2
        else
          p -= 1
        end
      else
        left = p
        if (left+right)/2 > p
          p = (left+right)/2
        else
          p += 1
        end
        break if p >= right
      end
    end

    (left-3).upto(left+3) do |elem|
      val1 = total_sum - (elem-1)*(elem-2)*0.5
      val2 = total_sum - (elem)*(elem-1)*0.5

      if(val1 >= n && n > val2)
        puts k-elem+1
        exit
      end
    end

    puts -1
  end
end

b = B.new

require 'scanf'

(n, k) = scanf("%d%d")

if k * (k-1) / 2 < n - 1
  puts "-1"
else
  low, up = 1, k-1
  while low < up do
    m = (low + up + 1) / 2
    if (m + k-1) * (k-1 - m + 1) / 2 < n - 1
      up = m - 1
    else
      low = m
    end
  end
  puts k - up
end


n,l=gets.split.map &:to_i
a=gets.split.map.with_index{|e,i|[e.to_i,2**i]}.sort_by{|c,v|c.to_r/v}
m={}
f=->x,i{
    return 0 if !a[i]
    c,v=a[i]
    k=x/v
    m[[x,i]]||=[f[x-k*v, i+1]+k*c, (k+1)*c].min
}
p f[l, 0]

#!/usr/bin/ruby
include Math

INF = 0x3f3f3f3f3f3f3f3f3f3f3f3f3f3f3f3f

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

best = []
best[0] = INF
res = INF
for i in 1..n
	best[i] = [2*best[i-1], cost[i-1]].min
	if 2**(i-1) >= v
		res = [res, best[i]].min
	end
end
for i in n+1..70
	best[i] = 2*best[i-1]
	if 2**(i-1) >= v
		res = [res, best[i]].min
	end
end

ans = INF
vv = v
while (vv & -vv) != vv
	temp = 0
	j = 0
	v = vv
	while v > 0
		j += 1
		if v % 2 == 1
			temp += best[j]
		end
		v /= 2
	end
	ans = [ans, temp].min
	vv += vv & -vv
end

puts [res, ans].min

n,l = gets.split.map &:to_i
c = gets.split.map &:to_i

(n-1).times{|i| c[i+1] = c[i]*2 if c[i+1] > c[i]*2}

ans = []
just = 0
(n-1).downto(0){|i|
  d = (i+1).times.map{|j| c[j]*(2**(i-j))}
  x = 2**i
  ne = l/x
  l %= x
  just += d.min*ne
  ans << just + d.min
}

ans << just

p ans.min

#!/usr/bin/ruby
include Math

INF = 0x3f3f3f3f3f3f3f3f3f3f3f3f3f3f3f3f

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

best = []
best[0] = INF
res = INF
for i in 1..n
	best[i] = [2*best[i-1], cost[i-1]].min
	if 2**(i-1) > v
		res = [res, best[i]].min
	end
end
for i in n+1..70
	best[i] = 2*best[i-1]
	if 2**(i-1) > v
		res = [res, best[i]].min
	end
end

ans = 0
j = 0
while v > 0
	j += 1
	if v % 2 == 1
		ans += best[j]
	end
	v /= 2
end

puts [res, ans].min

#!/usr/bin/ruby
include Math

INF = 0x3f3f3f3f3f3f3f3f3f3f3f3f3f3f3f3f

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

best = []
best[0] = INF
res = INF
for i in 1..n
	best[i] = [2*best[i-1], cost[i-1]].min
	if 2**(i-1) > v
		res = [res, best[i]].min
	end
end
for i in n+1..70
	best[i] = 2*best[i-1]
	if 2**(i-1) > v
		res = [res, best[i]].min
	end
end

ans = INF
vv = v
while (vv & -vv) != vv
	temp = 0
	j = 0
	v = vv
	while v > 0
		j += 1
		if v % 2 == 1
			temp += best[j]
		end
		v /= 2
	end
	ans = [ans, temp].min
	vv += vv & -vv
end

puts [res, ans].min


n = gets.chomp.split("").collect{|i| i.to_i}
k = n.max
ans = Array.new(k){Array.new}
n.each do |i|
    for j in 0...i
        ans[j].push('1')
    end
    for j in i...k
        ans[j].push('0')
    end
end
ans = ans.collect{|i| i.join.to_i}
puts k
puts ans.join(" ")

# cook your code here
n=gets.to_i
arr = Array.new(10,0)
t=1
m=0
while n>0
    b=n%10
    j=9
    while j>9-b
        arr[j]=(arr[j]+t)
        j-=1
    end
    t=(t*10)
    if(b>m)
        m=b
    end
    n=(n/10)
end
puts m
for i in 0..9
    if arr[i]!=0
        print arr[i].to_s + ' '
    end
end

#!/usr/bin/env ruby
n=gets.chomp.chars.map(&:to_i)
a=n.size.times.map{[0]*9}
n.each_with_index{|e,i|e.times{|j|a[i][j]=1}}
a=a.transpose.map{|e|e.join.to_i}.select{|e|e>0}
p a.size
puts a*' '

n = gets.strip.split(//).map(&:to_i)
ans = n.max
puts ans
ans.times do |i|
  pp = false
  n.size.times do |j|
    if n[j] > 0
      pp = true
      print 1
      n[j] -= 1
    elsif pp
      print 0
    end
  end
  if i < ans - 1
    print " "
  end
end
puts

#http://codeforces.com/problemset/problem/538/B

n = gets.to_i

arr = Array.new(9,0)
k = 1
largest = 0
while(n!=0) do
  individual = n%10
  if individual > largest
    largest = individual
  end

  ind = 0
  individual.times do
    arr[ind] += k
    ind +=1
  end

  k= k*10
  n = n/10
end

ind = 0
puts largest
arr.select! do |i|
  i>0
end

puts arr.join(' ')

n=gets.chomp

n=n.to_i
b = n

a = 0
d = 0

c = []

while b >= 10
	a+=1
	if b%10>d
		d=b%10
	end
	c.push(b%10)

	b/=10
end

c.push(b)

a+=1

if b != 0
	if b%10>d
		d=b%10
	end
end

arr = []

for i in (1..d)
	x=0
	for j in 0..(c.length - 1)
		if c[j] > 0
			x+=10**j
			c[j]-=1
		end
	end
	arr.push(x)
end

puts arr.length

arr.each do |i|
	print i
	print ' '
end

arr=[]
c=0
gets.chomp.chars{|e|
	arr<<e.to_i
	c+=e.to_i
}
if c==0 then
	puts 1
	puts 0
else
	ans=[]
	while c!=0
		s1=""
		c1=0
		arr.map!{|e|
			if e>0 then
				e-=1
				c1+=1
				c-=1
				s1<<"1"
			else
				s1<<"0"
			end
			e
		}
		ans<<s1.to_i
	end
	puts ans.size
	puts ans*" "
end

# coding: utf-8

# Quasi Binary
# 10진수이지만 1과 0으로 나타내어져 있어서 마치 2진수처럼 보이는 그 물건
# 이라고 정의하십니다.

# n 을 유사 이진수로 쪼개어(즉, 0으로 시작되지 않으면서 1과 0의 조합으로 표현되는)
# k개의 숫자를 만들어내는 것
# 그리고 콰지바이너리의 개수를 minimum으로 한다

n = gets.chomp.split(//).map(&:to_i)
ar = []

while !n.empty?
    if n.first == 0
        n.shift
        next
    end
    arr = []
    n.each_with_index { |i, index|
        if i > 0
            arr << 1
            n[index] -= 1
        else
            arr << 0
        end
    }
    ar << arr.join
end

puts ar.length
puts ar.join(' ')

n = gets.chomp.chars.map(&:to_i)
a = []
while n.any?{|x| x > 0}
  a << n.reduce(0){|x, y| x * 10 + (y > 0 ? 1 : 0)}
  n.map!{|x| x - 1}
end
puts a.size, a * ' '

n = gets.chomp.chars.map(&:to_i)
a = []
while !n.all?{|x| x == 0}
  b = []
  n.size.times do |i|
    if n[i] > 0
      n[i] -= 1
      b << 1
    else
      b << 0
    end
  end
  a << b
end
puts a.size
puts a.map{|x| x.join('').to_i}.join(' ')

n=gets.chomp
d=Array.new
for i in 0...n.length
  d.push(n[i].to_i)
end
m=d.max
# puts "m=#{m}"
puts m
ans=[]
for i in 0...m
  num=0
  for j in 0...n.length
    num*=10
    if d[j]>0
      d[j]-=1
      num+=1
    end
  end
  ans.push(num)
end
puts ans.join(" ")

n = gets.chomp.scan(/./)
maxx = n.map {|i| i.to_i}.max
puts maxx
for i in 0...maxx
  x = [0] * n.length
  for j in 0...n.length
    if n[j].to_i != 0
      x[j] = 1
      n[j] = (n[j].to_i - 1).to_s
    end
  end
  print x.join('').to_i, ' '
end

puts "Please enter your number:"
print '> '

n=gets.chomp

n=n.to_i
b = n

a = 0
d = 0

c = []

while b > 10
	a+=1
	if b%10>d
		d=b%10
	end
	c.push(b%10)

	b/=10
end

c.push(b)

a+=1

if b != 0
	if b%10>d
		d=b%10
	end
end

arr = []

for i in (1..d)
	x=0
	for j in 0..(c.length - 1)
		if c[j] > 0
			x+=10**j
			c[j]-=1
		end
	end
	arr.push(x)
end

puts arr.length

arr.each do |i|
	print i
	print ' '
end

n = gets.to_i
l = n.to_s.chars.length
s = ('1' * l).to_i
a = []
while n != 0
  if n - s >= 0
    n -= s
    a << s
  else
    t = s.to_s
    if t.count('1') >= 2
      t[t.rindex('1')] = '0'
      s = t.to_i
    else
      s /= 10
    end
  end
end
puts a.size
puts a.join(' ')

n = gets.to_i
l = n.to_s.chars.length
s = ('1' * l).to_i
a = []
while n != 0
  if n - s >= 0
    n -= s
    a << s
  else
    t = s.to_s
    if t.count('1') >= 2
      t[t.rindex('1')] = '0'
      s = t.to_i
    else
      s /= 10
    end
  end
end
puts a.join(' ')


a=gets.chomp.to_i
b=gets.chomp.split(" ")
ans=0

loop do
if b[0]=="0"
b.delete_at(0)
else
break
end
end
loop do
if b[b.length-1]=="0"
b.delete_at(b.length-1)
else
break
end
end

0.upto(b.length) do |i|
break if b[i]==nil
if b[i]=="1"
ans+=1
elsif b[i-1]=="1" && b[i+1]=="1"
ans+=1
end
end

puts "#{ans}"

n=gets.to_i
a=gets.split(" ").map(&:to_i).map{|x| x == 1 }

univ = false
count = 0
for i in 0...a.size
	if !univ
		if a[i]
			univ = true
		end
	end
	if univ && !a[i] && !a[i+1]
		univ = false
	end

	count += 1 if univ
end

p count

n, pairs = gets.chomp.to_i, gets.chomp.split(" ").join("")
pairs.gsub! /(^0+|00+|0+$)/, ""
puts pairs.length

n, pairs = gets.chomp.to_i, gets.chomp.split(" ")
loop do
	pairs[0] == "0" ? pairs.delete_at(0) : break
end
loop do
	pairs[-1] == "0" ? pairs.delete_at(-1) : break
end
pairs = pairs.join ""
pairs.gsub! /00+/, ""
puts pairs.length

n = gets.chomp.to_i
v = gets.split.map{ |x| x.to_i}

start = -1
last = n+1
zero = 0
less = 0
n.times do |i|
  start = i if v[i] == 1 and start == -1
  last = i if v[i] == 1
  if v[i] == 0 and start != -1
    zero += 1
  end
  if v[i] == 1
    if zero >= 2
      less += zero
    end
    zero = 0
  end
end
if start != -1
  puts last-start-less+1
else
  puts 0
end

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

arr.pop if arr.last == '0'
arr.shift if arr.first == '0'
puts arr.join.gsub(/00/, '').length

gets
a = gets.split(' ').map! {|x| x.to_i} << 0
a.unshift(0)
ans = 0

a.size.times do |i|
    ans += 1 if (a[i] == 1.to_i) || ((a[i - 1] == 1) && (a[i + 1] == 1))
end

p ans

#! ruby
# try Codeforces
# author: Leonardone @ NEETSDKASU

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

stay = :HOME
count = 0
i = 0

while i < n
	case stay
	when :HOME
		if a[i] == 1
			stay = :UNIV
		end
	when :UNIV
		if a[i] == 0
			if i == n - 1 || a[i + 1] == 0
				stay = :HOME
			end
		end
	end
	count += 1 if stay == :UNIV
	i += 1
end

puts count

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

	x<<0
	ans=0
	i=0
	while i<(x.size-1) && x[i]==0
		i+=1
	end
	while i<(x.size-1)
		if x[i]!=0 || x[i+1]!=0 then
			ans+=1
			i+=1
		else
			while i<(x.size-1) && x[i]==0
				i+=1
			end
		end
	end
	puts ans

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

for i in 0..n-3
  if as[i] * as[i + 2] == 1 && as[i + 1] == 0
    as[i + 1] = 1
  end
end

puts as.inject{|s, a| s + a }

n = gets.to_i
a = gets.split.map(&:to_i)
status, ans = 0, 0
n.times do |i|
  if a[i] == 1
    status = 1
    ans += 1
  elsif status == 1 && (i != 0 && a[i - 1] == 1) && (i + 1 != n && a[i + 1] == 1)
    ans += 1
  end
end
p ans

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

# coding: utf-8

n = gets.to_i
sched = gets.strip.gsub(' ', '')

sched.gsub!(/^0+/, '')
sched.gsub!(/0+$/, '')
sched.gsub!(/0{2,}/, '')

puts sched.length.to_s

# #325 Div2 A. Alena's Schedule
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
lesson = 0
rest = 0
a.each do |i|
  if i == 1 then
    if rest == 1 and lesson > 0 then
      lesson += 1
    end
    rest = 0
    lesson += 1
  else
    rest += 1
  end
end
puts lesson

totNum = gets.chomp.to_i
classArr = gets.chomp.split(' ').map {|item| item.to_i}
start = false
breaks = 0
ans = 0
classArr.each_with_index do |val, idx|
	#puts "idx : #{idx} , val : #{val} , classArr[idx + 1] : #{classArr[idx + 1]}"
	break if idx == classArr.length - 1
	start = true if (val == 1 && !start)
	#puts "start 1 step : #{start}"
	next if !start
	start = false if (val == 0 && classArr[idx + 1] == 0)
	#puts "start 2 step : #{start}"
	next if !start
	ans += 1
end
ans += 1 if classArr[totNum - 1] == 1
puts ans

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

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

# http://codeforces.com/contest/586/problem/A
# A. Alena's Schedule
n = gets.chomp.to_i
arr = gets.chomp.split.map(&:to_i)

arr.pop if arr.last == 0
arr.shift if arr.first == 0
puts arr.join.gsub(/00/, '').length

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

arr.pop if arr.last == 0
arr.shift if arr.first == 0
puts arr.join.gsub(/00/, '').length

gets.to_i
a = gets.split(' ').map! {|x| x.to_i}
p 0 if a.index(1) == nil
p (a.rindex(1) - a.index(1) + 1)

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

n=gets.to_i
x=gets.split.map{|e| e.to_i}
if n==1 then
	puts 1
else
	x<<0
	ans=0
	i=0
	while i<(x.size-1) && x[i]==0
		i+=1
	end
	while i<(x.size-1)
		if x[i]!=0 || x[i+1]!=0 then
			ans+=1
			i+=1
		else
			while i<(x.size-1) && x[i]==0
				i+=1
			end
		end
	end
	puts ans
end

n = gets.to_i
a = gets.split.map(&:to_i)
# ab = a.slice_when{|x, y| x != y }.select{|x| x.inject(:+) == 0}
ab = a
ab.shift if a[0] == 0
ab.pop if a[n - 1] == 0
ans = a.inject(:+) + ab.inject(0){|sum, n| sum + (n.size == 1 ? n.size : 0)}
puts ans

n = gets.to_i
a = gets.split.map(&:to_i)
ans = n
status = 0
n.times do |i|
  if status.zero? && a[i] == 0
    ans -= 1
  elsif a[i] == 1
    status = 1
  elsif status == 1 && a[i] == 0 && (a[i - 1] == 0 || a[i + 1] == 0)
    ans -= 1
  end
end
ans -= 1 if a[-1] == 0 && n != 1
p ans

n = gets.to_i
a = gets.split.map(&:to_i)
ans = n
status = 0
n.times do |i|
  if status.zero? && a[i] == 0
    ans -= 1
  elsif a[i] == 1
    status = 1
  elsif status == 1 && a[i] == 0 && (a[i - 1] == 0 || a[i + 1] == 0)
    ans -= 1
  end
end
ans -= 1 if a[-1] == 0 && n != 1 && status == 1
p ans

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


def pow(a, b, mod)
  ret = 1
  while b > 0
    if (b & 1 == 1)
      ret = ret * a % mod
    end
    b = b / 2
    a = a * a % mod
  end
  return ret
end
(n, m, k) = gets.chomp.split.map(&:to_i)
mod = 10**9 + 7
ans = pow(pow(2, n - 1, mod), m - 1, mod)
if (n % 2 != m % 2 and k == -1)
  ans = 0
end
print ans

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

n, m, k = gets.split.map(&:to_i)
if((n + m) % 2 == 1 && k == -1)
    p 0
else
    md = 1000000007
    p power(2, (n-1)*(m-1), md)
end

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

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


line = $stdin.gets.strip.split(/\s+/)
a = line[0].to_i
b = line[1].to_i
m = line[2].to_i
r = line[3].to_i
m.times {r = (a*r + b) % m } #going through the pre-period
rr = r
i = 0
loop do
  i += 1
  r = (a*r + b) % m
  if rr == r
    puts i
    exit 0
  end
end

a, b, m, r = gets.split.map(&:to_i)
t, s = [nil] * r, 0
loop do
    if t[r]
        p s - t[r]
        break
    else
        t[r] = s
        r = (a * r + b) % m
        s += 1
    end
end

a,b,m,r=gets.split.map(&:to_i)
back_r=Hash.new
back_r[r]=(now=0)
loop do
        r=(a*r+b)%m
        now+=1
        if back_r.key?(r)
                puts now-back_r[r]
                break
        end
        back_r[r]=now
end

input = STDIN.read

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

values1, values2 = Array.new, Array.new

def get_next_value(a, b, m, r)
  r ||= $r0
  (a * r + b) % m
end

element = nil

while true
  values1 << get_next_value(a, b, m, values1.last)
  values2 << get_next_value(a, b, m, values2.last)
  values2 << get_next_value(a, b, m, values2.last)

  if values1.last == values2.last
    element = values1.last
    break
  end
end

result = -1
i = values2.length - 2
until i < 0
  if element == values2[i]
    result = values2.length - 1 - i
    break
  end
  i -= 1
end

puts result

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

ar = Array.new(m)
ar[r]=0
i = 0
loop do
  i += 1
  r = (a*r+b)%m
  if ar[r]
    puts i - ar[r]
    break
  end
  ar[r] = i
end

a,b,m,r=gets.split.map &:to_i;
v=[0]*m;v[r=(a*r+b)%m]+=1 while v[r]!=3;
print 1+v.count(2);

a,b,m,r = gets.split.map &:to_i
ar = [nil]*100000
i = 0
while true
    r = (a*r+b)%m
    if ar[r]
        p i-ar[r]
        exit
    end
    ar[r] = i
    i += 1
end

a, b, m, r0 = gets.split.map{|i| i.to_i}
s = Array.new(100000, 0)
t = 1
r = r0
while s[r] == 0
        s[r] = t
        t += 1
        r = (a * r + b) % m
end
puts t - s[r]

a,b,m,r = gets.split.map &:to_i
t = [0]*m
while t[r] != 3
	t[r = (a*r+b)%m] += 1
end

puts 1+t.count(2)


x,y = gets.split.map(&:to_i)
prime = []
k = (y**0.5).to_i
k = x if k > x
a = Array.new(k+1,1)
i = 2
while i <= k
  if a[i] == 1
    prime << i
    (k/i).times do |j|
      a[i*j] = 0
    end
  end
  i += 1
end
isprime = false
while !isprime && x < y
  isprime = true
  prime.length.times do |i|
    isprime = false if y % prime[i] == 0
  end
  if isprime
    ans = y
  end
  y -= 1
end
ans = -1 if !isprime
puts ans

require 'prime'

def maxprime(x, y)
    y.downto(x){|n| return n if n.prime? }
    -1
end

p, y=gets.split.map &:to_i
q=maxprime(p+1, y)

if q==-1
    puts -1
    exit
end

p=maxprime(2, p)
res=q;
q.upto(y){|x| res=x if x.prime_division[0][0]>p}
puts res

x,y = gets.split.map(&:to_i)
prime = []
k = (y**0.5).to_i

a = Array.new(k+1,1)
i = 2
while i <= k
  if a[i] == 1
    prime << i
    (k/i).times do |j|
      a[i*j] = 0
    end
  end
  i += 1
end
isprime = false
while !isprime && x < y
  isprime = true
  prime.length.times do |i|
    isprime = false if y % prime[i] == 0
  end
  if isprime
    ans = y
  end
  y -= 1
end
ans = -1 if !isprime
puts ans

require 'prime'
p, y=gets.split.map &:to_i
y.downto(p+1){|x|
    if x.prime?
        puts x
        exit
    end
}
puts -1


n = gets.to_i
i, mx, mn = 0, 0, 1e10
while i*i*i <= n
 i += 1
 next if n%i > 0
 j = i-1
 while i*j*j <= n
  j += 1
  next if n/i%j > 0
   mx = [mx, (i+2)*(j+2)*(n/i/j+1)].max
   mn = [mn, (i+1)*(j+2)*(n/i/j+2)].min
 end
end
puts [mn-n, mx-n] * " "

require 'prime'

def sub(b, s)
  if b.empty?
    v = (s[0]+1)*(s[1]+2)*(s[2]+2) - s[0]*s[1]*s[2]
    return [v, v]
  end

  b = b.dup
  k, v = b.pop

  result = [1e100, 0]
  0.upto(v) do |i|
    0.upto(v-i) do |j|
      mn, mx = sub(b, [s[0]*k**i, s[1]*k**j, s[2]*k**(v-i-j)])
      result[0] = [result[0], mn].min
      result[1] = [result[1], mx].max
    end
  end

  result
end

def solve(n)
  a = Prime.prime_division(n)

  s1 = sub(a, [1, 1, 1])

=begin
  b = a.map{|k,v| [k]*v}.flatten
  r = []
  (3**b.size).times do |i|
    o = [1]*3
    ("0"*b.size+i.to_s(3))[-b.size,b.size].each_char.zip(b) do |j, k|
      o[j.to_i] *= k
    end
    r << [(o[0]+1)*(o[1]+2)*(o[2]+2) - o[0]*o[1]*o[2], o]
  end
  s2 = [r.min[0], r.max[0]]
=end
  s1
end

n = gets.to_i
puts solve(n)*" "

n = gets.to_i
i, mx, mn = 0, 0, 1e9
while i*i*i <= n
 i += 1
 next if n%i > 0
 j = i-1
 while i*j*j <= n
  j += 1
  next if n/i%j > 0
   mx = [mx, (i+2)*(j+2)*(n/i/j+1)].max
   mn = [mn, (i+1)*(j+2)*(n/i/j+2)].min
 end
end
puts [mn-n, mx-n] * " "


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

n = $stdin.gets.to_i
xs = $stdin.gets.chomp.chars.map(&:to_i)
ys = xs[0 .. n-1].sort
zs = xs[n .. 2*n-1].sort

puts (ys.zip(zs).all? { |y, z| y < z } or ys.zip(zs).all? { |y, z| y > z }) ? 'YES' : 'NO'

n = gets.chomp.to_i
a = gets.chomp.split(//).map!{|x| x.to_i}
q = Array.new
w = Array.new
for i in 0..n-1
    q[i] = a[i]
    w[i] = a[n+i]
end

q = q.sort
w = w.sort

if q[0] < w[0]
    t = 0
elsif q[0] > w[0]
    t = 1
else
    t = 2
end

for i in 1..n-1
    if q[i] < w[i] && t === 1
        t = 2
        break
    elsif q[i] > w[i] && t === 0
        t = 2
        break
    elsif q[i] === w[i]
        t = 2
        break
    elsif t === 2
        break
    end
end

if t === 2
    puts "NO"
else
    puts "YES"
end

n = gets.to_i
a = gets.strip

f = a[0..n-1].split(//).map(&:to_i).sort
s = a[n..2*n].split(//).map(&:to_i).sort

z = f.zip(s)
print (z.all?{|e| e[0] > e[1]} || z.all?{|e| e[0] < e[1]}) ? "YES" : "NO"

#!/usr/bin/ruby
n = STDIN.gets.chomp.to_i
line = STDIN.gets.chomp
left = line[0..n-1].split(//).map(&:to_i).sort
right = line[n..2*n].split(//).map(&:to_i).sort

ok1 = true
0.upto(n - 1) do |i|
    ok1 &= left[i] < right[i]
end

ok2 = true
0.upto(n - 1) do |i|
    ok2 &= left[i] > right[i]
end

if ok1 or ok2
    puts "YES"
else
    puts "NO"
end

n = Integer(gets)
input = gets.chomp
num = Array.new
for i in 0...2*n
    num[i] = Integer(input[i])
end
left = Array.new
right = Array.new
for i in 0...n
    left.push(num[i])
    right.push(num[i + n])
end
left = left.sort
right = right.sort

def less(left,right)
    if left < right
        return true
    else
        return false
    end
end
def more(left,right)
    if left > right
        return true
    else
        return false
    end
end
c = 0
if n == 1
    if left[0] != right[0]
        c = 1
    end
else

    if left[0] > right[0]
        for i in 1...n
            if more(left[i],right[i])
                c = 1
            else
                c = 0
                break
            end
        end
    elsif left[0] < right[0]
        for i in 1...n
            if less(left[i],right[i])
                c = 1
            else
                c = 0
                break
            end
        end
    end
end
if c == 1
    puts "YES"
else
    puts "NO"
end

n = gets.to_i
a = gets.split("")
a.pop

for i in 0 ... a.size
	a[i] = a[i].to_i
end

b = a[0...a.size/2]
c = a[a.size/2...a.size]

b.sort!
c.sort!

ans = true
for i in 1...a.size/2
	if b[0] < c[0] then
		if b[i] >= c[i] then
			ans = false
			break
		end
	elsif b[0] > c[0] then
		if b[i] <= c[i] then
			ans = false
			break
		end
	else
		ans = false
		break
	end
end
if n == 1 then
	ans = (b[0] != c[0])
end

if ans then
	puts("YES")
else
	puts("NO")
end

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

n = input[0].to_i
nums = input[1].split('').map(&:to_i)

num1 = nums[0..n-1].sort!
num2 = nums[n..-1].sort!

if num1[0] > num2[0]
	more = true
elsif num1[0] < num2[0]
	more = false
else
	STDOUT.puts "NO"
	exit
end

num1.length.times do |i|
	if more
		if num1[i] <= num2[i]
			STDOUT.puts "NO"
			exit
		end
	else
		if num1[i] >= num2[i]
			STDOUT.puts "NO"
			exit
		end
	end
end

STDOUT.puts "YES"

# http://codeforces.ru/problemset/problem/160/B

def run(input = STDIN.read)
  lines = input.split("\n")

  n       = lines[0].to_i
  ticket  = lines[1].split("").map(&:to_i)

  first   = ticket.take(ticket.size / 2).sort
  second  = ticket.drop(ticket.size / 2).sort

  if (0..n-1).all? { |i| first[i] < second[i] } or
     (0..n-1).all? { |i| first[i] > second[i] } then
    return 'YES'
  else
    return 'NO'
  end
end

begin
  require './testing.rb'
rescue LoadError
  puts run
end
__END__
2
2421
=
YES
---
2
0135
=
YES
---
2
3754
=
NO

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

n       = lines[0].to_i
ticket  = lines[1].split("").map(&:to_i)

first   = ticket.take(ticket.size / 2).sort
second  = ticket.drop(ticket.size / 2).sort

if (0..n-1).all? { |i| first[i] < second[i] } or
   (0..n-1).all? { |i| first[i] > second[i] } then
  puts 'YES'
else
  puts 'NO'
end

n = gets.to_i

ticket = []
ticket[0] = gets(n)
ticket[1] = gets(n)

ticket[0] = ticket[0].chars.sort.join
ticket[1] = ticket[1].chars.sort.join

unlucky = true
for i in (0..ticket[0].length-1)
  if ticket[0][i] >= ticket[1][i]
    unlucky = false
    break
  end
end

if unlucky; puts "YES"; Process.exit; end

unlucky = true
for i in (0..ticket[0].length-1)
  if ticket[0][i] <= ticket[1][i]
    unlucky = false
    break
  end
end

if unlucky; puts "YES"; Process.exit; end

puts "NO"

n = gets.chomp.to_i
digits = gets.chomp.split("").collect{|i| i.to_i}

left  = digits[0..n-1].sort
right = digits[n..-1].sort

if left[0] == right[0]
  puts "NO"
  exit
end

if left[0] > right[0]
  left, right = [right, left]
end

n.times{|i|
  if left[i] >= right[i]
    puts "NO"
    exit
  end
}

puts "YES"

n=gets.to_i
s=gets.split''
puts ((0...n).map{|i| s[0...n].sort[i]<=>s[n...n+n].sort[i] }.reduce(:+).abs==n) ? :YES : :NO

n = gets.to_i
s = gets.split('')
l = s[0...n].sort!
r = s[n...n+n].sort!
puts ((0...n).map{ |i| l[i] <=> r[i] }.reduce(:+).abs == n) ? "YES" : "NO"

n = Integer(gets.chomp)
digits = gets.chomp.split('').map { |x| x.to_i }
first_half = digits[0...n].sort
second_half = digits[n..-1].sort
op = first_half.first < second_half.first ? :< : first_half.first > second_half.first ? :> : :!=
res = true
for i in 0...n
  unless [first_half[i], second_half[i]].inject(op)
    res = false
    break
  end
end
puts(res ? 'YES' : 'NO')

l = gets.chomp.to_i
n = gets.chomp
a = n.split('');
d = []

a.each_index{|i| d[i] = a[i].to_i}
#puts d.first(1);
b = d.first(l);
c = d.last(l);
b = b.sort
c = c.sort
#puts b
#puts c
b.each_index{|i| b[i] -= c[i]}

b = b.sort
#puts b
if b[0]*b[-1] <= 0 then
  puts "NO"
else
  puts "YES"
end

n = gets.to_i
s = gets.chomp
t = [s[0, n], s[n, n]].map{|_| _.chars.to_a.sort}.transpose
puts t.all?{|i, j| i < j} || t.all?{|i, j| i > j} ? :YES : :NO

def solve(a,b)
        x=[]
        y=[]
        a.length.times do |i|
                x.push(a[i].to_i)
                y.push(b[i].to_i)
        end
        x.sort!
        y.sort!

        a.length.times do |i|
                return false if x[i]>=y[i]
        end
        return true
end

n=gets.to_i
a=gets.split[0]
x=a[0..n-1]
y=a[n..2*n-1]
if solve(x,y) || solve(y,x)
        puts "YES"
else
        puts "NO"
end

n = gets.to_i
s = gets.chomp

l = s[0...n].split(//).map(&:to_i).sort
r = s[n...2*n].split(//).map(&:to_i).sort

lh, rh = true, true
for i in 0...n do
  lh = lh && l[i] < r[i]
  rh = rh && l[i] > r[i]
end

puts(if lh || rh then "YES" else "NO" end)

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

first = a[0..(n - 1)].sort!
second = a[n..(2 * n - 1)].sort!

less = true
more = true
0.upto(n - 1) do |i|
  if first[i] <= second[i]
    less = false
  end

  if first[i] >= second[i]
    more = false
  end
end

if less or more
  puts "YES"
else
  puts "NO"
end

n = STDIN.readline.to_i
s = STDIN.readline.strip
a, b = s[0..n-1], s[n..2*n-1]
a = a.split('').map {|s| s.to_i }.sort
b = b.split('').map {|s| s.to_i }.sort
less, greater = true, true
n.times do |i|
  less = false if a[i] >= b[i]
  greater = false if a[i] <= b[i]
end
puts less || greater ? 'YES' : 'NO'

n,s = gets.to_i, gets.strip.split('').map(&:to_i)
a,b = s[0..n-1].sort.reverse, s[n..-1].sort.reverse
b = a.zip(b).map { |x,y| x-y }
puts (b.find_all { |x| x < 0 }.size == n or b.find_all { |x| x > 0 }.size == n) ? "YES" : "NO"

def check(b)
  f = true
  if b[0] > 0 then
    f = true
  else
    f = false
  end
  b.each { |el|
    if (f && el < 0 || !f && el > 0 || el == 0)
      puts "NO"
      return
    end
  }

  puts "YES"

end

l = gets.chomp.to_i
n = gets.chomp
a = n.split('');
d = []

a.each_index{|i| d[i] = a[i].to_i}
#puts d.first(1);
b = d.first(l);
c = d.last(l);
b.each_index{|i| b[i] -= c[i]}

check(b)

def check(b)
  f = true
  if b[0] > 0 then
    f = true
  else
    f = false
  end
  b.each { |el|
    if (f && el < 0 || !f && el > 0)
      puts "NO"
      return
    end
  }

  puts "YES"

end

l = gets.chomp.to_i
n = gets.chomp
a = n.split('');
d = []

a.each_index{|i| d[i] = a[i].to_i}
#puts d.first(1);
b = d.first(l);
c = d.last(l);
b.sort
c.sort

b.each_index{|i| b[i] -= c[i]}

check(b)

def check(b)
  f = true
  if b[0] > 0 then
    f = true
  else
    f = false
  end
  b.each { |el|
    if (f && el < 0 || !f && el > 0)
      puts "NO"
      return
    end
  }

  puts "YES"

end

l = gets.chomp.to_i
n = gets.chomp
a = n.split('');
d = []

a.each_index{|i| d[i] = a[i].to_i}
#puts d.first(1);
b = d.first(l);
c = d.last(l);
b.each_index{|i| b[i] -= c[i]}

check(b)

l = gets.chomp.to_i
n = gets.chomp
a = n.split('');
d = []

a.each_index{|i| d[i] = a[i].to_i}
#puts d.first(1);
b = d.first(l);
c = d.last(l);
b.sort
c.sort

b.each_index{|i| b[i] -= c[i]}

b.sort
if b[0]*b[-1] <= 0 || b[0] == b[-1] then
  puts "NO"
else
  puts "YES"
end

l = gets.chomp.to_i
n = gets.chomp
a = n.split('');
d = []

a.each_index{|i| d[i] = a[i].to_i}
#puts d.first(1);
b = d.first(l);
c = d.last(l);
b.each_index{|i| b[i] -= c[i]}
f = true
if b[0] > 0 then
  f = true
else
  f = false
end

b.each { |el|
  if (f && el < 0 || !f && el < 0 || f == 0)
    puts "NO"
    return
  end
}

l = gets.chomp.to_i
n = gets.chomp
a = n.split('');
d = []

a.each_index{|i| d[i] = a[i].to_i}
#puts d.first(1);
b = d.first(l);
c = d.last(l);
b.sort
c.sort

b.each_index{|i| b[i] -= c[i]}

b.sort
if b[0]*b[-1] < 0 || b[0] == b[-1] then
  puts "NO"
else
  puts "YES"
end

l = gets.chomp.to_i
n = gets.chomp
a = n.split('');
d = []

a.each_index{|i| d[i] = a[i].to_i}
#puts d.first(1);
b = d.first(l);
c = d.last(l);
b.sort
c.sort

b.each_index{|i| b[i] -= c[i]}

b.sort
if b[0]*b[-1] < 0 then
  puts "NO"
else
  puts "YES"
end

def check(b)
  f = true
  if b[0] > 0 then
    f = true
  else
    f = false
  end
  b.each { |el|
    if (f && el < 0 || !f && el < 0 || f == 0)
      puts "NO"
      return
    end
  }

  puts "YES"

end

l = gets.chomp.to_i
n = gets.chomp
a = n.split('');
d = []

a.each_index{|i| d[i] = a[i].to_i}
#puts d.first(1);
b = d.first(l);
c = d.last(l);
b.each_index{|i| b[i] -= c[i]}

check(b)

def check(b)
  f = true
  if b[0] > 0 then
    f = true
  else
    f = false
  end
  b.each { |el|
    if (f && el < 0 || !f && el > 0 || el == 0)
      puts "NO"
      return
    end
  }

  puts "YES"

end

l = gets.chomp.to_i
n = gets.chomp
a = n.split('');
d = []

a.each_index{|i| d[i] = a[i].to_i}
#puts d.first(1);
b = d.first(l);
c = d.last(l);
b.sort
c.sort
b.each_index{|i| b[i] -= c[i]}

check(b)

def solve(a,b)
        a.length.times do |i|
                return false if a[i].to_i<=b[i].to_i
        end
        return true
end

n=gets.to_i
a=gets.split[0]
x=a[0..n-1]
y=a[n..2*n-1]
if solve(x,y) || solve(y,x)
        puts "YES"
else
        puts "NO"
end

n = gets.to_i
s = gets.chomp

l = s[0...n].split(//).map(&:to_i)
r = s[n...2*n].split(//).map(&:to_i)

lh, rh = true, true
for i in 0...n do
  lh = lh && l[i] < r[i]
  rh = rh && l[i] > r[i]
end

puts(if lh || rh then "YES" else "NO" end)

n = gets.chomp.to_i
a = gets.chomp.split(//).map!{|x| x.to_i}
q = Array.new
w = Array.new
for i in 0..n-1
    q[i] = a[i]
    w[i] = a[n+i]
end

q = q.sort
w = w.sort

if q[0] < w[0]
    t = 0
elsif q[0] > w[0]
    t = 1
else
    t = 2
end

for i in 1..n-1
    if q[i] < w[i] && t === 1
        t = 2
        break
    elsif q[i] > w[i] && t === 0
        t = 2
        break
    elsif t == 2
        break
    end
end

if t === 2
    puts "NO"
else
    puts "YES"
end

n = Integer(gets)
input = gets.chomp
num = Array.new
for i in 0...2*n
    num[i] = Integer(input[i])
end
left = Array.new
right = Array.new
for i in 0...n
    left.push(num[i])
    right.push(num[i + n])
end
left = left.sort
right = right.sort

def less(left,right)
    if left < right
        return true
    else
        return false
    end
end
def more(left,right)
    if left > right
        return true
    else
        return false
    end
end
c = 0
if n == 1
    if left[0] != right[0]
        c = 1
    end
else

    if left[0] > right[0]
        for i in 1...n
            if more(left[i],right[i])
                c = 1
            else
                c = 0
            end
        end
    elsif left[0] < right[0]
        for i in 1...n
            if less(left[i],right[i])
                c = 1
            else
                c = 0
            end
        end
    end
end
if c == 1
    puts "YES"
else
    puts "NO"
end

n = Integer(gets)
input = gets.chomp
num = Array.new
for i in 0...2*n
	num[i] = Integer(input[i])
end
left = Array.new
right = Array.new
for i in 0...n
	left.push(num[i])
	right.push(num[i + n])
end
left = left.sort
right = right.sort
def less(left,right)
	if left < right
		return true
	else
		return false
	end
end
def more(left,right)
	if left > right
		return true
	else
		return false
	end
end
c = 0
if left[0] > right[0]
	for i in 1...n
		if more(left[i],right[i])
			c = 1
		else
			c = 0
		end
	end
elsif left[0] < right[0]
	for i in 1...n
		if less(left[i],right[i])
			c = 1
		else
			c = 0
		end
	end
end

if c == 1
	puts "YES"
else
	puts "NO"
end

# http://codeforces.ru/problemset/problem/160/B

def run(input = STDIN.read)
  lines = input.split("\n")

  n       = lines[0].to_i
  ticket  = lines[1].split("").map(&:to_i)

  first   = ticket.take(ticket.size / 2).sort
  second  = ticket.drop(ticket.size / 2).sort

  if (0..n-1).all? { |i| first[i] < second[i] } or
     (0..n-1).all? { |i| first[i] > second[i] } then
    return 'YES'
  else
    return 'NO'
  end
end

begin
  require './testing.rb'
rescue LoadError
  run
end
__END__
2
2421
=
YES
---
2
0135
=
YES
---
2
3754
=
NO

n = STDIN.gets.to_i
ticket = STDIN.gets.split("").map(&:to_i)

first = ticket.take(ticket.size / 2).sort
second = ticket.drop(ticket.size / 2).sort

if (0..n-1).all? { |i| first[i] <= second[i] } or
   (0..n-1).all? { |i| first[i] >= second[i] } then
  puts 'YES'
else
  puts 'NO'
end

n = STDIN.gets.to_i
ticket = STDIN.gets.split("").map(&:to_i)

first = ticket.take(ticket.size / 2).sort
second = ticket.drop(ticket.size / 2).sort

if ((0..n-1).all? { |i| first[i] < second[i] } or
    (0..n-1).all? { |i| first[i] > second[i] }) then
  puts 'YES'
else
  puts 'NO'
end

n = STDIN.gets.to_i
ticket = STDIN.gets.split("").map(&:to_i)

first = ticket.take(ticket.size / 2).sort
second = ticket.drop(ticket.size / 2).sort

if (0..n-1).all? { |i| first[i] < second[i] } or
   (0..n-1).all? { |i| first[i] > second[i] } then
  puts 'YES'
else
  puts 'NO'
end

n = gets.to_i
a = gets.split("")
a.pop

for i in 0 ... a.size
	a[i] = a[i].to_i
end

b = a[0...a.size/2]
c = a[a.size/2...a.size]

b.sort!
c.sort!

ans = true
for i in 1...a.size/2
	if b[0] < c[0] then
		if b[i] >= c[i] then
			ans = false
			break
		end
	elsif b[0] > c[0] then
		if b[i] <= c[i] then
			ans = false
			break
		end
	else
		ans = false
		break
	end
end

if ans then
	puts("YES")
else
	puts("NO")
end

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

n = input[0].to_i
nums = input[1].split('').map(&:to_i)

if nums.first > nums.last
	more = true
elsif nums.first < nums.last
	more = false
else
	STDOUT.puts "NO"
	exit
end

n.times do |i|

	if more
		if nums[i] < nums[nums.length - i - 1]
			STDOUT.puts "NO"
			exit
		end
	else
		if nums[i] > nums[nums.length - i - 1]
			STDOUT.puts "NO"
			exit
		end
	end

end

STDOUT.puts "YES"

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

n = input[0].to_i
nums = input[1].split('').map(&:to_i)

num1 = nums[0..n-1].sort!
num2 = nums[n..-1].sort!

if num1[0] > num2[0]
	more = true
elsif num1[0] < num2[0]
	more = false
else
	STDOUT.puts "NO"
	exit
end

num1.length.times do |i|
	if more
		if num1[i] < num2[i]
			STDOUT.puts "NO"
			exit
		end
	else
		if num1[i] > num2[i]
			STDOUT.puts "NO"
			exit
		end
	end
end

STDOUT.puts "YES"


n, k = gets.strip.split.map(&:to_i)
hsh = {}
('a'..'z').each.with_index{|c, i| hsh[c]=i+1 }
str = gets.strip
ary = []
str.each_char{|c| ary << hsh[c]}
ary.sort!

i = 0
ans=[ary[i]]
2.upto(k).each do
  (i+1).upto(n-1).each do |j|
    if ary[j]-ary[i] > 1
      ans << ary[j]
      i = j
      break
    end
  end
end

if ans.size == k
  puts ans.inject(:+)
else
  puts -1
end

#!/usr/bin/ruby
n,k=gets.split.map &:to_i
r=0
t=95
gets.chomp.bytes.sort.each{|b|
	if b-t>1
		t=b
		r+=b-96
		k-=1
		break if k==0
	end
}
p k>0 ? -1 : r

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

string = gets.chomp

arr = string.each_char.to_a.uniq.sort

if k > 26
  puts -1
  exit
end

weight = 0
i = 0
prevch = 'A'

def addto(char,no)
  return (char.ord+no).chr
end

len = arr.length
while k>0
  if i>=len
    puts -1
    exit
  end

  ch = arr[i]
  if ch<=addto(prevch,1)
    i+=1
    next
  end

  #p ch
  weight += ch.ord-'a'.ord+1
  k-=1
  i+=1
  prevch = ch
end

puts weight

N, k = gets.split.map(&:to_i)
S = gets.chomp.split('').map{|c| c.ord - 'a'.ord + 1}.sort
sum = 0
prev = -1
N.times do |i|
    if prev + 2 <= S[i]
        prev = S[i]
        sum += S[i]
        k -= 1
        break if k == 0
    end
end
puts k == 0 ? sum : -1

a, b = gets.chomp.split.map &:to_i
s = gets.chomp.chars.map{|x|x.ord-'a'.ord+1}.sort
res = []
i = 0

while i < a  && res.size != b
  if res.size < 1
    res << s[i]
  elsif (res[-1] - s[i]).abs > 1
    res << s[i]
  end
  i += 1
end

p res.size < b ? -1 : res.reduce(:+)

a, b = gets.split.map &:to_i
s = gets.chars.map{|x|x.ord-'a'.ord+1}.sort
res = []
i = 0

while i < a  && res.size != b
  if res.size < 1
    res << s[i]
  elsif (res[-1] - s[i])**2 > 1
    res << s[i]
  end
  i += 1
end

if res.size == b
  puts res.reduce:+
else
  puts -1
 end

a, b = gets.split.map &:to_i
s = gets.chars.map{|x|x.ord-'a'.ord+1}.sort
res = []
print s
i = 0

while i < a  && res.size != b
  if res.size < 1
    res << s[i]
  elsif (res[-1] - s[i]).abs > 1
    res << s[i]
  end
  i += 1
end

p res.size < b ? -1 : res.reduce(:+)

a, b = gets.split.map &:to_i
s = gets.chars.map{|x|x.ord-'a'.ord+1}.sort
res = []
i = 0

while i < a  && res.size != b
  if res.size < 1
    res << s[i]
  elsif (res[-1] - s[i]).abs > 1
    res << s[i]
  end
  i += 1
end

p res.size < b ? -1 : res.reduce(:+)


def f(n, a, b)
    if a > b
        f(n, b, a)
    else
        (b / n).floor + 1 - (a / n).ceil
    end
end

x, y, a, b, c, d = gets.split.map(&:to_r)
p [f(2 * x, a + b, c + d), f(2 * y, a - b, c - d)].max

def f(n, a, b)
    if a > b
        f(n, b, a)
    else
        Rational(b, n).floor + 1 - Rational(a, n).ceil
    end
end

x, y, a, b, c, d = gets.split.map(&:to_i)
p [f(2 * x, a + b, c + d), f(2 * y, a - b, c - d)].max


m, n = gets.strip.split(" ").map(&:to_i)
if m == 1 && n == 1 then
  puts 0
else
  count = 0
  i = 0
  while (i < n) do
    if n - i >= 2 then
      m.times {count += 1}
      i += 2
    else
      (m / 2).times {count += 1}
      i += 1
    end
  end
end
puts count

n,m = gets.split.map{|r| r.to_i}
max = m*n
puts max/2

t = $stdin.readline.split
m = t[1].to_i
n = t[0].to_i

k = 0
imax = (n%2==0) ? n : n-1
jmax = (m%2==0) ? m : m-1
tmax = n*m/2 - imax*jmax/2

puts imax*jmax/2 +  tmax

n, m = gets.split.map(&:to_i)
puts (n*m*0.5).floor

input = gets.split().map { |item| item.to_i }
if input[0] % 2 == 0
	puts input[0] / 2 * input[-1]
else puts input[0] / 2 * input[-1] + input[-1] / 2
end

m, n = gets.split(' ').map(&:to_i)
print m*n/2

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

puts m * n / 2

a=gets.chomp.split(" ")
c=a[0].to_i*a[1].to_i
b=(c/2)
puts"#{b}"

a,b=gets.split.map{|e| e.to_i}
puts (a*b)/2

require 'scanf'
input_data = $stdin.readline

m, n = input_data.scanf('%d%d')

#if m == 1 && n == 1
#  res = 0
#else
  res = (m*n)/2
#end

puts res

m, n = gets.chomp.split(' ').map{|a| a.to_i}
puts (m*n/2).floor

def solve a,b
	if a==1
		b/2
	elsif a==2
		b
	else
		solve(a-1, b-1)+a/2+b/2
	end
end

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

m, n = gets.chomp.split.map{ |x| x.to_i }
puts m*n/2

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

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

print c

m, n = gets().split(' ').map {|p| p.to_i}

if m.even?
        puts (m/2)*n
elsif n.even?
        puts (n/2)*m
else
        puts (m*n-1)/2
end

m,n = gets.split.map {|x| x.to_i}
puts (m*n)/2

input = gets.chomp.split(" ").map { |x| x.to_i}
M = input[0]
N = input[1]

places = (0..M*N-1).to_a
edges = {}
tiles = 0
for i in places
  temp = []
  if i-1>=0
    temp.push i-1
  end
  if i+1<M*N
    temp.push i+1
  end
  if i-N>=0
    temp.push i-N
  end
  if i+N<M*N
    temp.push i+N
  end

  edges[i] = temp
end

if M.even?
  puts (M/2)*N
  exit
end
if N.even?
  puts (N/2)*M
  exit
end

while places.count > 0
  place = places.pop
  options = edges[place]
  good = false
  for option in options
    if places.include?(option)
      places.delete option
      good = true
      break
    end
  end
  if good
    tiles += 1
  else
    break
  end
end
puts tiles

arr = gets.split(" ")
m = arr[0].to_i
n = arr[1].to_i

result = m * (n / 2)
if n > 2 and n % 2 == 1
    result = result + (m / 2)
end

print result

require 'scanf'
STDIN.read.split("\n").each do |line|
  m, n = line.scanf("%d%d")
  puts m * n / 2
end

a, b = gets.strip.split(" ").map(&:to_i)
puts (((a*b)/2).to_i)

#puts "Enter the dimensions of rectangle\n"
m,n = gets.split.map(&:to_i)
if m == n
    a = (m*n)/2
    puts a
else
    b = (m*n)/2
    r = n/2
    s = r*m
    d = m/2
    v = d*n
    if s>=v
        if s >= b
            puts s
        else
            puts b
        end
    else
        if v >= b
            puts v
        else
            puts b
        end
    end
end

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

input_N = gets.chomp.split()
print (input_N.at(0).to_i * input_N.at(1).to_i)/2
print "\n"

input = gets.chomp.split(' ')
x = input.first.to_i * input.last.to_i
if x%2==1
	x -= 1
end
puts x/2

dim = gets.chomp().split(" ").map(&:to_i)
tiles = dim[0] * dim[1]

puts (tiles - (tiles % 2)) / 2

m, n = STDIN.gets.split.map(&:to_i)
puts m*n/2

(n, m) = gets.split(/\s/).map &:to_i
puts n * m / 2

m, n = gets.split.map(&:to_i)
c = (m*n)/2

puts c

s = gets.split(" ")
n = s[0].to_i
m = s[1].to_i
rez1 = 0
rez2 = 0
if n % 2 == 1
rez1 += m / 2;
 end
rez1 += (n / 2) * m
if m % 2 == 1
rez2 += n / 2;
end
rez2 += (m / 2) * n
rez = [rez1, rez2].max
puts(rez)

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

puts (m * n) / 2

n, m = gets.chomp.split(' ').map(&:to_i)
puts n * m / 2

input = gets.chomp.split(" ")

n = input[0].to_i
m = input[1].to_i

mult = n * m

puts mult / 2

def solve(m, n)

  num_dominoes = 0
  p = m / 2

  num_dominoes = p * n

  q = m % 2

  num_dominoes += n / 2 if q == 1

  num_dominoes

end

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

puts solve(m, n)

a = STDIN.gets.split(" ")

puts "#{a[0].to_i * a[1].to_i / 2}"

buf = gets.split(' ').map(&:to_i)
a, b = buf[0], buf[1]
puts a * b / 2

in_m, in_n = STDIN.gets.split(" ")
m = Integer(in_m)
n = Integer(in_n)
volume = m*n
p volume/2

m,n = gets.split.map &:to_i
if m.even? || n.even?
  puts m*n/2
else
  puts (m*n - 1)/2
end

gets.split.map(&:to_i).tap {|a| c = a[0] * a[1]; c-=1 unless (c % 2).zero?; print c/2}

#!/usr/bin/ruby
input = gets.chomp
arr =input.split(' ')
n = arr[0]
m = arr[1]
out = (n.to_i * m.to_i)/2
puts "#{out}"

class Solver1
  def self.solve(n, m)
    if n.even? && m.even?
      return self.even_pair(n, m)
    else
      n1, n2 = 0
      n1 = n.even? ? n : n - 1
      n2 = m.even? ? m : m - 1
      even_area = n1 * n2
      even_solved = even_pair(n1, n2)
      total_area = n * m
      return even_solved + ((total_area - even_area) / 2).floor
    end
  end

  def self.even_pair(n, m)
    (n * m) / 2
  end
end
n, m = STDIN.gets.split(" ")
puts Solver1.solve(n.to_i, m.to_i)

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

puts m*n/2

n, m = gets.split.map &:to_i; puts n * m / 2

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

### 1
sum_a = m / 2 * n
if m % 2 != 0
	sum_a = sum_a + (n / 2)
end

### 2
sum_b = n / 2 * m
if n % 2 != 0
	sum_b = sum_b + (m / 2)
end

if sum_a > sum_b
	puts "#{sum_a}"
else
	puts "#{sum_b}"
end

a,b=gets.chomp.split(' ')
a=a.to_i
b=b.to_i
puts a*b/2

aa =  STDIN.getc.to_i
bb =  STDIN.getc.to_i
puts aa * bb / 2

aa =  STDIN.getc.to_i
bb =  STDIN.getc.to_i
cc =  STDIN.getc.to_i
puts aa * cc / 2

ARGV
puts "#{ARGV[0].to_i * ARGV[1].to_i / 2}"

a = gets.to_i
b = gets.to_i
puts a * b / 2

    input = gets.split.map(&:to_i)
    input.sort!
    input[1]-=1 if input[1] % 2 != 0
    print input[0]*input[1]/2

gets.split.map(&:to_i).tap {|a| c = a[0] * a[1]; c-=1 unless (c % 2).zero?; print c}

m = gets
n = gets
out = (n.to_i * m.to_i)/2
puts "#{out}"

m, n = gets.strip.split(" ").map(&:to_i)
if m == 1 && n == 1 then
  puts 0
else
  count = 0
  i = 0
  while (i < n) do
    if n - i - 1 >= 2 then
      m.times {count += 1}
      i += 2
    else
      (m / 2).times {count += 1}
      i += 1
    end
  end
end
puts count

#         ... LETS HACK THE WORLD ...
#... KEEP CALM AND SAY LE ROI EST MORT IS HERE ...
#       ... EL-BADRY BECOME A LEGEND ...

x = gets.to_i
z = gets.to_i
a = x * z / 2
puts a

#         ... LETS HACK THE WORLD ...
#... KEEP CALM AND SAY LE ROI EST MORT IS HERE ...
#       ... EL-BADRY BECOME A LEGEND ...
x = gets.to_i
z = gets.to_i
puts((x*z)/2)

def solve a,b
	if a==1
		b/2
	elsif a==2
		b
	else
		if a%2==0
			2*solve(a/2, b)
		else
			solve(a-1, b) + solve(1, b)
		end
	end
end

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

input = gets.chomp.split(" ").map { |x| x.to_i}
M = input[0]
N = input[1]

places = (0..M*N-1).to_a
edges = {}
tiles = 0
for i in places
  temp = []
  if i-1>=0
    temp.push i-1
  end
  if i+1<M*N
    temp.push i+1
  end
  if i-N>=0
    temp.push i-N
  end
  if i+N<M*N
    temp.push i+N
  end

  edges[i] = temp
end

if M.even?
  puts (M/2)*N
  exit
end
if N.even?
  puts (N/2)*M
  exit
end

while places.count > 0
  place = places.pop
  options = edges[place]
  good = false
  for option in options
    if places.include?(option)
      places.delete option
      good = true
      break
    end
  end
  if good
    tiles += 1
  else
    break
  end
end
puts edges
puts places
puts tiles

#puts "Enter the dimensions of rectangle\n"
m,n = gets.split.map(&:to_i)
if m == n
    a = (m*n)/2
    puts a
else
    r = n/2;
    s = r*m;
    puts s
end

#puts "Enter the dimensions of rectangle\n"
m,n = gets.split.map(&:to_i)
if m == n
    a = (m*n)/2
    puts a
else
    r = n/2
    s = r*m
    d = m/2
    v = d*n
    if s>=v
        puts s
    else
        puts v
    end
end

puts "Enter the dimensions of rectangle\n"
m,n = gets.split.map(&:to_i)
if m = n
    a = (m*n)/2
    puts a
else
    r = n/2;
    s = r*m;
    puts s
end

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

puts ((n * m) / 2) * 2

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

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

print c

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

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

print c

arr = gets.split(" ")
m = arr[0].to_i
n = arr[1].to_i

result = m * (n / 2)
if m > 2 and m % 2 == 1
    result = result + (n / 2)
end

print result

arr = gets.split(" ")
m = arr[0].to_i
n = arr[1].to_i

result = m * (n / 2)
if m % 2 == 1
    result = result + (n / 2)
end

print result


def solve(idx, b)
    a = Array.new(b)
    if a[idx] == 0
        return -1
    end
    num = a[idx] / 14
    (a[idx] % 14).times do |i|
        a[(idx + i + 1) % 14] += 1
    end
    a[idx] = 0
    res = 0
    14.times do |i|
        a[i] += num
        if a[i] % 2 == 0
            res += a[i]
        end
    end
    return res
end

a = gets.split.map(&:to_i)
ans = 0
14.times do |i|
    ans = [ans, solve(i, a)].max
end
puts ans

a=gets.split.collect{|s|s.to_i}
  m=0
for i in 0..13
  b=a.collect{|s|s}
  k=b[i]
  b[i]=0
  kd=k/14
  km=k%14
  res=0
  for j in 1..14
    b[(i+j)%14]+=((j<=km) ? kd+1:kd)
  end
  for j in 0..13
    if(b[j]%2==0)
      res+=b[j]
  end
  end
  if res>m
    m=res
  end
end
puts m


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

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

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

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

if n == m
  puts "0"
  exit
end

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

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

#! usr/bin/env ruby

str1 = gets
str2 = gets
puts str1.casecmp str2

#! usr/bin/env ruby

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

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

str1 = gets.chomp.downcase

str2 = gets.chomp.downcase

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

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

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

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

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

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

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

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

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

call

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

a = gets.chomp
b = gets.chomp

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

string1 = gets
string2 = gets

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

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

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

puts counter

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

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

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

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

puts s1 <=> s2

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

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

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

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

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

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

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

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

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

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

s.downcase!
t.downcase!

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

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

puts a <=> b

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

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

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

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

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

str1 = gets.chomp
str2 = gets.chomp

puts str1.downcase  <=> str2.downcase

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

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

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

s1 = gets
s2 = gets

s1 = s1.downcase
s2 = s2.downcase

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

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

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

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

s1 = gets.chomp
s2 = gets.chomp

puts s1.casecmp s2

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

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

puts l1 <=> l2

first = gets.chomp
second = gets.chomp

puts first.downcase <=> second.downcase

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

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

order = 0

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

puts order

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

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

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

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

puts gets.capitalize <=> gets.capitalize

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

s1 = gets.chomp
s2 = gets.chomp

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

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

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

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

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

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

puts s1 <=> s2

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

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

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

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

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

puts firstSen <=> secondSen

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

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

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

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

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

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

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

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

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

str1 = gets.chomp.downcase

str2 = gets.chomp.downcase

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

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

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

call

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

run

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

run

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

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

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

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

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

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

ans=0

a=gets.downcase.sum

b=gets.downcase.sum

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

p ans

la,lb,ans=0,0,0

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

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

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

p ans

la,lb,ans=0,0,0

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

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

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

p ans

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

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

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

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

puts '0'

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

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

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

puts str1 <=> str2

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

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

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

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

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

first_line = gets.chomp
second_line = gets.chomp

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

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

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

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

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

compare_strings(first_string, second_string)

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

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

puts compare_strings(first_string, second_string)

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

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

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

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

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


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

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

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

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

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

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

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

puts a.max - a.min

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

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

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

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

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

puts x3-x1

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

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

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

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

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

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

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

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

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

print res
fin.close

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

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

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

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

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

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

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

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

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

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

puts min_d

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

puts xs.max - xs.min

d = gets.chomp
distances = d.split

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

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

print distance

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

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

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

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

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

puts ans

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

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

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

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

input = gets.split(" ")

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

middle_pt = middle_pt / input.size

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

puts total_dist

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

total_dist = 0

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

puts total_dist


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

puts res

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

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

# kkk  +1

# kkv skip
# kvk skip
# vkk skip

# vvk skip
# vkv skip
# kvv

# vvv +1

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

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

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

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

puts res

# kkk  +1

# kkv skip
# kvk skip
# vkk skip

# vvk skip
# vkv skip
# kvv

# vvv +1

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

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

# kkk  +1

# kkv skip
# kvk skip
# vkk skip

# vvk skip
# vkv skip
# kvv

# vvv +1

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

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

# kkk  +1

# kkv skip
# kvk skip
# vkk skip

# vvk skip
# vkv skip
# kvv

# vvv +1

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


#!/usr/bin/env ruby

n = gets.to_i

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

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


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

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

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


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

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

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


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

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


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

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

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

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


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

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

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

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

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

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

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

def read_line
  STDIN.gets.chomp
end

s1 = read_line
s2 = read_line
s3 = read_line

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

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

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

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

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

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

a = gets.chomp
b = gets.chomp

$x = []

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

addToList a
addToList b

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

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

#!/usr/bin/env ruby

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

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

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

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

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

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

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

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

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

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

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

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

puts check_pile(string_a, string_b, letters_found)

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

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

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

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

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

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

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

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

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

puts ans ? "YES" : "NO"

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

t = a+b

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

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

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

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

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

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

  rest.delete_at(index)
end

puts "YES"

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

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

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

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

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

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

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

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

  hash_x = {}
  hash_z = {}

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

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

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

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

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

h = Hash.new(0)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

guest = gets.chomp
residence = gets.chomp

found = gets.chomp

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

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

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

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

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

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

amusing_joke

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

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

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

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

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

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

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

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

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

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

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

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

answer = gets.chomp.split ""

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

a = true

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

  break unless a
end

puts a ? "YES" : "NO"

#!/usr/bin/env ruby

$ma = {}
$ma.default = 0

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

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

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

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

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

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

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

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

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

a = 'A'.ord

arr = Array.new(26,0)

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

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

	arr[i.ord - a ] -= 1

end

ans = arr.minmax

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

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

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

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

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

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

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

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

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

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

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

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

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

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

def read_line
  STDIN.gets.chomp
end

s1 = read_line
s2 = read_line
s3 = read_line

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

puts ans

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

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

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

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

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

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

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

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

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

  hash_x = {}
  hash_z = {}

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

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

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

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

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

  hash_x = {}
  hash_z = {}

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

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

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

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

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

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

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

answer = gets.chomp.split ""

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

  a = false if result[i] < 0
end

puts a ? "YES" : "NO"