n=gets.chomp.to_i
a=Array.new(6,0)
b=Array.new(6,0)
integer=gets.chomp.split(" ")
integer.each do |integer|
    #puts "a=#{integer}"
    a[integer.to_i]+=1;
end
integer=gets.chomp.split(" ")
integer.each do |integer|
    #puts "b=#{integer}"
    b[integer.to_i]+=1;
end
atob=0
can=1
#for i in 1..5
#    puts "#{i} #{a[i]} #{b[i]}"
#end

for i in 1..5
    if a[i] > b[i]
        if (a[i]-b[i])%2!=0
            can=0
            break
        end
        atob+=(a[i]-b[i])/2;
    end
    #感觉只要处理一种情况就可以！
end
if can==1
    puts atob
else
    puts -1
end


POSSIBLES = [
  [[1, 2], [18, 20], [11, 12], [13, 15]],
  [[3, 4], [17, 19], [9, 10], [14, 16]],
  [[2, 4], [6, 8], [10, 12], [21, 23]],
  [[1, 3], [5, 7], [9, 11], [22, 24]],
]

FACES = [
  (1..4).to_a,
  (5..8).to_a,
  (9..12).to_a,
  (13..16).to_a,
  (17..20).to_a,
  (21..24).to_a,
]

def check_solved(c)
  FACES.each do |face|
    return false unless face.map { |f| c[f] }.uniq.size == 1
  end
  true
end

def solve(cube)
  # [[[2, 4], [6, 8], [10, 12], [21, 23]]].each_with_index do |possib|
  POSSIBLES.each_with_index do |possib|
    face_colors = possib.map { |p| cube[p.first] == cube[p.last] }
    next if face_colors.include?(false)
    colors = possib.map { |p| cube[p.first] }
    [possib.rotate(1), possib.rotate(-1)].each do |rot|
      c = cube.dup
      rot.each_with_index do |curr, i|
        c[curr.first] = colors[i]
        c[curr.last] = colors[i]
      end
      if check_solved(c)
        return "YES"
      end
    end
  end
  return "NO"
end

cube = {}
vals = gets.strip.split.map(&:to_i)

vals.each_with_index do |v, i|
  cube[i + 1] = v
end

puts solve(cube)


def judge(cube)
    6.times do |i|
        if !(cube[4 * i] == cube[4 * i + 1] && cube[4 * i + 1] == cube[4 * i + 2] && cube[4 * i + 2] == cube[4 * i + 3])
            return false
        end
    end
    return true
end

a1 = [0,2,4,6,8,10,23,21]
b1 = [1,3,5,7,9,11,22,20]
a2 = [12,13,4,5,16,17,20,21]
b2 = [14,15,6,7,18,19,22,23]
a3 = [2,3,16,18,9,8,15,13]
b3 = [0,1,17,19,11,10,14,12]

cube = gets.split.map(&:to_i)
ans = judge(cube)

tmp = Array.new(a1)
tmp.rotate!(2)
cube2 = Array.new(cube)
8.times do |i|
    cube2[a1[i]] = cube[tmp[i]]
end
ans |= judge(cube2)

tmp = Array.new(b1)
tmp.rotate!(2)
cube2 = Array.new(cube)
8.times do |i|
    cube2[b1[i]] = cube[tmp[i]]
end
ans |= judge(cube2)

tmp = Array.new(a2)
tmp.rotate!(2)
cube2 = Array.new(cube)
8.times do |i|
    cube2[a2[i]] = cube[tmp[i]]
end
ans |= judge(cube2)

tmp = Array.new(b2)
tmp.rotate!(2)
cube2 = Array.new(cube)
8.times do |i|
    cube2[b2[i]] = cube[tmp[i]]
end
ans |= judge(cube2)

tmp = Array.new(a3)
tmp.rotate!(2)
cube2 = Array.new(cube)
8.times do |i|
    cube2[a3[i]] = cube[tmp[i]]
end
ans |= judge(cube2)

tmp = Array.new(b3)
tmp.rotate!(2)
cube2 = Array.new(cube)
8.times do |i|
    cube2[b3[i]] = cube[tmp[i]]
end
ans |= judge(cube2)

tmp = Array.new(a1)
tmp.rotate!(-2)
cube2 = Array.new(cube)
8.times do |i|
    cube2[a1[i]] = cube[tmp[i]]
end
ans |= judge(cube2)

tmp = Array.new(b1)
tmp.rotate!(-2)
cube2 = Array.new(cube)
8.times do |i|
    cube2[b1[i]] = cube[tmp[i]]
end
ans |= judge(cube2)

tmp = Array.new(a2)
tmp.rotate!(-2)
cube2 = Array.new(cube)
8.times do |i|
    cube2[a2[i]] = cube[tmp[i]]
end
ans |= judge(cube2)

tmp = Array.new(b2)
tmp.rotate!(-2)
cube2 = Array.new(cube)
8.times do |i|
    cube2[b2[i]] = cube[tmp[i]]
end
ans |= judge(cube2)

tmp = Array.new(a3)
tmp.rotate!(-2)
cube2 = Array.new(cube)
8.times do |i|
    cube2[a3[i]] = cube[tmp[i]]
end
ans |= judge(cube2)

tmp = Array.new(b3)
tmp.rotate!(-2)
cube2 = Array.new(cube)
8.times do |i|
    cube2[b3[i]] = cube[tmp[i]]
end
ans |= judge(cube2)

puts ans ? "YES" : "NO"


a=gets.split.map &:to_i
s=a.inject :+
puts ((1..5).any?{|i| a.combination(i).any?{|j| j.inject(:+)*2==s}} ? "YES" : "NO")


n = gets.chomp.downcase
m = gets.chomp.downcase
a = 0
while n[a] == m[a]
  a += 1
end

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


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

if n == m
  abort "0"
end

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

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


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


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


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
end
puts 0 if f==1


def equality(n)
	l = 0
	essai = 0
	nombre = 2
	while n > essai
		divi = n.to_f / nombre
		l = l + 1 if divi.to_s[divi.to_s.index(".") + 1] == "0"
		nombre = nombre + 1
		essai = essai + 1
	end
	return l
end

n = gets.chomp.to_i
puts(equality(n))


n,m,*a=$<.read.split.map &:to_i
p m/a.select{|e|m%e}.max


n,k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
a.sort!
ans = 0
while (t = a.pop) && ans == 0
    ans = t if k % t == 0
end
puts ans


strs = []
k = false
8.times do |i|
    strs[i] = gets.chomp
    st = strs[i].gsub("BB", "*").gsub("WW", "*")
    if st.index("*") then k = true
    end
end

if k then
    puts "YES"
else
    puts "NO"
end


first = gets
index = -1
if first.include?("WWW") or first.include?("BBB")
	puts "NO"
	exit
end
if first[0] == "W"
	successful = true
	needed = 0
else
	successful = false
	needed = temp.rfind("W")
	after_needed = needed+1
	if after_needed == 8
		after_needed = 0
	end
end
if first.include?("WW")
		if first.count("WW") > 1
			puts "NO"
			exit
		end
		if index == -1
			index = first.index("WW")
		else
			unless index == first.index("WW")
				puts "NO"
				exit
			end
			unless first[index+1] == "W"
				puts "NO"
				exit
			end
		end
	end
	if first.include?("BB")
		successful = false
		if first.count("BB") > 1
			puts "NO"
			exit
		end
		if index == -1
			index = first.index("BB")
		else
			unless index == first.index("BB")
				puts "NO"
				exit
			end
			unless first[index+1] == "W"
				puts "NO"
				exit
			end
		end
	end
for i in 1...8
	temp = gets
	unless successful
		if temp[needed] == temp[after_needed]
			puts "NO"
			exit
		end
	end
	if temp.include?("WWW") or temp.include?("BBB")
		puts "NO"
		exit
	end
	if temp.include?("WW")
		if temp.count("WW") > 1
			puts "NO"
			exit
		end
		if index == -1
			index = temp.index("WW")
		else
			unless index == temp.index("WW")
				puts "NO"
				exit
			end
			unless first[index+1] == "W"
				puts "NO"
				exit
			end
		end
	end
	if temp.include?("BB")
		successful = false
		if temp.count("BB") > 1
			puts "NO"
			exit
		end
		if index == -1
			index = temp.index("BB")
		else
			unless index == temp.index("BB")
				puts "NO"
				exit
			end
			unless first[index+1] == "W"
				puts "NO"
				exit
			end
		end
	end
end
puts "YES"


 infile = STDIN
8.times do
  s = input.readline
  7.times do |i|
    if s[i] == s[i+1]
      puts "NO"
      exit
    end
  end
end
puts "YES"


sq = Array.new(3)
for i in 0..2
  sq[i] = gets.split.map(&:to_i)
end
sq[0][0] = sq[0][2]
sq[2][2] = sq[2][0]
sq[1][1] = sq[0][0] + sq[2][0] - sq[1][2]
for i in sq
  for j in i
    print j, " "
  end
  puts ""
end


lines = ARGF.readlines

ary = []
lines.each do | line |
  ary << line.chomp.split(" ").map { |x| x.to_i }
end

for i in 1..(10**5) do
  t = ary[0][1] + ary[0][2] + i

  j = t - (ary[1][0] + ary[1][2])
  k = t - (ary[2][0] + ary[2][1])

  next if j <= 0 or k <= 0

  y1 = ary[1][0] + ary[2][0] + i
  y2 = ary[0][1] + ary[2][1] + j
  y3 = ary[0][2] + ary[1][2] + k

  if (y1 == y2) and (y2 == y3)
    ary[0][0] = i
    ary[1][1] = j
    ary[2][2] = k

    ary.each do | x |
      puts x.join(" ")
    end

    break
  end
end


word = gets.chomp().downcase!.delete("aeiouy")
tword = word;
word.each_char {|c| print '.', c }.delete!(tword)

puts word


input = gets.chomp

input = input.downcase
input = input.gsub!(/[aoyeui]/, "")

input = input.each_char.map { |c| ".#{c}" }.join

puts input


#! ruby -Ku
# -*- coding: UTF-8 -*-
inputs = open("input.txt")
# inputs = STDIN
word = inputs.gets.gsub(/[AOYEUIaoyeui]/, '').downcase
ret_word = String::new
word.split(//).each do |ch|
  ret_word += "." + ch
end
puts ret_word


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

def solution(n, k)
  s = ""
  j = 0
  n.times do |i|
    s += ((i % k) + 97).chr
  end
  return s
end

q = gets.chomp.to_i
q.times do
  n, k = gets.chomp.split(" ").map(&:to_i)
  puts solution(n, k)
end


x, y = gets.strip.split.map &:to_i
n = gets.to_i

fn = [x, y]

(2 ... n + 1).each do |i|
  fn[i] = fn[i - 1] - fn[i - 2]
end

puts (fn[-2] % 1000000007)


x, y = gets.strip.split.map &:to_i
n = gets.to_i

f = [x, y]

def sequence f, n
  if f[n]
    return f[n]
  else
    f[n] = sequence(f, n - 1) - sequence(f, n - 2)
    return f[n]
  end
end

sequence f, n
puts f[-2] % 1000000007


x,y = gets.split(" ").map(&:to_i)
n = gets.to_i
ans = nil
ans = x if n == 1
ans = y if n == 2
unless ans
	(n-2).times do
		ans = y - x
		x = y
		y = ans
	end
end
puts ans % ((10**9) + 7)


no_op = gets.chomp.to_i
ops = gets.chomp.split("")
count_add = ops.count("+")
count_rem = ops.count("-")

if count_rem > count_add
    puts 0
elsif ops[0] == "-"
    puts count_add - count_rem + 1
else
    puts count_add - count_rem
end


x, y = gets.split.map(&:to_i)
if (y == 1 && x == 0) || ((x-y+1).even? && (x-y+1) > 0)
  puts "YES"
else
  puts "NO"
end


def judge(a, b)
  return false if b == 0
  return false if b == 1 && a != 0
  return false if (a - b + 1) % 2 == 1
  return true
end

a, b = gets.split.map(&:to_i)
if judge(a, b)
  puts "Yes"
else
  puts "No"
end


n,m=gets.split.map &:to_i
p n<64 ? m%2**n : m


x = gets.chomp.to_i
y = gets.chomp.to_i
c = y % (power(2,x))
puts "#{c}"


n,k=gets.split.map &:to_i;r=1;(r+=1;k/=2)while k%2>0;p r


length, index = gets.split

seq = '1'
length = length.to_i
index = index.to_i

2.upto(length) do |i|
  seq = "#{seq}#{i}#{seq}"
end
puts seq[index - 1]


length, index = gets.split
seq = [1]
length = length.to_i
index = index.to_i

2.upto(length) do |i|
  seq = seq + [i] + seq
end
puts seq[index - 1]


n, k = gets.chomp.split(" ").map(&:to_i)
a = Array.new
a.insert(a.length, 1)
if n>1
  for i in 2..n
    a = a.insert(a.length, *a).insert((a.length+1)/2, i)
  end
  puts a[k-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"


m, n = gets.chomp.split(' ')
puts m.downcase >= n.downcase ? m.downcase == n.downcase ? 0 : 1 : -1


def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end

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

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

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

def kaizyo(n)(n < 2)? 1 : (2..n).inject(:*) end

def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end

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

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

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

def bit(n) n.to_s(2).split("").map(&:to_i) end

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

def k2(k,n,m)
  return 1 if k == 0
  return n if(k == 1)
  ans = 1
  if((k%2) == 0)
    ans *= k2(k/2,n,m)**2
  else
    ans *= k2(k-1,n,m)
    ans *= n
  end
  return ans % m
end

a,b = inp
mod = 10**9+7
ans = k2(b,k2(a,2,mod),mod)
non = a*k2(b,k2((a-1),2,mod),mod)

p ans - non + (a-1)


#!/usr/bin/ruby
require 'rational'
a,b=gets.split.map(&:to_i)
r=0
while a>0
	g=a.gcd(b)
	a/=g;b/=g
	r+=a/b
	a,b=b,a-a/b*b
end
p r


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

n, a, b, c, d = input[0], input[1], input[2], input[3], input[4]

ans = 0
firstPart = a + b
secondPart = b + d
thirdPart = c + d
fourthPart = a + c

guessNum = 1

until guessNum > n
	# Left to right
	balanceFactor = b - c + guessNum

	if balanceFactor <= 0
		guessNum += 1
		next
	end

	balanceFactor_2 = a - d + balanceFactor

	if balanceFactor_2 <= 0
		guessNum += 1
		next
	end

	balanceFactor_3 = c - b + balanceFactor_2

	if balanceFactor_3 <= 0
		guessNum += 1
		next
	end

	#puts "#{guessNum} #{balanceFactor} #{balanceFactor_2} #{balanceFactor_3}"
	ans += 1
	guessNum += 1
end

puts ans * n


# coding: utf-8

# if __FILE__ == $0
# end

# n - 방문한 버텍스까지의 웨이트 총합
# k - 트리의 유형(the number of children)
# d - 웨이트가 d인 에지로, 반드시 포함되어야함
# 1<=d<=k 이므로 d가 k보다 커질 일은 없음
# 1<=n,k<=100
$n, $k, $d = gets.split.map(&:to_i)
MODULO_BASE = 10**9 + 7

ways = 0
def recur_tree(visited, acc, depth)
    #puts "#{'>' * (depth+1)} #{visited} #{acc}"
    if acc >= $n
        if acc == $n
            if !visited
                return 0
            else
                return 1
            end
        else
            return 0 # exceeded
        end
    end

    sub_ways = 0

    for i in 1..$k
        sub_ways += recur_tree(visited || (i >= $d), acc + i, depth + 1)
    end

    return sub_ways
end

ways = recur_tree(false, 0, 0)
puts ways%MODULO_BASE


def count(sum,k,d,i,arr)
	if sum < 0
		return
	end

	if sum == 0 && arr.any? { |e| e >= d  }
		@c += 1
		return
	end

	(1..k).each do |v|
		arr[i] = v
		count(sum-v,k,d,i+1,arr.dup)
	end
end

n,k,d = gets.split(" ").map(&:to_i)
@c = 0
count(n,k,d,0,[])
puts @c


def solution(n, k, d)
  @memo = Array.new(2) { Array.new(n+1, false) }
  def solve(n, k, d, flag)
    return @memo[(flag ? 1 : 0)][n] if @memo[(flag ? 1 : 0)][n]
    return 1 if n == 0 && flag
    return 0 if n == 0 && !flag
    cnt = 0
    for i in 1..k do
      cnt += solve(n-i, k, d, flag || (i >= d)) if n-i >= 0
    end
    @memo[(flag ? 1 : 0)][n] = cnt
  end
  solve(n, k, d, false)
  @memo[0][n] % 1000000007
end

solution(*gets.split.map(&:to_i))


def ascan; gets.split.map(&:to_i);end

ans = []

n = gets.to_i

(0..9).to_a.repeated_combination(9) do |a|
    t = a.reduce(n){|s,e| s-=e}
    next if t < 0
    h = [0]*10
    a.each{|e| h[e]+=1}
    t.to_s.chars.each{|c| h[c.to_i]-=1}
    b = true
    (1..9).each{|e| b &= h[e] == 0}
    ans << t if b
end

p ans.size
puts ans


a,b,c,d=gets.split.map(&:to_i)
p=a*d
q=b*c
puts[Rational(p-q,p),Rational(q-p,q)].max


def gcd(a,b)
if b == 0
  return a;
else
  return gcd(b, a % b);
end
end

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

l,m = (a/b.to_f),(c/d.to_f)

num = den = 0

if l < m
	num = (b * c) - (a * d)
	den =  b * c
elsif l > m
	num = (a * d) - (b * c)
	den = a * d
end

if num == 0
	puts 0
else
	g = gcd(num,den)
	puts "#{num/g}/#{den/g}"
end


# f = File.new('test.txt', 'r')
a, b, c, d = f.gets.split.map(&:to_i)
# f.close

def gcd(a, b)
  if b == 0
    a
  else
    gcd(b, a % b)
  end
end

if a * d < b * c
  numerator = (b * c - a * d)
  denomerator = (b * c)
elsif a * d > b * c
  numerator = a * d - b * c
  denomerator = a * d
else
  numerator, denomerator = [0, 1]
end

uc = gcd(numerator, denomerator)
numerator /= uc
denomerator /= uc
puts "#{numerator} / #{denomerator}"


def Sum(ar)
  ar.reduce(:+) || 0
end

n = gets.to_i
ar = gets.split.map(&:to_i).sort
if n == 1
  puts ar
  exit 0
end
if ar[-1] < 0
  puts Sum(ar).abs
elsif ar[-1] > 0 and ar[0] < 0
  pos = ar.select{|i| i >= 0}
  neg = ar.select{|i| i < 0}
  puts Sum(pos)-Sum(neg)
else
  puts Sum(ar)
end


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

b = 0
c = as.inject(:+)
ans = b - c

(0..n-1).each do |i|
  a = as[i]
  b += a
  c -= a
  ans = [ans, b-c].max
end
puts ans


#!/usr/bin/ruby

i = gets
x = i.split(" ")[0]
y = i.split(" ")[1]
z = i.split(" ")[2]

total = 0
totrows = (x/z) + (x%z == 0 ? 0 : 1)
totcols = (y/z) + (y%z == 0 ? 0 : 1)

total = totrows * totcols

puts total


def theatre(n, m, a)
  n_m = n * m
  a_a = a * a
  sum = 0
  cnt = 0
  loop do
    if n_m - sum <= 0
      break
    else
      sum += a_a
      cnt += 1
    end
  end
  cnt
end

input = gets.chomp
theatre input[0].to_i input[1].to_i input[2].to_i


if a%n == 0
   if b%n == 0
      a/n * b/n
   else
      a/n * (b/n + 1)
    end
else
  if b%n == 0 then
    (a/n + 1 ) * (b/n)
  else
    (((a/n) +1) * ((b/n) +1))
  end
end


def splitspaceint(s)
	aaa = s.split(/ /)
	bbb = []
	for i in 0..aaa.length-1
		bbb.push(aaa[i].to_i)
	end
	return bbb
end

n,m,a = splitspaceint(gets)
puts (n.prec_f/a).ceil * (m.prec_f/a).ceil


n, m, a = gets.split.map &:to_i
while n%a!=0
  n+=1
end
while m%a!=0
  m+=1
end
p n*m/(a*a)


input = gets.split.map(&:to_i)
n = input[0]
m = input[1]
a = input[2]

b = input[2]
c = input[2]

if n == m && a == 1
  puts n*n
else
  temp1 = 1
  temp2 = 1
  while n > b do
    temp1 += 1
    b += a
  end

  while m > c do
    temp2 += 1
    c += a
  end

  puts temp1 * temp2
end


data = gets.chomp.split(" ")
len = data[0].to_i
wid = data[1].to_i
size = data[2].to_i

num_len = 0
num_wid = 0
size_len = 0
size_wid = 0

loop do
  if size_len < len
    num_len += 1
    size_len += size
  else
    break
  end
end

loop do
  if size_wid < wid
    num_wid +=1
    size_wid += size
  else
    break
  end
end

puts(num_wid*num_len)


n = gets.chomp

digit_count = n.length
n = n.to_i

result = (n - (10 ** (digit_count - 1) - 1)) * digit_count

result += (1..(digit_count - 1)).inject(0) do |sum, count|
	sum + ('9' * count).to_i * count
end

puts result


# http://codeforces.com/contest/552/problem/B
n = gets.chomp.to_i
puts (1..n).to_a.map(&:to_s).inject(0) { |a, e| a + e.length }


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

if m > n
  puts -1
else
  cand = n / m
  while cand % m != 0 do
    cand += 1
  end
  puts cand
end


def run
  x, y = gets.chomp.split(" ").map(&:to_i)
  a, b = gets.chomp.split(" ").map(&:to_i)

  r = if a * 2 < b || x == 0 ||  y == 0
    (x + y) * a
  else
    (x - y).abs * a + [x, y].min * b
  end
  puts r
end

def main
  t = gets.chomp.to_i

  t.times do
    run
  end
end

main


# coding: utf-8

# if __FILE__ == $0
# end

n_stairs, moves_multiple = gets.split.map { |i| i.to_i }
# use 2 or 1 step only. 2 step -> 1 move, 1 step -> 1 move.
twosteps = n_stairs/2 # moves
onestep = n_stairs%2 # moves
met_condition = false
while twosteps > 0
    if (twosteps + onestep) % moves_multiple == 0
        met_condition = true
        break
    else
        twosteps -= 1
        onestep += 2
    end
end

if met_condition
    puts twosteps + onestep
else
    puts -1
end


n, m = gets.chomp.split.map(&:to_i)
ans = -1
if n % 2 == 0
  steps = n / 2
else
  steps = n / 2 + 1
end
(n / 2).times do
  if steps % m == 0
    ans = steps
    break
  else
    steps += 1
  end
end
puts ans


nmz = gets.chomp.split
n = nmz[0].to_i
m = nmz[1].to_i
z = nmz[2].to_i

if n == m
	print z
else
	i = 0
	call = []
	art = []
	np = n
	mp = m
	while np <= z
		np = n * (i+1)
		call << np
		i += 1
	end
	i = 0
	while mp <= z
		mp = m * (i+1)
		art << mp
		i += 1
	end

	count = 0
	for i in (0..call.size-1)
		for x in (0..art.size-1)
			if call[i] == art[x] && call[i] <= z && art[x] <= z
				count += 1
			end
		end
	end
	print count
end


nmz = gets.chomp.split
n = nmz[0].to_i
m = nmz[1].to_i
z = nmz[2].to_i

i = 0
call = []
art = []
np = n
mp = m
while np <= z
	np = n * (i+1)
	call << np
	i += 1
end
i = 0
while mp <= z
	mp = m * (i+1)
	art << mp
	i += 1
end

count = 0
for i in (0..call.size-1)
	for x in (0..art.size-1)
		if call[i] == art[x] && call[i] <= z && art[x] <= z
			count += 1
		end
	end
end
print count


sum = gets.chomp.to_i
sum<0 ?
    {sum = -sum
    a = sum/10
    b = (sum/100)*10 + sum%10
    acc = case
        when a<=b && a<sum then sum = -a
        when b<a && b<sum then sum = -b
    end}

puts sum


n = gets.to_i
if n>=0
    puts n
else
    dig1,dig2 = n%10, (n/10)%10
    n1,n2 = n/10,n1+dig1-dig2
    if n1>n2
        puts n1
    else
        puts n2
    end
end


s = gets()
s.chomp!
max = s.to_i
if s.size > 1 && s[0...s.size-1].to_i > max
  max = s[0...s.size-1].to_i
end
 if s.size > 2
  arr = s.split(//)
  arr.delete_at(-2)
  n = aarr.join.to_i
  if n > max
    max = n
  end
end
puts max


def not_vowel? jumping
  an = %w{A E I O U Y} #  a e i o u y
  an.each { |value| return false if value == jumping }
  return true
end

def ability jump_list1
  jump_list = jump_list1.split("")
  jump_list.delete_at(-1)
  jump_list.unshift('A')
  jump_list << 'A'
  # puts jump_list.length
  return 0 if jump_list.length == 0
  throw ArgumentException if jump_list.length > 100

  jump_ability = 0
  current_ability = 0 # at least jump 1
  jump_list.each do  |current|
    current_ability = current_ability + 1
    if not_vowel?(current)
      # puts "1"
    elsif current_ability > jump_ability
      # puts "2"
      jump_ability = current_ability
      current_ability = 0
    else
      # puts "3"
      current_ability = 0
    end
  end
    current_ability > jump_ability ? current_ability : jump_ability
end

jump_list = gets
puts ability(jump_list)


bottle = gets.to_i - 1
people = w%[Sheldon Leonard Penny Rajesh Howard]
p_num = people.length

until bottle <= p_num do
 bottle = (bottle - p_num)/2
end

puts people[n]


bottle = gets.to_i - 1
people = w%(Sheldon Leonard Penny Rajesh Howard)
p_num = people.length

until bottle <= p_num do
 bottle = (bottle - p_num)/2
end

puts people[n]


queue = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
n = gets.to_i

for i in 1...n
  queue << queue[0] << queue[0]
  queue.delete_at(0)
end

print queue[0]


n = $stdin.readline.split.first.to_i

l = [:Sheldon, :Leonard, :Penny, :Rajesh, :Howard]
s = l.count

while n>1
    s = l.shift
    l << s << s
    n-=1
end

puts l.first


a=["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
n=gets.chomp.to_i
n.times do
    x=a.shift
    a << x
    a << x
end
puts a.pop


n = gets.to_i

name = ["Sheldon", "Leonard", "Penny", "Rajesh", "Howard"]
tmp = ""
res = []
n.times do
  tmp = name.shift
  name.push tmp
  name.push tmp
  res.push tmp

end

print res[n - 1]


s=gets;puts %w(Danil Olya Slava Ann Nikita).one?{|e|s.scan(e).size==1}?:YES: :NO


s = gets
res = 0
for i in 0..s.length
    case
      when i + 4 < s.length && s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4] == "Danil" then res += 1
      when i + 3 < s.length && s[i] + s[i + 1] + s[i + 2] + s[i + 3] == "Olya" then res += 1
      when i + 2 < s.length && s[i] + s[i + 1] + s[i + 2] == "Ann" then res += 1
      when i + 5 < s.length && s[i] + s[i + 1] + s[i + 2] + s[i + 3] + s[i + 4] + s[i + 5] == "Nikita" then res += 1
    end
end
if res == 1
  puts "YES"
else
  puts "NO"
end


f=["Danil", "Olya", "Slava", "Ann", "Nikita"]
s=gets
puts (f.one?{|x| !!s[x]} ? "YES" : "NO")


names = %w(Danil Olya Slava Ann Nikita)
line = gets.chomp

puts names.select { |name| line.include?(name) }.count == 1 ? 'YES' : 'NO'


5.times do |i|
  j = gets.split.find_index(1)
  puts (i-2).abs + (j-2).abs
end


a  = []

for i in 0..4
  a[i] = []
  for j in 0..4
    a[i][j] = gets.to_i
    if a[i][j] == 1
        b = i
        c = j
    end
  end
end

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


1..5 { |i| gets.chomp.split.each_with_index do |x,j|
  if x == 1
    puts (i-3).abs + (j-2).abs
  end
}


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

p = q = 0
a.each_with_index do |v, i|
  dp = (v - (i*2+1)).abs
  dq = (v - (i*2+2)).abs
  p += dp
  q += dq

end

puts p < q ? p : q


start, finish = gets.chop.split
numberOfSpins = gets.chomp.to_i % 4
spinner = ['v', '<', '^', '>']
si = spinner.index start
a = spinner[si + numberOfSpins] == finish
b = spinner[si - numberOfSpins] == finish
if a and !b
  puts "cw"
elsif b and !a
  puts "ccw"
else
  puts "undefined"
end


rotations = %w{ ^ > v < ^ > v < }

start_pos, end_pos = gets.strip.split
n = gets.strip.to_i
n %= 4

start_pos_cw = rotations.index start_pos
start_pos_ccw = rotations.index start_pos

cw = rotations[start_pos_cw + (n - 4)] == end_pos
ccw = rotations[start_pos_ccw + (n - 4)] == end_pos
if cw && !ccw
    puts "cw"
elsif ccw && !cw
    puts "ccw"
else
    puts "undefined"
end