# Codeforces Beta Round #80
# Problem A -- Blackjack
cards = [0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 15, 4]
n = gets.to_i - 10
puts (0 <= n and n <= 11) ? cards[n] : 0

#!/usr/bin/env ruby

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

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

puts solve(STDIN.gets.to_i)

n = gets.chomp.to_i - 10
if n < 1 || n > 11
  puts 0
elsif n == 10
  puts 15
else
  puts 4
end

need = STDIN.readline.to_i - 10
if need == 10
  puts 15
elsif need >= 1 and need <= 11
  puts 4
else
  puts 0
end

n = gets.to_i
if n <= 10 or n >= 22
  puts 0
else
  if n== 20
    puts 15
  else
    puts 4
  end
end

#104A
n=gets.to_i
if n <= 10
    puts "0"
elsif n >= 11 and n <= 19
    puts "4"
elsif n == 20
    puts "15"
elsif n == 21
    puts"4"
else
    puts "0"
end

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

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

  goal = gets.to_i
  if goal-10 < 1
    puts 0
  else
    puts (c.has_key?(goal-10)) ? c[goal-10] : 0
  end
end

blackjack

case gets.chomp.to_i
  when 11..19, 21
    puts 4
  when 20
    puts 15
  else
    puts 0
end

s=gets.to_i
need=s-10

data=[10]*(3*4-1)+[1, 11]
for i in 2..10
	data+=[i]*4
end

puts data.count(need)

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

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

blackjack

#!/usr/bin/env ruby

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

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

puts solve(STDIN.gets.to_i)

#!/usr/bin/env ruby

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

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

puts solve(STDIN.gets.to_i)

#!/usr/bin/env ruby

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

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

puts solve(STDIN.gets.to_i)


# http://codeforces.com/contest/592/problem/A
# A. PawnChess

cols = [].tap do |arr|
  8.times { arr << gets.chomp.chars }
end
b_idx = []
w_idx = []
cols.transpose.each do |row|
  b = row.rindex('B')
  w = row.rindex('W')
  b_idx << 7 - b if b && (w.nil? || (b > w))

  b = row.index('B')
  w = row.index('W')
  w_idx << w if w && (b.nil? || (b > w))
end

if !b_idx.empty? && (w_idx.empty? || b_idx.min < w_idx.min)
  puts 'B'
else
  puts 'A'
end

Board = Array.new( 8 ) do | i |
	gets.chomp.split( "" )
end
.transpose.freeze;

a = 8; b = 8
Board.each do |row|
	8.times do | i |
		if row[i] != '.'
			if row[i] == 'W'
				a = [ a, i ].min
			end
			break
		end
	end
	7.downto( 0 ) do | i |
		if row[i] != '.'
			if row[i] == 'B'
				b = [ b, 7 - i ].min
			end
			break
		end
	end
end

puts ( a <= b ? "A" : "B" )

matr=[]
8.times{matr<<gets.split("")}
a,b=9,9

8.times do |j|
  tmp=0
  8.times do |i|
    if matr[i][j] == "W"
      tmp=i
      a=[tmp,a].min
      break
    elsif matr[i][j] == "B"
      break
    end
  end
end

8.times do |j|
  tmp=0
   (0..7).to_a.reverse.each do |i|
    if matr[i][j] == "B"
      tmp=7-i
    b=[tmp,b].min
      break
    elsif matr[i][j] == "W"
      break
    end
  end
end

puts a>b ? "B" : "A"

#! /usr/bin/env ruby

board = 8.times.collect { $stdin.gets.chomp }

w = 100
b = 100
for c in 0..7
  for r in 0..7
    board[r][c] == 'B' and break
    board[r][c] == 'W' and w = [w, r].min
  end
  for r in (0..7).reverse_each
    board[r][c] == 'W' and break
    board[r][c] == 'B' and b = [b, 7-r].min
  end
end

puts (w <= b ? 'A': 'B')

#!/usr/bin/env ruby

require 'matrix'

rows = 8.times.map do gets.chars.to_a end
MATRIX = Matrix.rows(rows)

def win_in_colA(col_no)
  (0..7).each do |row_no|
    if MATRIX[row_no, col_no] == 'W'
      return row_no
    elsif MATRIX[row_no, col_no] == 'B'
      return 9
    end
  end
  return 9
end

def win_in_colB(col_no)
  (0..7).to_a.reverse.each do |row_no|
    if MATRIX[row_no, col_no] == 'B'
      return 7-row_no
    elsif MATRIX[row_no, col_no] == 'W'
      return 9
    end
  end
  return 9
end

steps_for_A = (0..7).map do |col_n|
  win_in_colA(col_n)
end

steps_for_B = (0..7).map do |col_n|
  win_in_colB(col_n)
end

who_won = (steps_for_B.min < steps_for_A.min) ? 'B' : 'A'
puts who_won

field = []
while line = gets
  field << line.chomp.split("")
end
field = field.transpose
stepA = []
stepB = []
field.each do |r|
  a = r.rindex("W")
  b = r.rindex("B")
  unless b.nil? then
    if a.nil? or (a < b) then
      stepB << 7 - b
    end
  end
  a = r.index("W")
  b = r.index("B")
  unless a.nil? then
    if b.nil? or (a < b) then
      stepA << a
    end
  end
end
if stepB.empty? or (stepA.min <= stepB.min) then
  puts "A"
elsif stepA.empty? or (stepA.min > stepB.min) then
  puts "B"
end

a = Array.new(8)
c = [0] * 8
for x in 0..7
    a[x] = gets
end
flag = 0
for x in 0..7
    for y in 0..7
        if a[x][y] == "W" and c[y] == 0
            w = x;
            flag = 1;
            break;
        end
        if a[x][y] == "B"
            c[y] = 1;
        end
    end
    if flag == 1
        break
    end
end
c = [0] * 8
flag = 0
for x in 0..7
    for y in 0..7
        if a[7 - x][y] == 'B' and c[y] == 0
            b = x;
            flag = 1;
            break;
        end
        if a[7 - x][y] == 'W'
            c[y] = 1;
        end
    end
    if flag == 1
        break;
    end
end
if w > b
    print "B\n"
else
    print "A\n"
end

n, a1, a2, min, c = [], [], [], 99999, ''
(0..7).each do |_|
  n << gets.chomp.split('')
end
(0..7).each do |i|
  arr, a1, a2 = [], [], []
  (0..7).each do |j|
    arr << n[j][i]
  end
  x = Array.new arr
  y = Array.new arr
  x.uniq!.delete('.')
  y.reverse!.uniq!.delete('.')
  a1 = x
  a2 = y
  if a1.size == 0
  	next
  elsif a1.size == 1
  	d = a1.first == 'W' ? arr.index('W') : arr.reverse.index('B')
  	if (d < min) || (d == min && a1.first == 'W')
  		min = d
  		c = a1.first
  	end
  else
		if a1.first == 'W' && arr.index('W') <= min
			min = arr.index('W')
			c = 'W'
		end
		if a2.first == 'B' && arr.reverse.index('B') < min
			min = arr.reverse.index('B')
			c = 'B'
		end
  end
end
puts c == 'W' ? 'A' : 'B'

class Solver
	def main
		f = []
		8.times { f << gets }
		ans_w = 10
		ans_b = 10
		8.times do |i|
			8.times do |j|
				if f[i][j] == "W" then
					flag = true
					tmp = i - 1
					while tmp >= 0 do
						flag = false if f[tmp][j] != '.'
						tmp -= 1
					end
					ans_w = [ans_w, i].min if flag
				elsif f[i][j] == "B" then
					flag = true;
					tmp = i + 1
					while tmp < 8 do
						flag = false if f[tmp][j] != '.'
						tmp += 1
					end
					ans_b = [ans_b, 7 - i].min if flag
				end
			end
		end
		puts ans_w <= ans_b ? "A" : "B"
	end
end

Solver.new.main

# http://codeforces.com/contest/592/problem/A
# A. PawnChess

cols = [].tap do |arr|
  8.times { arr << gets.chomp.chars }
end
rows = cols.transpose.reject do |row|
  row.include?('B') && row.include?('W')
end

b_indexes = rows.map { |row| row.rindex('B') }.compact.map { |idx| 8 - idx }
w_indexes = rows.map { |row| row.index('W') }.compact

if b_indexes.min < w_indexes.min
  puts 'B'
else
  puts 'A'
end

# http://codeforces.com/contest/592/problem/A
# A. PawnChess

cols = [].tap do |arr|
  8.times { arr << gets.chomp.chars }
end
rows = cols.transpose.reject do |row|
  row.include?('B') && row.include?('W')
end

b_indexes = rows.map { |row| row.rindex('B') }.compact.map { |idx| 7 - idx }
w_indexes = rows.map { |row| row.index('W') }.compact

if w_indexes.empty? || b_indexes.min < w_indexes.min
  puts 'B'
else
  puts 'A'
end

# http://codeforces.com/contest/592/problem/A
# A. PawnChess

cols = [].tap do |arr|
  8.times { arr << gets.chomp.chars }
end
b_idx = []
w_idx = []
rows = cols.transpose.reject do |row|
  b = row.rindex('B')
  w = row.rindex('W')
  if b && (w.nil? || (b > w))
    b_idx << 7 - b
  end

  b = row.index('B')
  w = row.index('W')
  if w && (b.nil? || (w > b))
    w_idx << w
  end
end

if !b_idx.empty? && (w_idx.empty? || b_idx.min < w_idx.min)
  puts 'B'
else
  puts 'A'
end

#!/usr/bin/env ruby

require 'matrix'

rows = 8.times.map do gets.chars.to_a end
MATRIX = Matrix.rows(rows)

def win_in_colA(col_no)
  (0..7).each do |row_no|
    if MATRIX[row_no, col_no] == 'W'
      return row_no
    elsif MATRIX[row_no, col_no] == 'B'
      return 9
    end
  end
  return 9
end

def win_in_colB(col_no)
  (0..7).to_a.reverse.each do |row_no|
    if MATRIX[row_no, col_no] == 'B'
      return 7-row_no
    elsif MATRIX[row_no, col_no] == 'W'
      return 9
    end
  end
  return 9
end

steps_for_A = (0..7).map do |col_n|
  win_in_colA(col_n)
end
print steps_for_A
puts

steps_for_B = (0..7).map do |col_n|
  win_in_colB(col_n)
end
print steps_for_B

who_won = (steps_for_B.min < steps_for_A.min) ? 'B' : 'A'
puts who_won

#!/usr/bin/env ruby

require 'matrix'

rows = 8.times.map do gets.chars.to_a end
MATRIX = Matrix.rows(rows)

def win_in_colB(col_no)
  (0..7).each do |row_no|
    if MATRIX[row_no, col_no] == 'B'
      return row_no+1
    elsif MATRIX[row_no, col_no] == 'W'
      return 9
    end
  end
  return 9
end

def win_in_colA(col_no)
  (0..7).to_a.reverse.each do |row_no|
    if MATRIX[row_no, col_no] == 'W'
      return 8-row_no
    elsif MATRIX[row_no, col_no] == 'B'
      return 9
    end
  end
  return 9
end

steps_for_A = (0..7).map do |col_n|
  win_in_colA(col_n)
end

steps_for_B = (0..7).map do |col_n|
  win_in_colB(col_n)
end

who_won = (steps_for_B.min < steps_for_A.min) ? 'B' : 'A'
puts who_won

field = []
while line = gets
  field << line.chomp.split("")
end
field = field.transpose
stepA = []
stepB = []
field.each do |r|
  a = r.rindex("W")
  b = r.rindex("B")
  unless b.nil? then
    if a.nil? or (a < b) then
      stepB << 7 - b
    end
  end
  a = r.index("W")
  b = r.index("B")
  unless a.nil? then
    if b.nil? or (a < b) then
      stepA << 7 - a
    end
  end
end
if stepB.empty? or (stepA.min < stepB.min) then
  puts "A"
elsif stepA.empty? or (stepA.min > stepB.min) then
  puts "B"
end

a = Array.new(8)
for x in 0..7
    a[x] = gets
end
for x in 0..7
    for y in 0..7
        if a[7 - x][y] == 'B'
            print "B\n"
            exit
        end
        if a[7 - x][y] == 'W'
            print "A\n"
            exit
        end
    end
end

n, a1, a2, min, c = [], [], [], 99999, ''
(0..7).each do |_|
  n << gets.chomp.split('')
end
(0..7).each do |i|
  arr, a1, a2 = [], [], []
  (0..7).each do |j|
    arr << n[j][i]
  end
  x = Array.new arr
  y = Array.new arr
  x.uniq!.delete('.')
  y.reverse!.uniq!.delete('.')
  a1 = x
  a2 = y
  if a1.size == 0
  	next
  elsif a1.size == 1
  	d = a1.first == 'W' ? arr.index('W') : arr.reverse.index('B')
  	if d < min || (d == min && c == 'W')
  		min = d
  		c = a1.first
  	end
  else
		if a1.first == 'W' && arr.index('W') <= min
			min = arr.index('W')
			c = 'W'
		end
		if a2.first == 'B' && arr.reverse.index('B') < min
			min = arr.reverse.index('B')
			c = 'B'
		end
  end
end
puts c == 'W' ? 'A' : 'B'

arr, arr1, arr2, index, min, result, c = [], [], [], 1000000, 99999, '', ''
(0..7).each do |_|
  arr << gets.chomp.split('')
end
(0..7).each do |i|
  arr1 = []
  (0..7).each do |j|
    arr1 << arr[j][i]
  end
  arr2 = Array.new arr1
  arr2.uniq!.delete('.')
  if arr2[0] && arr2.size == 1
    c = arr2[0]
    if c == 'W'
      index = arr1.index(c)
    else c == 'B'
      index = arr1.reverse.index(c)
    end
  end
  if index < min
    min = index
    result = c
  end
end
puts result == 'W' ? 'A' : 'B'

arr, arr1, arr2, index, min, result, c = [], [], [], 1000000, 99999, '', ''
(0..7).each do |_|
  arr << gets.chomp.split('')
end
(0..7).each do |i|
  arr1 = []
  (0..7).each do |j|
    arr1 << arr[j][i]
  end
  arr2 = Array.new arr1
  arr2.uniq!.delete('.')
  if arr2[0] && arr2.size == 1
    c = arr2[0]
    if c == 'W'
      index = arr1.index(c)
    else c == 'B'
      index = arr1.reverse.index(c)
    end
  end
  min = index; result = c if index < min
end
p result == 'W' ? 'A' : 'B'

arr, arr1, arr2, index, min, result, c = [], [], [], 1000000, 99999, '', ''
(0..7).each do |_|
  arr << gets.chomp.split('')
end
(0..7).each do |i|
  arr1 = []
  (0..7).each do |j|
    arr1 << arr[j][i]
  end
  arr2 = Array.new arr1
  arr2.uniq!.delete('.')
  if arr2[0] && arr2.size == 1
    c = arr2[0]
    if c == 'W'
      index = arr1.index(c)
    else c == 'B'
      index = arr1.reverse.index(c)
    end
  end
  if index < min
    min = index
    result = c
  end
end
p result == 'W' ? 'A' : 'B'

arr, arr1, arr2, index, min, result, c = [], [], [], 1000000, 99999, '', ''
(0..7).each do |_|
  arr << gets.chomp.split('')
end
(0..7).each do |i|
  arr1 = []
  (0..7).each do |j|
    arr1 << arr[j][i]
  end
  arr2 = Array.new arr1
  arr2.uniq!.delete('.')
  if arr2[0] && arr2.size == 1
    c = arr2[0]
    if c == 'W'
      index = arr1.index(c)
    else c == 'B'
      index = arr1.reverse.index(c)
    end
  end
  if index < min
    min = index
    result = c
  end
end
p result == 'W' ? :A : :B

class Solver
	def main
		map = []
		8.times do
			map << gets.chomp
		end
		move_a = 9
		move_b = 9

		8.times do |i|
			up_most_w = 10
			down_most_b = -1
			8.times do |j|
				up_most_w = [up_most_w, j].min if map[j][i] == "W"
				down_most_b = [down_most_b, j].max if map[j][i] == "B"
			end
			if up_most_w == 10 && down_most_b != -1 then
				move_b = [move_b, 7 - down_most_b].min
			elsif up_most_w != 10 && down_most_b == -1 then
				move_a = [move_a, up_most_w].min
			elsif up_most_w != 10 && down_most_b != -1 then
				if up_most_w < down_most_b then
					move_a = [move_a, up_most_w].min
					move_b = [move_b, 7 - down_most_b].min
				end
			end
		end

		if move_a <= move_b then
			puts "A"
		else
			puts "B"
		end
	end
end

Solver.new.main


n, k, x = $stdin.gets.chomp.split(' ').map { |v| v.to_i }
a = $stdin.gets.chomp.split(' ').map { |v| v.to_i }

class Solver
  def initialize(n, k, x, a)
    @n = n
    @k = k
    @x = x
    @a = a
  end

  def cnt(l, r)
    ans = 0
    flag = false
    while true do
      sum = 0
      while l>-1 && @a[l] == @a[r]
        l -= 1
        sum += 1
      end
      l += 1
      while r < @n && @a[l] == @a[r]
        r += 1
        sum += 1
      end
      r -= 1
      return ans if flag && sum < 3
      flag = 1
      ans = [ans, r - l + 1].max
      l -= 1
      r += 1
      return ans if l <0 || r >= @n || @a[l] != @a[r]
    end
  end
end

solver = Solver.new(n, k, x, a)
ans = 0
for i in 0..n-1
  ans = [ans, solver.cnt(i, i+1)].max if a[i] == a[i+1] && a[i] == x
end

puts ans

# Created by Alex
n, k, x = gets.split.map {|i| i.to_i}
a = gets.split.map {|i| i.to_i}
max = 0
maxi = -1
for i in 0...n - 1
  #print a[i].to_s + ' '
  if a[i] != x || a[i + 1] != x
    next
  end
  l = i - 1
  r = i + 2
  cnt = 3
  while l >= 0 && r < n && a[l] == a[r]
    p1 = l
    while p1 > 0 && a[p1 - 1] == a[r]
      p1 -= 1
    end
    p2 = r
    while p2 < n - 1 && a[p2 + 1] == a[l]
      p2 += 1
    end
    if l - p1 + p2 - r + 2 < 3
      break
    end
    cnt += l - p1 + p2 - r + 2
    l = p1 - 1
    r = p2 + 1
  end
  if cnt >= max
    #print ' (' + cnt.to_s + ' ' + p1.to_s + ' ' + p2.to_s + ') '
    max = cnt
    maxi = i
  end
end
if max < 3
  max = 1
end
puts max - 1

myArray = $stdin.readlines

input=[]

myArray.each do |l|
  input.push(l)
end

a = input[0].split(',').map{|x| x.to_i}

#insert your code within this function
def solution(a)
  a2 = a.sort
  n = a2.size
  index_swap = 0
  for i in 0..n-1
    index_swap +=1 if a[i] != a2[i]
  end
  return index_swap <= 2
end

puts solution(a)

# Created by Alex
n, k, x = gets.split.map {|i| i.to_i}
a = gets.split.map {|i| i.to_i}
max = 0
for i in 0...n - 1
  if a[i] != x || a[i + 1] != x
    next
  end
  l = i - 1
  r = i + 2
  cnt = 3
  while l >= 0 && r < n
    p1 = l
    while p1 > 0 && a[p1 - 1] == a[r]
      p1 -= 1
    end
    p2 = r
    while p2 < n - 1 && a[p2 + 1] == a[l]
      p2 += 1
    end
    if l - p1 + p2 - r + 2 < 3
      break
    end
    cnt += l - p1 + p2 - r + 2
    l = p1 - 1
    r = p2 + 1
  end
  if cnt > max
    max = cnt
  end
end
if max < 3
  max = 1
end
puts max - 1

# Created by Alex
n, k, x = gets.split.map {|i| i.to_i}
a = gets.split.map {|i| i.to_i}
max = 0
for i in 0...n - 2
  if a[i + 1] != x || a[i + 2] != x
    next
  end
  l = i - 1
  r = i + 2
  cnt = 3
  while l >= 0 && r < n
    p1 = l
    while p1 > 0 && a[p1 - 1] == a[r]
      p1 -= 1
    end
    p2 = r
    while p2 < n - 1 && a[p2 + 1] == a[l]
      p2 += 1
    end
    if l - p1 + p2 - r + 2 < 3
      break
    end
    cnt += l - p1 + p2 - r + 2
    l = p1 - 1
    r = p2 + 1
  end
  if cnt > max
    max = cnt
  end
end
if max < 3
  max = 1
end
puts max - 1

# Created by Alex
n, k, x = gets.split.map {|i| i.to_i}
a = gets.split.map {|i| i.to_i}
max = 0
for i in 0...n - 1
  if a[i] != x && a[i + 1] != x
    next
  end
  l = i
  r = i
  if a[i] == x && a[i + 1] == x
    l = i - 1
    r = i + 2
  end
  if a[i] == x && i > 0 && a[i - 1] == x
    l = i - 2
    r = i + 1
  end
  if a[i + 1] == x && i + 2 < n && a[i + 2] == x
    l = i
    r = i + 3
  end
  if l == i && r == i
    next
  end
  cnt = 3
  while l >= 0 && r < n
    p1 = l
    while p1 > 0 && a[p1 - 1] == a[r]
      p1 -= 1
    end
    p2 = r
    while p2 < n - 1 && a[p2 + 1] == a[l]
      p2 += 1
    end
    if l - p1 + p2 - r + 2 < 3
      break
    end
    cnt += l - p1 + p2 - r + 2
    l = p1 - 1
    r = p2 + 1
  end
  if cnt > max
    max = cnt
  end
end
if max < 3
  max = 1
end
puts max - 1


LIMIT = 1000000007

@res = []
l = 1
while l < LIMIT
  @res << l
  l = l * 2
end

def power i
  return @res[i] if i < @res.size
  half_power = power(i/2)
  partial = (half_power * half_power) % LIMIT
  if i % 2 == 1
    partial = (partial * 2) % LIMIT
  end
  partial
end

years = gets.to_i

if years == 0
  puts 1
else
  partial = power(years-1)
  puts (partial * (((2 * partial) % LIMIT) + 1)) % LIMIT
end

# 2^(n-1) * (2^n +1)

$p = 1000000007
def mul(a,b)
  n = a.size
  c = Array.new(n){Array.new(n){0}}
  n.times do |i|
    n.times do|j|
      n.times do |k|
        c[i][j] += a[i][k] * b[k][j]
        c[i][j] %= $p
      end
    end
  end
  c
end

def po(m)
  e = [[3,1],[1,3]]
  ret = [[1,0],[0,1]]

  while m > 0
    if m % 2 == 1
      ret = mul(ret,e)
    end
    e = mul(e,e)
    m /= 2
  end

  ret
end

def work(n)
    if n == 1
      puts 3
    else
      ret = po(n)
      ans = ret[0][0]
      puts ans % $p
    end
end

n = gets.to_i
work n
#10.times{|x| work x+1}

def pow(a,k)
  n = 1000000007
  b = 1
  while (k!= 0) do
    if (k % 2 == 0 ) then
      k/=2
      a = (a*a) % n
    else
      k-=1
      b = (b*a) % n
    end
  end
  return b
end

n = gets.to_i
k = pow(2,n)
k = (k*(k-1)/2) % 1000000007
if (n == 0) then
  puts "1"
else
  ans = (pow(4,n) - k) % 1000000007
  puts ans
end

def pow(a,k)
  n = 1000000007
  b = 1
  while (k!= 0) do
    if (k % 2 == 0 ) then
      k/=2
      a = (a*a) % n
    else
      k-=1
      b = (b*a) % n
    end
  end
  return b
end

n = gets.to_i
if (n == 0) then
  puts "1"
else
  ans = pow(4,n)/2 + pow(2,n-1)
  puts ans
end

def pow(a,k)
  n = 1000000007
  b = 1
  while (k!= 0) do
    if (k % 2 == 0 ) then
      k/=2
      a = (a*a) % n
    else
      k-=1
      b = (b*a) % n
    end
  end
  return b
end

n = gets.to_i
if (n == 0) then
  puts "1"
else
  ans = (pow(4,n)/2 + pow(2,n-1)) % 1000000007
  puts ans
end


#!/usr/bin/env ruby

N = gets.to_i

def total_sections
  return 1 if N == 3
  return 4 if N == 4

  sections_without_2_triangles = (3..N-2).map do |second_vertice|
    third_vertice = second_vertice + 1

    lines_from_second = N - second_vertice - 1
    lines_from_third = third_vertice - 3

    lines_from_second + lines_from_third + 1
  end.inject(:+)

  sections_without_2_triangles + (N-2)*2
end

puts total_sections

angles = gets.to_i
puts (angles - 2) * (angles - 2)

n = gets.chomp.to_i
puts n ** 2 - 4 * n + 4

class Solver
	def main
		n = gets.to_i
		puts (n - 2) ** 2
	end
end

Solver.new.main

n = gets.to_i
puts n * (n - 3) - (n - 4)

n = gets.chomp.to_i
if n == 3 then
  puts 1
else
  a1 = 1
  4.upto(n).each do |a|
    a1 += 3 + 2*(a-4)
  end
  puts a1
end

#! /usr/bin/env ruby

n = $stdin.gets.to_i
puts (n-2)**2

n=gets.chomp.to_i
n=(n-1)*(n-3)+1
puts n.inspect


mas = gets.split(" ")
n, m, k = mas[0].to_i, mas[1].to_i, mas[2].to_i
per, ch = k-n-m+2, 2*(m-1)
if k < (n+m-1)
	finvar = k < n ? [k+1, 1] : [n, k-n+2]
else
	is = per % (m-1) == 0 ? (n-per/(m-1)) : (n-per/(m-1)-1)
	prom = per % ch
	if prom == 0
		prom = ch
	end
	finvar = prom <= (m-1) ? [is, m-prom+1] : [is, 1+prom-(m-1)]
end
puts finvar[0], finvar[1]

mas = gets.split(" ")
n, m, k = mas[0].to_i, mas[1].to_i, mas[2].to_i
per, ch = k-n-m+2, 2*(m-1)
if k < (n+m-1)
	finvar = k < n ? [k+1, 1] : [n, k-n+2]
else
	if per % (m-1) == 0
		is = n - per/(m-1)
	else
		is = n - per/(m-1) - 1
	end
	prom = per % ch
	if prom == 0
		prom = ch
	end
	finvar = prom <= (m-1) ? [is, m-prom+1] : [is, 1+prom-(m-1)]
end
puts finvar[0], finvar[1]

n, m, k = gets.split.map(&:to_i)
if k < n
    puts "#{k + 1} 1"
else
    hoge = (m - 1) * 2
    k -= n
    r = n - k / hoge * 2
    tmp = k % hoge
    c = 0
    if tmp < m - 1
        c = tmp + 2
    else
        c = 2 * (m - 1) - tmp + 1
        r -= 1
    end
    puts "#{r} #{c}"
end

mas = gets.split(" ")
n, m, k = mas[0].to_i, mas[1].to_i, mas[2].to_i
per, ch = k-n-m+2, 2*(m-1)
if k < (n+m-1)
	finvar = k < n ? [k+1, 1] : [n, k-n+2]
else
	is = per % (m-1) == 0 ? (n-per/(m-1)) : (n-per/(m-1)-1)
	prom = per % ch == 0 ? ch : (per % ch)
	finvar = prom <= (m-1) ? [is, m-prom+1] : [is, 1+prom-(m-1)]
end
puts finvar[0], finvar[1]

mas = gets.split(" ")
n, m, k = mas[0].to_i, mas[1].to_i, mas[2].to_i
if k < (n+m - 1)
	finvar = k < n ? [k+1, 1] : [n, k-n+2]
else
	is = n - (Float(k-(n+m-2))/(m-1)).ceil
	ncheck = n % 2
	ischeck = is % 2
	if (ncheck ^ ischeck) == 0
		finvar = [is, 2 + ((k - (n+m-2)) % (m))]
	else
		if (per = ((k - (n+m-2)) % (m-1))) == 0
			finvar = [is, 2]
		else
			finvar = [is, m + 1 - per]
		end
	end
end
puts finvar[0], finvar[1]

mas = gets.split(" ")
n, m, k = mas[0].to_i, mas[1].to_i, mas[2].to_i
if k < (n+m - 1)
	finvar = k < n ? [k+1, 1] : [n, k-n+2]
else
	is = n - (Float(k-(n+m-2))/(m-1)).ceil
	finvar = [is, 2 + ((k - (n+m-2)) % (m-1))]
end
puts finvar[0], finvar[1]

mas = gets.split(" ")
n, m, k = mas[0].to_i, mas[1].to_i, mas[2].to_i
if k < (n+m - 1)
	finvar = k < n ? [k+1, 1] : [n, k-n+2]
else
	is = n - (Float(k-(n+m-2))/(m-1)).ceil
	prom = (k-n-m+2) % (2*(m-1))
	if prom == 0
		prom = 2*(m-1)
	end
	finvar = prom <= (m-1) ? [is, m-prom+1] : [is, 1+prom-(m-1)]
end
puts finvar[0], finvar[1]

mas = gets.split(" ")
n, m, k = mas[0].to_i, mas[1].to_i, mas[2].to_i
per, ch = k-n-m+2, 2*(m-1)
if k < (n+m-1)
	finvar = k < n ? [k+1, 1] : [n, k-n+2]
else
	if per % (m-1) == 0
		is = n - per/(m-1)
	else
		is = n - (Float(per)/(m-1)).floor - 1
	end
	prom = per % ch
	if prom == 0
		prom = ch
	end
	finvar = prom <= (m-1) ? [is, m-prom+1] : [is, 1+prom-(m-1)]
end
puts finvar[0], finvar[1]

mas = gets.split(" ")
n, m, k = mas[0].to_i, mas[1].to_i, mas[2].to_i
if k < (n+m - 1)
	finvar = k < n ? [k+1, 1] : [n, k-n+2]
else
	is = n - (Float(k-(n+m-2))/(m-1)).ceil
	ncheck = n % 2
	ischeck = is % 2
	if (ncheck ^ ischeck) == 0
		finvar = [is, 2 + ((k - (n+m-2)) % (m-1))]
	else
		if (per = ((k - (n+m-2)) % (m-1))) == 0
			finvar = [is, 2]
		else
			finvar = [is, m + 1 - per]
		end
	end
end
puts finvar[0], finvar[1]


N, M, R = gets.split.map(&:to_i)
S = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)

s = S.min
cnt = R / s
b = B.max
diff = b - s

money = R + diff * cnt
puts [money, R].max

n,m,r = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).min
b = gets.split.map(&:to_i).max
p a < b ? (r/a)*b + r % a : r

n,m,r = gets.split.map(&:to_i)
s = gets.split.map(&:to_i).min
b = gets.split.map(&:to_i).max
if s > b
    puts r
else
    puts r%s+(r/s)*b
end

n, m, r = gets.chomp.split.map(&:to_i)
buy = gets.chomp.split.map(&:to_i).min
sell = gets.chomp.split.map(&:to_i).max

if sell > buy
  shares = r / buy
  profit = shares * (sell - buy)
  r += profit
end

puts r


#!/usr/bin/ruby
# Made With LOVE <3

n = gets.to_i
i=1
s=0
while i<=n
s = s + n - (i-1)
i*=10
end

puts s

# cook your code here

a = gets.to_i
b = 0
ans = 0

until a < b
    ans = ans + a - b;
    b = 10*b + 9
end

puts ans

def f(n)
    result, total, k = 0, 10, 1

    while n >= total do
       result += k * (total - total / 10)
       k += 1
       total *= 10
    end

    result + (n - total / 10 + 1) * k
end

puts f(gets.to_i)

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 * 10 ** (count - 1)) * count
end

puts result

n = gets.to_i
ans = 0
len = 1
base = 10
while true
    if n < base then
        ans += (n - base / 10 + 1) * len
        break
    else
        ans += base / 10 * 9 * len
    end
    len += 1
    base *= 10
end
puts ans

# http://codeforces.com/contest/552/problem/B
n = gets.chomp.to_i
sum = 0

(0...n.to_s.chars.length).each do |idx|
  d = [9 * (10 ** idx), n].min
  n -= d
  sum += d * (idx + 1)
end

puts sum

# coding: utf-8

# 총 기록해야하는 숫자의 개수를 의미를 가리킵니다.
# n = 13의 경우
# n[1..9]: 1, 2, 3, 4, 5, 6, 7, 8, 9 -> 9글자
# n[10..13]: 10, 11, 12, 13 -> 8글자
# 총 합쳐서 17글자가 필요합니다.

n = gets.to_i
t = 0
for i in 1..10
    s, e = 10**(i-1), (10**i) - 1
    #p [s,e]
    if e < n
        t += (e - s + 1) * i # 10 ~ 99 -> 총 몇개의 숫자가 존재할까, 89개가 아니라 90개
    else
        if s <= n
            t += (n - s + 1) * i
        else
            break
        end
    end
end

puts t

number = gets.chomp.to_i
result = 0
maxDigit = 10
divisor = 1000000000

until number / divisor != 0
	maxDigit -= 1
	divisor /= 10
end

nowDigit = 1

until nowDigit == maxDigit
	result += (9 * (10**(nowDigit - 1))) * nowDigit

	nowDigit += 1
end

result += ((number - (10**(maxDigit - 1))) + 1) * maxDigit

puts result

a=gets.chomp
l=a.length-1
if l==0
puts a
else
ans=9
2.upto l do |i|
ans+= (9*(10**(i-1)))*i
end
ans+=(a.to_i-("9"*l).to_i)*(l+1)
puts ans.inspect
end

n = gets.chomp
ans = 0
num = 9
(1...n.size).each do |i|
    ans += i*num
    num *= 10
end
ans += n.size*(n.to_i-10**(n.size-1)+1)
puts ans

n = gets.to_i
ans = 0
n.to_s.chars.size.times do |i|
  a = [9 * (10 ** i), n].min
  n -= a
  ans += a * (i + 1)
end
p ans

a=gets.to_i
r=9
ans=0
while a>0
	ans+=a
	a-=r
	r*=10
end

puts ans

#!/usr/bin/env ruby

num = ARGF.gets.chomp
length = num.length
count = 0
if length > 1
    num = (num.to_i - ('9' * (length - 1)).to_i).to_s
end

count += (num.to_i) * length

length -= 1
while (length > 0) do
    count += (9 * 10**(length - 1)) * length
    length -= 1
end

puts count

n = gets.to_i
d = n.to_s.length

ans = n * d
1.upto(d - 1) do |i|
	ans -= (d - i) * 9 * 10 ** (i - 1)
end
puts ans

n = gets.to_i
s = 1
ans = 0
while s.to_s.length < n.to_s.length
  ans += s * 9 * s.to_s.length
  s *= 10
end
ans += (n - s + 1) * n.to_s.length
p ans

#!/usr/bin/env ruby

num = ARGF.gets.chomp
length = num.length
count = 0
if length > 1
    num = num[1..-1]
end
count += (num.to_i + 1) * length
if length == 1
    count -= 1
end

length -= 1
while (length > 0) do
    count += (9 * 10**(length - 1)) * length
    length -= 1
end

puts count

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

result

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

#!/usr/bin/ruby
# Made With LOVE <3

n = gets.to_i
i=1
s=0
while i<n
s += n - (i-1)
i*=10
end

puts s

# coding: utf-8

# 총 기록해야하는 숫자의 개수를 의미를 가리킵니다.
# n = 13의 경우
# n[1..9]: 1, 2, 3, 4, 5, 6, 7, 8, 9 -> 9글자
# n[10..13]: 10, 11, 12, 13 -> 8글자
# 총 합쳐서 17글자가 필요합니다.

n = gets.to_i
t = 0
for i in 1..10
    s, e = 10**(i-1), (10**i) - 1
    #p [s,e]
    if e < n
        t += (e - s + 1) * i # 10 ~ 99 -> 총 몇개의 숫자가 존재할까, 89개가 아니라 90개
    else
        if s < n
            t += (n - s + 1) * i
        else
            break
        end
    end
end

puts t


a=gets.chomp.to_i
ans=0
loop do
if a%2==1
    ans+=1
end
a=a/2
break if a==0
end
puts "#{ans}"

user_input = gets.chomp
user_input = user_input.to_i
count = 0
while user_input != 0
  count += user_input & 1
  user_input = user_input >> 1
end
print count

class Solver
	def main
		n = gets.to_i
		ans = (0..30).to_a.count { |i| n[i] == 1 }
		puts ans
	end
end

Solver.new.main

#!/usr/bin/ruby

n = gets.to_i
ans = 0
while n > 0
  # p  "n=#{n}, ans=#{ans}"
  ans+=1 if n % 2 == 1
  n/=2
end

puts ans

p sprintf("%b", gets.chomp).gsub('0', '').length

#! /usr/bin/env ruby

x = gets.to_i
puts x.to_s(2).count('1')

a = gets.to_i
sum = 0
(0..48).each {|n| sum += a[n]}
puts sum

n = gets.chomp.to_i

c = 0

while n > 1

  if n % 2 == 0
    n /= 2
  else
    c += 1
    n -= 1
  end
end

puts c + 1

x = gets.to_i
ans = 0
while x>0
  x=x&(x-1)
  ans += 1
end
print ans

n=gets.to_i.to_s(2)
p n.chars.count{|e|
	e=="1"
}

n = gets.to_i
r = 0
while n > 0
	if n % 2 > 0
		r += 1
	end
	n = n / 2
end
p r

#$stdin = File.open('in.txt')
#$stdout = File.open('out.txt', 'w')

n = gets.to_i

ans = 0
while (n > 0) do
  ans += 1 if n % 2 == 1
  n /= 2
end

p ans

x = gets.chomp.to_i

rtn = 0
while 0 < x
  rtn += x % 2
  x /= 2
end
puts rtn

num = gets.chomp.to_i
count = 0
until num == 0
  count += num%2
  num = num/2
end
p count

a = gets.to_i
ans = 0
c = 2**30
while c > 0
  ans += a / c
  a %= c
  c /= 2
end
puts ans

#!/usr/bin/ruby

n = gets.to_i
x = 1
while x*2 <= n
  x*=2
end

puts 1 + n - x

a = gets.to_i
puts a.odd? && a != 1 ? 2 : 1


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

puts n.num_at_position(k)

def run
  n, k = $stdin.gets.split.map(&:to_i)

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

run if $0 == __FILE__

n, k = gets.chomp.split.map &:to_i
if k > (n / 2.0).ceil
  puts 2 * (k - (n / 2.0).ceil)
else
  puts 2 * k - 1
end

class A
  def initialize
    n, k = gets.split(' ').map(&:to_i)
    d = 0

    if n.even?
      if k <= n/2
        puts 2*k-1
      else
        puts 2*(k-n/2)
      end
    else
      if k <= n/2+1
        puts 2*k-1
      else
        puts 2*(k-(n/2+1))
      end
    end
  end
end

a = A.new

a=gets.chomp.split(" ")
odd=(a[0].to_i/2.0).ceil
even=(a[0].to_i/2.0)
if a[1].to_i<=odd
ans=2*(a[1].to_i-1)+1
puts "#{ans}"
else
ans=2*(a[1].to_i-odd)
puts "#{ans}"
end

n, k = gets.chomp.split(/ /).map(&:to_i)
mid = n / 2
mid += 1 if n.odd?
ans = (k - mid) * 2
ans = (2 * k) - 1 if mid >= k
puts "#{ans}"

n,k=gets.split.map{|e| e.to_i}
e=n/2+n%2
puts (k<=e)?2*k-1:(k-e)*2

n, k = gets.chomp.split.map(&:to_i)
a = n.odd? ? n/2+1 : n/2
puts k <= a ? 2*k-1 : 2*(k-a)

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

t = (n.to_f / 2).ceil

if k < t
  puts 1 + 2 * k
else
  puts 2 + 2 * (k - t)
end

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

if d % 2 == 0
  ot = d/2
  if n <= ot
    puts (2*n) - 1
  else
    puts 2*(n-ot)
  end
else
  ot = (d/2.0).ceil
  if n <= ot
    puts (2*n) - 1
  else
    puts 2*(n-ot)
  end
end

n,k=gets.split.map(&:to_i)
odd=(n+1)/2
puts k<=odd ? 2*k-1 : 2*(k-odd)

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

if position <= (numbers/2) + (numbers%2)
	new_number = (position * 2) - 1
else
	new_number = (position - ((numbers/2) + (numbers%2))) * 2
end

print new_number

#puts "Enter the total number and position to find the number\n"
n, v = gets.split.map(&:to_i)
if n%2 == 0
    m = n/2
else
    m = n/2 + 1
end
if v <= m
    puts (2*v)-1
else
    puts 2*v - (2*m)
end

n,k = gets.split(" ").map(&:to_i)
even_count = n /2
odd_count = n / 2
odd_count += 1 if n % 2 != 0
ans = k > odd_count ? (k - odd_count) * 2 : k * 2 - 1
puts ans

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

if a >= b * 2 - 1 - a % 2
  puts b * 2 - 1
else
  puts (b - a/2 - a % 2) * 2
end

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

if k <= n / 2 + (n % 2 == 1 ? 1 : 0)
	puts k * 2 - 1
else
	if n % 2 == 1
		puts (k - n / 2 - 1) * 2
	else
		puts (k - n / 2) * 2
	end
end

n, k = gets.chomp.split(' ').collect { |i| i.to_i }

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

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

mid = (n+1)/2
if k>mid
 puts 2*(k-mid)
else
 puts (k*2)-1
end

n,k = gets.split(" ").map(&:to_i)
m = (n/2.0).ceil()
if(k<=m)
    print((2*k)-1)
else
    print(2*(k-m))
end

s = gets.split(' ')	#Танцы с бубном

n = s[0].to_i
k = s[1].to_i

f = k - n/2 - n%2

if f > 0
	puts 2 * f
else
	puts n - 1 + n % 2 + 2 * f
end

n, k = gets.strip.split(" ").collect{|v| v.to_i}
if k <= (n / 2.0).ceil then
  puts ((k-1)*2+1)
else
  puts ((k-(n/2.0).ceil)*2)
end

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

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

val += 2*(k-1)

print val

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

if 2*k-1 <= n
  puts 2*k-1
else
  puts 2*k - n - n%2
end

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

mid = n/2 + n%2

if k > mid
  puts (k-mid)*2
else
  puts 2*k-1
end

#!/usr/bin/env ruby

n, k = gets.split.map(&:to_i)
puts k > (n + 1) / 2 ? (k - (n + 1) / 2) * 2 : 2 * k - 1

g = gets.split(' ')

n = g[0].to_f
k = g[1].to_i

if k > (n/2).ceil
    if n.modulo(2) == 0
        i = 2*k - n
    else
        i = 2*k - n - 1
    end
else
    i = 2*k - 1
end

puts i.to_i

n,k =gets.split(' ').map{|i| i.to_i()}
ans=k+k-1
if(ans>n)
	ans=(k-((n+1)>>1))<<1
end
p ans

n, k = gets.split.map { |x| x.to_i }
evens = n / 2
odds = n - evens
offset = 0
if k > odds
	k -= odds
	offset = 1
end

puts k * 2 - 1 + offset

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

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

maxOdd = (n + 1) / 2

puts (2 * k) - 1 if k <= maxOdd
puts (2* (k - maxOdd)) if k > maxOdd

n, k = gets.split(' ').map(&:to_i)
ofs = (n+1)/2
if k <= ofs
  puts 2*k-1
else
  puts 2*(k-ofs)
end

sin = STDIN
sout = STDOUT
# sin = File.open("test.in", "r")
# sout = File.open("test.out", "w")

n, k = *sin.readline.split.map{|e| e.to_i}
sout.puts k <= (n + 1) / 2 ? (2 * k - 1) : ((k - (n + 1) / 2) * 2)

STDIN.each_line { |l|
    l.strip!
    t = l.split(/\s+/)
    n = t[0].to_i
    k = t[1].to_i

    if k <= (n + 1) / 2 then
        puts 2 * k - 1
    else
        puts 2 * (k - (n + 1) / 2)
    end
}

n_k = gets.split.map &:to_i

n = n_k[0]
k = n_k[1]

half_n = n.even? ? n / 2 : n / 2 + 1

kth_element = k <= half_n ? 2 * k - 1 : 2 * (k - half_n)

puts kth_element

n,k = gets.split.map(&:to_i)
t=(n/2.0).ceil
p k>t ? 2*(k-t) : 2*k-1

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

cs = (n+1)/2
if k > cs
    puts (k-cs)*2
else
    puts (k*2)-1
end

n, k = $stdin.readline.split.map(&:to_i)

if n%2==0
    if k <= n/2
        puts 2*(k-1)+1
    else
        k -= n/2
        puts 2*(k)
    end
else
    if k <= n/2+1
        puts 2*(k-1)+1
    else
        k -= n/2+1
        puts 2*(k)
    end
end

#!/usr/bin/env ruby
n, k = gets.split(' ').map(&:to_i)
odd = (n + 1) / 2
even = n / 2
if k <= odd
  puts k * 2 - 1
else
  puts (k - odd) * 2
end

def run
  n, k = $stdin.gets.split.map(&:to_i)

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

run if $0 == __FILE__

n, k = gets.chomp.split.map &:to_i
if k > (n / 2.0).ceil
  puts 2 * (n - (n / 2.0).ceil)
else
  puts 2 * k - 1
end

n, k = gets.chomp.split.map(&:to_i)
if k < n / 2
  puts 2 * (k-1) + 1
else
  puts 2 * ((k-1) / 2)
end

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

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

n,k=gets.split.map(&:to_i)
puts (2*k<=n ? 2*k-1 : k/2*2)

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

if k <= n / 2
	puts k * 2 - 1
else
	if n % 2 == 1
		puts (k - n / 2 - 1) * 2
	else
		puts (k - n / 2) * 2
	end
end

s = gets.split(' ')	#Танцы с бубном

n = s[0].to_i
k = s[1].to_i

a = 1
i = 1

while a <= n  && i < k
	a += 2
	i += 1
end

if i < k
	a = 2
end

while i < k
	a += 2
	i += 1
end

puts a

n = gets.to_i
k = gets.to_i

a = 1
i = 1

while a <= n  && i < k
	a += 2
	i += 1
end

if i < k
	a = 2
end

while i < k
	a += 2
	i += 1
end

puts a

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

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

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

print val

g = gets.split(' ')

n = g[0].to_f
k = g[1].to_i

if k > (n/2).ceil
    i = 2*k - n
else
    i = 2*k - 1
end

puts i

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

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

maxOdd = (n - 1) / 2

puts (2 * k) - 1 if k <= maxOdd
puts (k / 2) + maxOdd if k > maxOdd

n, k = $stdin.readline.split.map(&:to_i)

if n%2==0
    if k <= n/2
        puts 2*(k-1)+1
    else
        puts 2*(k-1-n/2)
    end
else
    if k < n/2
        puts 2*(k-1)+1
    else
        puts 2*(k-1-n/2)
    end
end

n, k = $stdin.readline.split.map(&:to_i)

if n%2==0
    if k <= n/2
        puts 2*(k-1)+1
    else
        puts 2*(k-n/2)
    end
else
    if k <= n/2+1
        puts 2*(k-1)+1
    else
        puts 2*(k-n/2)
    end
end

n, k = $stdin.readline.split.map(&:to_i)

if n%2==0
    if k <= n/2
        puts 2*(k-1)+1
    else
        puts 2*(k-n/2)
    end
else
    if k < n/2
        puts 2*(k-1)+1
    else
        puts 2*(k-1-n/2)
    end
end


n = gets().to_i
arr = []
n.times do
  arr += [gets().to_i]
end
cur = "0" * n
last = "1" * n
f = false
while (cur.to_i(10) < last.to_i(10))
  d = 0
  arr.each_with_index do |e, ind|
    if cur[ind] == '0'
      d -= e
    else
      d += e
    end
  end
  if (d % 360 == 0)
    f = true
    break
  end
  cur = (cur.to_i(2) + 1).to_s(2)
  # puts cur
  cur = ("0" * (n - cur.size)) + cur
end
if f
  puts "YES"
else
  puts "NO"
end

N = gets.to_i
as = [0]
bs = nil
N.times {
  rot = gets.to_i
  bs = as.map{ |a| [(a+rot)%360, (a-rot+360)%360]}.flatten.uniq
  as,bs = bs,as
}
puts as.include?(0) ? "YES" : "NO"

n,*a=$<.read.split.map &:to_i
s=a.reduce :+
puts (1<<n).times.any?{|i|t=n.times.select{|j|i[j]>0}.map{|j|a[j]}.reduce 0,:+;(s-2*t)%360==0} ? :YES : :NO

# Utility

# Better use B-tree but eff that
def spin(angle, initial = [0])
  return Array.new(initial.length * 2) { |i| initial[i / 2] + angle * (-1)**(i % 2) }
end

# Input
n = gets.to_i
a = Array.new(n) { |i| gets.to_i }

# Processing
variants = [a[0]]
(n - 1).times do |i|
  variants = spin(a[1 + i], variants)
end

able_to_open = variants.detect { |el| el % 360 == 0 }

# Output
puts(able_to_open ? "YES" : "NO")

n,*a=$<.read.split.map &:to_i
s=a.reduce :+
puts (1<<n).times.any?{|i|t=n.times.select{|j|i[j]>0}.map{|j|a[j]}.reduce 0,:+;t%360==0} ? :YES : :NO

n,*a=$<.read.split.map &:to_i
s=a.reduce :+
puts (1<<n).times.any?{|i|t=n.times.select{|j|i[j]>0}.map{|j|a[j]}.reduce 0,:+;t*2==s} ? :YES : :NO


n = gets.to_i
s = gets.chomp
c = Hash.new(0)
for i in 0..n-1
  c[s[i]] += 1
end
puts (n == 1 || c.values.any?{|i|i > 1}) ? "Yes" : "No"

n=gets.to_i
puts n>gets.chomp.chars.uniq.size||n==1?:Yes: :No

N = gets.to_i
S = gets.chomp.split('').sort
if N == 1
    puts 'Yes'
    exit
end

(N-1).times do |i|
    if S[i] == S[i+1]
        puts 'Yes'
        exit
    end
end
puts 'No'

useless = gets.chomp
line = gets.chomp
a = Array.new(26,0)
if(line.size == 1)
	print ("Yes")
	exit
end
for i in 0...line.size
	a[line[i].ord - 97] += 1
end

for i in 0...26
	if(a[i] > 1)
		print("Yes")
		exit
	end
end
print("No")

n = gets.split()[0].to_i
s = gets.split()[0]
mx = 0
('a'..'z').each do |x|
    mx = [mx, (s.count x)].max
end
puts ((mx > 1 or s.length == 1) ? 'Yes' : 'No')

n = gets.to_i
str = gets.chomp

if n==1
  puts "Yes"
  exit
end

if n>26
  puts "Yes"
else
  hash = Hash.new(0)
  str.each_char {|x| hash[x]+=1}

  if hash.values.max==1
    puts "No"
  else
    puts "Yes"
  end
end

n=gets.to_i
puts n>gets.chars.uniq.size||n==1?:Yes: :No

n = gets.to_i
s = gets.chomp
c = Hash.new(0)
for i in 0..n-1
  c[s[i]] += 1
end
puts c.values.any?{|i|i > 1} ? "YES" : "NO"

useless = gets.chomp
line = gets.chomp
a = Array.new(26,0)

for i in 0...line.size
	a[line[i].ord - 97] += 1
end

for i in 0...26
	if(a[i] > 1)
		print("Yes")
		exit
	end
end
print("No")

n = gets.to_i
str = gets.chomp

if n==1
  puts "Yes"
end

#if n>26
#  puts "Yes"
#  exit
#else
  hash = Hash.new(0)
  str.each_char {|x| hash[x]+=1}

  if hash.values.max<2
    puts "No"
  else
    puts "Yes"
  end
#end

n = gets.to_i
str = gets.chomp

if n==1
  puts "Yes"
end

if n>26
  puts "Yes"
  exit
else
  hash = Hash.new(0)
  str.each_char {|x| hash[x]+=1}

  if hash.values.max<2
    puts "No"
  else
    puts "Yes"
  end
end

n = gets.to_i
str = gets.chomp

if n>26
  puts "Yes"
  exit
else
  hash = Hash.new(0)
  str.each_char {|x| hash[x]+=1}

  if hash.values.max<2
    puts "No"
  else
    puts "Yes"
  end
end


n1,n2,k1,k2=gets.split.map{|e| e.to_i}
if n1>n2 then
	puts "First"
else
	puts "Second"
end

pa=Array.new
str=gets.to_s
pa=str.split
n1=pa[0].to_i
n2=pa[1].to_i
if n1<=n2
  puts "Second"
else
  puts "First"
end

a, b, c, d = gets.split.map{|i| i.to_i}
puts a > b ? 'First' : 'Second'

n1, n2 = *gets.split.map(&:to_i)
puts n1 <= n2 ? "Second" : "First"

n1, n2, k1, k2 = gets.split.map { |x| x.to_i }
if n1 > n2
	puts 'First'
else
	puts 'Second'
end

a, b = gets.strip.split.map( &:to_i )
puts a <= b ? "Second" : "First"

#!/usr/bin/ruby

input = STDIN.readline.chomp
input = input.split(' ')
if input[0].to_i > input[1].to_i
    puts "First"
elsif input[0] == input[1]
    puts "Second"
else
    puts "Second"
end

#!/usr/bin/ruby

input = STDIN.readline.chomp
input = input.split(' ')
if input[0].to_i > input[1].to_i
    puts "First"
elsif input[0].to_i == input[1].to_i
    puts "Second"
else
    puts "Second"
end

n1,n2,k1,k2=gets.chomp.split

n1 = n1.to_i
n2 = n2.to_i

case n1<=>n2
    when 0
        print "Second";
    when 1
        print "First";
    when -1
        print "Second";
end

n,m,k,l=gets.split.map &:to_i
puts n>m ? "First" : "Second"

n1, n2, k1, k2 = $stdin.readline.split.map(&:to_i)

if n1>n2
    puts "First"
else
    puts "Second"
end

#le roi est mort is here
k, l, c, d = gets.split.map &:to_i
if k > l
  puts "First"
else
  puts "Second"
end

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

a, b, c, d = gets.split.map &:to_i
puts (a > b) ? "First" : "Second"

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

n, m, a, b = gets.split().map(&:to_i)
if n>m
  puts "First"
else
  puts "Second"
end

n1, n2, k1, k2 = gets.split.map(&:to_i)

if n1 > n2
  puts 'First'
else
  puts 'Second'
end

n,m,k,l = gets.split.map(&:to_i)
puts n > m ? 'First' : 'Second'

#!/usr/bin/ruby

input_line = gets

params = input_line.split(' ')
n1 = params[0].to_i
n2 = params[1].to_i
k1 = params[2].to_i
k2 = params[3].to_i

if (n1<=n2)
    puts 'Second'
else
    puts 'First'
end

n1, n2, k1, k2 = gets.split.map &:to_i

puts (n1 > n2) ? "First" : "Second"

s = gets.split(" ").map { |e| e.to_i }
puts "First" if s[0] > s[1]
puts "Second" if s[0] <= s[1]

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

if n1 <= n2
	print "Second"
elsif n1 > n2
	print "First"
end

arr = $stdin.readline.split(" ")
n1=  Float("#{arr[0]}")
n2 = Float("#{arr[1]}")
k1 = Float("#{arr[2]}")
k2 = Float("#{arr[3]}")
if (n2 + 1 > n1 )
    puts "Second"
else
    puts "First"
end

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

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

a,b,c,d=gets.chomp.split.map &:to_i
puts (a>b)? :First: :Second

n1, n2, k1, k2 = gets.split.map(&:to_i)
puts n1 > n2 ? "First" : "Second"

input = gets.split(" ")
n1 = input[0].to_i
n2 = input[1].to_i
if n1 > n2
  puts "First"
else
  puts "Second"
end

n_1, n_2, k_1, k_2 = gets.split.map{|x| x.to_i}
puts(n_1 > n_2 ? 'First' : 'Second')

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

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

a, b = gets.strip.split
puts a <= b ? "Second" : "First"

# cook your code here

n1,n2,k1,k2=gets.chomp.split

case n1<=>n2
    when 0
        print "Second";
    when 1
        print "First";
    when -1
        print "Second";
end

a,b,c,d=gets.split &:to_i
puts (a>b)? :Second: :First

a,b,c,d=gets.split &:to_i
puts (a<=b)? :Second: :First

a,b,c,d=gets.split &:to_i
puts (a>b)? :First: :Second

n_1, n_2, k_1, k_2 = gets.split
puts(n_1 > n_2 ? 'First' : 'Second')

pa=Array.new
str=gets.to_s
pa=str.split
n1=pa[0]
n2=pa[1]
if n1<=n2
  puts "Second"
else
  puts "First"
end


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

cnt=0

if b>=n && g>=n
  cnt = n+1
elsif b<n && g<n
  diff = n-[b,g].max
  cnt = [b,g].min-diff+1
  cnt = 0 if cnt<0
else
  cnt = [b,g].min+1
end

puts cnt

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

ans = 0
(0..n).each do |bb|
  gg = n - bb
  ans += 1 if bb <= b && gg <= g
end
puts ans

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

cnt=0

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

puts cnt


a=gets.chomp.split(" ")
pow=a[0].to_i
price=a[1].to_i
apple=0
half=0
0.upto(pow-1) do |i|
k=gets.chomp
if k.length!=4
apple=apple+2**i
half+=1
end
end

ans=(apple-(0.5*half))*price
puts "#{ans.to_i}"

N, P = gets.split.map(&:to_i)
A = N.times.map{ gets.chomp }

x = A.reverse.reduce(0){|acc, a| (a == 'half') ? (acc * 2) : (acc * 2 + 1)}

ans = 0
N.times do
  if x % 2 == 0
    ans += P * (x/2)
  else
    ans += P * (x/2) + P/2
  end
  x /= 2
end

puts ans

#!/usr/bin/ruby
n,p=gets.split.map(&:to_i)
m=r=0
$<.map(&:chomp).reverse.each{|e|
	m+=1 if e.end_with?('plus')
	r+=m*p/2
	m*=2
}
p r

n, p = gets.split(' ').map(&:to_i)
rest = 0
sum = 0
records = []

for i in 1..n
  records.unshift(gets.to_s.chomp)
end

records.each do |record|
  if record == 'half'
    rest = rest * 2
    sum += rest * p / 2
  else
    rest = ( rest + 0.5 ) * 2
    sum += rest * p / 2
  end

end

puts sum.to_i

n, p = gets.chomp.split.map(&:to_i)
apples = 1.0
com = []
n.times do
  com << gets.chomp
end
halfplus = 1
com.pop
com.reverse.each do |c|
  if c == "halfplus" then
    apples += 0.5
    apples *= 2
    halfplus += 1
  else
    apples *= 2
  end
end

puts ((apples - halfplus * 0.5) * p).to_i


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

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

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

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

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

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

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

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

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

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

require 'prime'
n = inp[0]

d = Prime.prime_division(n)
if(d.size == 1 )
  p d[0][0]
else
  p 1
end

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

require 'set'

n = gets.to_i

dividers = Set.new []

i = 2
size = n

while i * i <= n
  if n % i == 0
    dividers.add(i)
    n /= i
    i -= 1
  end
  i += 1
end

dividers.add(n) if n > 1

arr = []
dividers.each { |num| arr << num }

if arr[0] == size
  puts size
elsif arr.size == 1
  puts arr[0]
else
  puts 1
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 kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

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

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

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

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

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

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

n = inp[0]
(2..((n**0.5).ceil)).each do |d|
  if (n%d ==0)
    p d
    exit
  end
end
p n

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

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

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

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

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

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

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

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

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

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

n = inp[0]
(2..((n**0.5).ceil)).each do |d|
  if (n%d ==0)
    if ( n/d  == d)
      p d
    else
      p 1
    end
    exit
  end
end
p n


Mod = (1e9 + 7).to_i

n = gets.to_i

ans1 = 1
ans2 = 1

n.times do
	ans1 *= 27
	ans2 *= 7

	ans1 %= Mod
	ans2 %= Mod
end

ans = (ans1 - ans2 + Mod) % Mod
puts ans


def function
b=gets.chomp
a=gets.chomp
a=a.split(' ').map(&:to_i).sort.reverse
1.upto a.length do |i|
if a[0..i-1].include?(a[i])
a[i]=a[i-1]-1
end
end
sum=0
a.each do |i|
if i>0
sum+=i
end
end
puts sum
end
function

n = gets.to_i
a = gets.split(" ").map(&:to_i).sort.reverse
x = a[0]
ans = 0
a.each do |k|
    k = [k, x].min
    ans += k
    x = k-1
    break if x == 0
end
p ans

gets
h={}
gets.split.map(&:to_i).each{|e| h[e] ? h[e]+=1 : h[e]=1}
f=->(n){n*(n+1)/2}
res=0
x=10**9*2
h.sort.reverse.each{|k,v|
    a=f[x=[k, x].min]
    b=f[[x-v, 0].max]
    res+=a-b
    x=[x-v, 0].max
}
puts res

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

as.sort!.reverse!
b = as[0]
as.each do |a|
  ans += [a, b].min
  b = [[a - 1, b - 1].min, 0].max
end

puts ans

gets
a=gets.split.map &:to_i
h = {}
a.sort.each{|x|
  x -= 1 while h[x]
  h[x] = true
}
p h.map{|k,v|[k,0].max}.inject :+

n = gets.to_i
a = gets.split(' ').map &:to_i
r = []
for v in a
  while r.index(v) && v > 0
    v-=1
  end

  r << v
end

puts r.inject(&:+)

class Solver
	def main
		n = gets.to_i
		arr = gets.split.map { |x| x.to_i }
		arr = arr.sort.reverse

		ans = 0
		last = 1 << 30
		arr.each do |x|
			x = last - 1 if x >= last
			ans += x if x >= 0
			last = x
		end
		puts ans
	end
end
Solver.new.main

def function
b=gets.chomp
a=gets.chomp
a=a.split(' ').map(&:to_i).sort.reverse
b=a.clone
1.upto a.length do |i|
if a[i]==a[i-1]
b[i]-=1
end
end
sum=0
b.each do |i|
sum+=i
end
puts sum
end
function

gets
a=gets.split.map &:to_i
h = {}
a.sort.each{|x|
  x -= 1 while h[x]
  h[x] = true
}
if h[-1]
  p 0
else
  p h.map{|k,v|k}.inject :+
end

gets
a=gets.split.map &:to_i
h = {}
a.sort.each{|x|
  x -= 1 while h[x]
  h[x] = true
}
if h.find 0
  p 0
else
  p h.map{|k,v|k}.inject :+
end

n = gets.to_i
a = gets.split(' ').map &:to_i
r = []
broken = false
for v in a
  while r.index(v)
    v-=1
  end
  if v >= 0
    r << v
  else
    r = [0]
    break
  end
end

puts r.inject(&:+)


w,b=gets.split.map(&:to_i)
$dp=Array.new(1002){Array.new(1002){Array.new(2,-1)}}
#t=0 姫 t=1 ドラゴン
def solve(w,b,t)
        return 0 if b<0 || w<0
        return 0 if w+b==0
        return $dp[w][b][t] if $dp[w][b][t]>=0
        res=0.0
        if t==0 then
                res+=w.to_f/(w+b)
                res+=b.to_f/(w+b)*solve(w,b-1,1-t)
        else
                #Wを取る
                res=0
                #Bを取る
                tb=b-1
                tw=w
                if tb+tw==0 then
                        res=0
                else
                        res+=b.to_f/(w+b)*tb.to_f/(tb+tw)*solve(w,b-2,1-t)
                        res+=b.to_f/(w+b)*tw.to_f/(tb+tw)*solve(w-1,b-1,1-t)
                end
        end
        return $dp[w][b][t]=res
end
p solve(w,b,0)

Memo = {}# Array.new(1001*1001)

def f(w, b)
  return 0 if w==0
  ix = w*1001 + b
  return Memo[ix] if Memo[ix]
  res = 1.0*w/(w+b)
  if b>1
    m = 1.0*b*(b-1)/(w+b)/(w+b-1)
    wr = 1.0*w/(w+b-2)
    wp = f(w-1, b-2)
    br = 1.0-wr
    bp = 0
    bp = f(w, b-3) if b>2
    res += m * (wr*wp + br*bp)
  end
  Memo[ix] = res
  #puts "for w=#{w} b=#{b}: #{res}"
  res
end

w,b = readline.split(' ').map(&:to_i)
puts f(w,b)

Memo = Array.new(1001*1001)

def f(w, b)
  return 0 if w==0
  ix = w*1001 + b
  return Memo[ix] if Memo[ix]
  res = 1.0*w/(w+b)
  if b>1
    m = 1.0*b*(b-1)/(w+b)/(w+b-1)
    wr = 1.0*w/(w+b-2)
    wp = f(w-1, b-2)
    br = 1.0-wr
    bp = 0
    bp = f(w, b-3) if b>2
    res += m * (wr*wp + br*bp)
  end
  Memo[ix] = res
  #puts "for w=#{w} b=#{b}: #{res}"
  res
end

w,b = readline.split(' ').map(&:to_i)
puts f(w,b)


r, c, n, k = gets.split.map(&:to_i)
pos = n.times.map{gets.split.map(&:to_i)}

photos = 0
for top in 1..r do
  for left in 1..c do
    for down in top..r do
      for right in left..c do
        alts = pos.count do |x, y|
          x >= top && x <= down && y >= left && y <= right
        end
        photos += 1 if alts >= k
      end
    end
  end
end
puts photos

buf = gets.split(' ')
r,c,n,k = buf[0].to_i, buf[1].to_i, buf[2].to_i, buf[3].to_i
a=Array.new(22)
for i in 0..r
	a[i]=Array.new(22, 0)
end
for i in 1..n
	buf = gets.split(' ')
	x, y = buf[0].to_i, buf[1].to_i
	a[x][y]=1
end
for i in 1..r
	for j in 1..c
		a[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1]
	end
end
ans=0
for x1 in 1..r
	for y1 in 1..c
		for x2 in x1..r
			for y2 in y1..c
				tot = a[x2][y2]-a[x1-1][y2]-a[x2][y1-1]+a[x1-1][y1-1]
				ans+=1 if tot>=k
			end
		end
	end
end
puts ans

l1 = gets.chomp
vals1 = l1.split(' ').map {|x| x.to_i}

r = vals1[0]
c = vals1[1]
n = vals1[2]
k = vals1[3]

violas = []
columns = []
c.times {|x| columns << 0}
r.times {|x| col = []; c.times {|y| col << 0}; violas << col }
minx = r
miny = c
maxx = -1
maxy = -1
n.times {
  indices = gets.chomp.split(' ').map {|x| x.to_i - 1}
  violas[indices[0]][indices[1]] = 1
  minx = indices[1] if indices[1] < minx
  miny = indices[0] if indices[0] < miny
  maxx = indices[1] if indices[1] > maxx
  maxy = indices[0] if indices[0] > maxy
}

Rect = Struct.new(:x, :y, :x2, :y2)

rectangles = []
(0..r-1).each do |y|
  (0..c-1).each do |x|
    (y..r-1).each do |y2|
      (x..c-1).each do |x2|
        v = 0
        (y..y2).each do |yi|
          (x..x2).each do |xi|
            v += violas[yi][xi]
          end
        end
        if v >= k
          rectangles << Rect.new(x, y, x2, y2) unless rectangles.any? {|r|
            r.x == x && r.y == y && r.x2 == x2 && r.y2 == y2
          }
        end
      end
    end
  end
end
puts rectangles.length


x,y,z,a,b,c=gets.split.map &:to_i
d=(x-y).abs
puts d*a<((x-z).abs+d)*b+3*c ? :No : :Yes

def solution
  x, y, z, stairs, elv, elv_doors = read_ints

  elv_time = ((z-x).abs + (x-y).abs) * elv + elv_doors * 3
  stair_time = (y-x).abs * stairs

  puts elv_time <= stair_time ? "YES" : "NO"

end

def read_int
  gets.to_i
end

def read_ints
  gets.split.map(&:to_i)
end

def read_string
  gets.chomp
end

solution unless ENV['TEST__MODE']

class A
  def self.run(s)
    x, y, z, t1, t2, t3 = s.split.map(&:to_i)
    walk = (x-y).abs * t1
    lift = (x-z).abs * t2 + t3*2 + (x-y).abs * t2 + t3
    if lift <= walk
      true
    else
      false
    end
  end
end

if A.run(gets.chomp)
  puts 'YES'
else
  puts 'NO'
end

x,y,z,t1,t2,t3 = gets.split.map { |e| Integer(e)  }
stair  = t1 * (x - y).abs
elevator =  t2 * (z - x).abs +  t3*2 + t2*(x-y).abs + t3
puts (if elevator <= stair then "YES" else "NO" end)

x, y, z, t1, t2, t3 = gets.split.map(&:to_i)

foot = (x-y).abs * t1
ev = (x-z).abs*t2+(x-y).abs*t2+t3*3

if foot < ev
  puts 'NO'
else
  puts 'YES'
end

line = gets.chomp

x, y, z, t1, t2, t3 = line.split.map(&:to_i)

elevator_time = ( (z-x).abs + (x-y).abs ) * t2 + 3 * t3
stair_time = (y-x).abs * t1

# puts elevator_time
# puts stair_time

if stair_time >= elevator_time
    puts "YES"
else
    puts "NO"
end

x, y, z, t1, t2, t3 = gets.split.map &:to_i
puts ((x - y).abs + (x - z).abs)*t2 + 3*t3 <= (x - y).abs*t1 ? 'YES' : 'NO'

xyzts = gets.chomp.split(" ").map(&:to_i)

x = xyzts[0]
y = xyzts[1]
z = xyzts[2]
t1 = xyzts[3]
t2 = xyzts[4]
t3 = xyzts[5]

st = (x-y).abs*t1
et = (x-z).abs*t2 + 3*t3 + (x-y).abs*t2

if et<=st
  puts "YES"
else
  puts "NO"
end


# cook your code here

n = gets.chomp

if (n[-1].to_i)%2==0
    puts "2"
else
    puts "1"
end

n = gets.chomp.to_i
puts n % 2 == 0 ? 2 : 1


x = gets.chomp.split(' ')
n = x[0].to_i
k = x[1].to_i
if k == 1
  puts n
else
  ans = 0
  i = 0
  while 2**i <= n
    ans += 2 ** i
    i += 1
  end
  puts ans
end

n,k=gets.split.map &:to_i
p k==1 ? n : 2**n.to_s(2).size-1

#!/usr/bin/ruby
include Math

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

if k == 1 then
	puts n
else
	puts (1 << n.to_s(2).length) - 1
end

#!/usr/bin/ruby
include Math

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

if k == 1 then
	puts n
else
	puts (1 << n.to_s(2).length) - 1
end


candies, friends = gets.strip.split(' ').map(&:to_i)

result = []
number = candies/friends
redundant = candies%friends
friends.times do |f|
  result << number
end
if redundant != 0
  for i in 0...redundant
    result[i] += 1
  end
  result = result.reverse
end

print result.join(' ')

n, m = gets.split.map(&:to_i)
r, n = n % m, n / m
r.times{print "#{n+1} "}
(m-r).times{print "#{n} "}

#!/usr/bin/ruby
n,m=gets.split.map(&:to_i)
puts m.times.map{|i|n/m+(i<n%m ? 1 : 0)}*' '

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

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

candies = input[0]
friends = input[1]

c = candies / friends
leftover = candies - c * friends

puts ("#{c} " * (friends - leftover) + "#{c + 1} " * leftover).rstrip

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

a = Array.new(m, 0)
for i in 0...n
  a[i%m] += 1
end

for i in a
  print i, " "
end


n=gets.to_i
s=gets.split('')
idx=0
ans=""
ctr=1
while idx<n do
  ans+=s[idx]
  idx+=ctr
  ctr+=1
end
puts ans

n=gets.to_i
i=x=0
s=gets.chomp
while i<n
print s[i]
i+=x+=1
end

# Input
n = gets.to_i
t = gets.chomp

# Processing
m = (((8*t.length + 1)**0.5 - 1) / 2).round
str = ""
m.times do |i|
  str << t[(i + 2) * (i + 1) / 2 - 1]
end

# Output
puts str

n = gets.to_i
s = gets.chomp
ans = ''
j = 0
(1..n).each do |i|
  j += i
  if s[j-1].nil?
    break
  end
  ans += s[j-1]
end
puts ans

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

def decrypt(n, t)
  s = ""
  c = 1
  i = 0
  while i < n do
    s += t[i]
    i += c
    c += 1
  end
  return s
end

n = gets.chomp.to_i
t = gets.chomp

puts decrypt(n, t)

n = gets.to_i
t = gets.strip
i = 0
d = 1
s = ''
while i < t.size
    s += t[i]
    i += d
    d += 1
end
puts s

n = gets.to_i
str = gets.chomp

newstr = ""

i = 0
(1..n).each do |x|
  newstr += str[i]
  i += x
  break if i>=str.length
end

puts newstr

gets
s = gets.chomp

result = ''
1.upto(10) do |i|
  break if s.empty?

  result += s[0]

  s.replace s[i..-1]
end

puts result


n = gets.to_i
x = 0
y = 0
for i in 1..Math.sqrt(n).round
  if (n%i === 0)
    x = i
    y = n/i
  end
end
print x
print " "
print y

require 'prime'
def find_minimum(row, col, factor, n)
  res = (0..n).collect {|i|
    [row * (factor**i), col * (factor**(n-i))]
  }.select{ |pair|
    pair[0] <= pair[1]
  }.min_by { |pair|
    pair[1] - pair[0]
  }
  res.nil? ? [1, row*col*(factor**n)] : res
end

def minimum_pair(row, col, primes)
  if primes.size == 1
    return find_minimum(row, col, primes[0][0], primes[0][1])
  else
    prime = primes[0][0]
    n = primes[0][1]
    rest = primes[1..-1]
    minimum = 10000000
    minimum_result = nil
    (0..n).collect { |i|
      minimum_pair(row*(prime**i), col*(prime**(n-i)), rest)
    }.select{ |pair|
      pair[0] <= pair[1]
    }.min_by { |pair|
      pair[1] - pair[0]
    }
  end
end

def solve(n)
  return [1,1] if n == 1
  return [0,0] if n == 0
  primes = n.prime_division
  minimum_pair(1, 1, primes)
end

puts solve(STDIN.read.to_i).join(" ")

n=gets.to_i
x, y=1, n
a=1
d=n-1
while a<=n
    if n % a==0 and n/a>=a and n/a-a<d
        x=a
        y=n/a
        d=y-x
    end
    a+=1
end
puts [x, y]*' '

class RectangleLike
  class << self
    def from_area(area)
      width = Math.sqrt(area).to_i
      new(area, width)
    end
  end

  attr_reader(:area, :width)
  def initialize(area, width)
    @area = area
    @width = width
  end

  def next
    if(not valid?)
      return RectangleLike.new(area, width - 1).next
    else
      return self
    end
  end

  def length
    (area / width).to_i
  end

  def valid?
    area == width * length
  end

  def to_s
    "#{width} #{length}"
  end

end

puts RectangleLike.from_area(gets.strip.to_i).next

n=gets.to_i
r=i=1
while i*i<=n
r=i if n%i==0
i+=1
end
puts '%d %d'%[r,n/r]

n = gets.to_i
a = (1..n).select { |x| x * x <= n && n % x == 0 }.last
puts [a, n / a].join(' ')

n = gets.to_i
a, b = 1, n
(1..Math.sqrt(n)).each do |i|
  a, b = i, n / i if n % i == 0
end
puts "#{a} #{b}"

require 'prime'
def find_minimum(row, col, factor, n)
  (0..n).collect {|i|
    [row * (factor**i), col * (factor**(n-i))]
  }.select{ |pair|
    pair[0] <= pair[1]
  }.min_by { |pair|
    pair[1] - pair[0]
  }
end

def minimum_pair(row, col, primes)
  if primes.size == 1
    return find_minimum(row, col, primes[0][0], primes[0][1])
  else
    prime = primes[0][0]
    n = primes[0][1]
    rest = primes[1..-1]
    minimum = 10000000
    minimum_result = nil
    (0..n).collect { |i|
      minimum_pair(row*(prime**i), col*(prime**(n-i)), rest)
    }.select{ |pair|
      pair[0] <= pair[1]
    }.min_by { |pair|
      pair[1] - pair[0]
    }
  end
end

def solve(n)
  primes = n.prime_division
  puts primes
  minimum_pair(1, 1, primes)
end

puts solve(STDIN.read.to_i).join(" ")


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

(1..4**2).each do |x|
  sum = 0
  (0..3).each do |i|
    if x & (1<< i) == 0
      sum += as[i]
    end
  end
  if sum * 2 == as.inject(:+)
    puts 'YES'
    exit
  end
end
puts 'NO'

a = gets.split.map &:to_i
(0..15).each do |x|
  f, s = 0, 0
  (0..3).each { |i| x & 1 << i != 0 ? f += a[i] : s += a[i] }
  if f == s
    puts 'YES'
    exit
  end
end
puts 'NO'

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

a = gets.split.map(&:to_i).sort
puts a[0] + a[3] == a[1] + a[2] ? 'YES' : 'NO'


#!/usr/bin/env ruby
point,x, y = [], [], []
8.times do
  point << gets.split(' ').map(&:to_i)
  x << point[-1][0] unless x.include? point[-1][0]
  y << point[-1][1] unless y.include? point[-1][1]
end
if x.sort!.size == 3 && y.sort!.size == 3
  if point.uniq.size == point.size && !point.include?([x[1], y[1]])
    puts "respectable"
  else
    puts "ugly"
  end
else
  puts "ugly"
end

points =[]
for i in 1..8
 temp=gets.chomp.split.collect{|a| a.to_i}
 points.push temp
end
xs=points.collect{|a| a.first}.sort.uniq
ys=points.collect{|a| a.last }.sort.uniq
#puts xs,ys
#puts points.uniq.length
if xs.length!=3 ||ys.length!=3 || points.uniq.length !=8
   puts "ugly"
else
  avg=[xs[1],ys[1]]
 # puts avg
  if points.include? avg
     puts "ugly"
  else
      puts"respectable"
  end
end

points = 8.times.map{|i| gets.split.map(&:to_i) }.uniq
puts [:first, :last].all?{|sym| points.group_by(&sym).to_a.sort_by(&:first).map{|x| x.last.length} == [3,2,3] } ? "respectable" : "ugly"

xy = []
8.times do
  x,y = gets.split(' ').map(&:to_i)
  xy << [x,y]
end

xs,ys = xy.transpose
xxs = xs.sort.uniq
yys = ys.sort.uniq

ok = xy.uniq.size == 8
xxs.each.with_index do |x,i|
  if xs.count(x) != (i == 1 ? 2 : 3)
    ok = false
    break;
  end
end if ok

yys.each.with_index do |y,i|
  if ys.count(y) != (i == 1 ? 2 : 3)
    ok = false
    break;
  end
end if ok

if !ok || xxs.size != 3 || yys.size != 3 || xy.include?([xxs[1], yys[1]])
  puts "ugly"
else
  puts "respectable"
end

def runb(list)
  x = list.map{|x,y| x}.uniq.sort
  y = list.map{|x,y| y}.uniq.sort

  return false unless x.size == 3
  return false unless y.size == 3
  x.each_with_index do |x,i|
    y.each_with_index do |y,j|
      if (i == j) and (j == 1)
        return false if list.member?([x,y])
      else
        return false unless list.member?([x,y])
      end
    end
  end
  return true
end

def run(list)
  runb(list) ? "respectable" : "ugly"
end

def convert(n)
  n.split(' ').map(&:to_i)
end

n = gets
list = []
while n != nil
  list << convert(n)
  if list.size == 8
    puts run(list)
    list = []
  end
  n = gets
end

#0 0
#2 1
#1 0
#0 2
#2 2
#1 0
#2 1
#0 2

x=[]
y=[]
8.times do
  a,b=gets.split.map(&:to_i)
  x<<a
  y<<b
end
a=x.uniq.sort
b=y.uniq.sort
if a.size!=3 or b.size!=3
  puts 'ugly'
  exit
end
p=[]
3.times do |i|
  3.times do |j|
    next if i==1 and j==1
    p << [a[i],b[j]]
  end
end
8.times do |i|
  p.delete([x[i],y[i]])
end
if p.size == 0
  puts 'respectable'
else
  puts 'ugly'
end

# http://codeforces.com/problemset/problem/334/B
list = []
list_x = []
list_y = []
8.times do |i|
  list << gets.chomp.split.map(&:to_i)
  list_x << list[i][0]
  list_y << list[i][1]
end

def eight_point_set(list, list_x, list_y)
  for i in 0..7
    for j in (i + 1)..7
      if list[j] == list[i]
        return "ugly"
      end
    end
  end

  sorted_list_x = list_x.sort
  sorted_list_y = list_y.sort
  avg_x, avg_y = 0, 0

  for i in 0..7
    avg_x += 1 if sorted_list_x[i] == sorted_list_x[3]
    avg_y += 1 if sorted_list_y[i] == sorted_list_y[3]
  end

  return avg_x == 2 && avg_y == 2 ? "respectable" : "ugly"
end

puts eight_point_set(list, list_x, list_y)

# http://codeforces.com/problemset/problem/334/B
list = []
list_x = []
list_y = []
8.times do |i|
  list << gets.chomp.split.map(&:to_i)
  list_x << list[i][0]
  list_y << list[i][1]
end

def eight_point_set(list, list_x, list_y)
  hash = Hash.new { |hash, key| hash[key] = 0 }
  for i in 0..7
    hash[list[i]] += 1

    if hash[list[i]] > 1
      return "ugly"
    end
  end

  sorted_list_x = list_x.sort
  sorted_list_y = list_y.sort
  avg_x, avg_y = 0, 0

  for i in 0..7
    avg_x += 1 if sorted_list_x[i] == sorted_list_x[3]
    avg_y += 1 if sorted_list_y[i] == sorted_list_y[3]
  end

  return avg_x == 2 && avg_y == 2 ? "respectable" : "ugly"
end

puts eight_point_set(list, list_x, list_y)

xs, ys = [], []
x_count, y_count = {}, {}
8.times do
	x, y = STDIN.readline.split.map {|s| s.to_i }
	xs.push(x)
	ys.push(y)
	x_count[x] = (x_count[x] || 0) + 1
	y_count[y] = (y_count[y] || 0) + 1
end
[x_count, y_count].each do |z_count|
	values = z_count.values.sort
	if values.length != 3
		puts 'ugly'
		exit
	end
end
input_points = xs.zip(ys).sort
x1, x2, x3 = x_count.keys.sort
y1, y2, y3 = y_count.keys.sort
constructed_points = [[x1, y1], [x1, y2], [x1, y3],
					  [x2, y1], [x2, y3],
					  [x3, y1], [x3, y2], [x3, y3]].sort
if constructed_points == input_points
	puts 'respectable'
else
	puts 'ugly'
end

xs, ys = [], []
x_count, y_count = {}, {}
8.times do
	x, y = STDIN.readline.split.map {|s| s.to_i }
	xs.push(x)
	ys.push(y)
	x_count[x] = (x_count[x] || 0) + 1
	y_count[y] = (y_count[y] || 0) + 1
end
if x_count.values.length != 3 || y_count.values.length != 3
	puts 'ugly'
	exit
end
input_points = xs.zip(ys).sort
x1, x2, x3 = x_count.keys.sort
y1, y2, y3 = y_count.keys.sort
constructed_points = [[x1, y1], [x1, y2], [x1, y3],
					  [x2, y1], [x2, y3],
					  [x3, y1], [x3, y2], [x3, y3]].sort
puts constructed_points == input_points ? 'respectable' : 'ugly'

#!/usr/bin/env ruby
point,x, y = [], [], []
8.times do
  point << gets.split(' ').map(&:to_i)
  x << point[-1][0] unless x.include? point[-1][0]
  y << point[-1][1] unless y.include? point[-1][1]
end
if x.sort!.size == 3 && y.sort!.size == 3
  ok = true
  for i in 0...3
    for j in 0...3
      next if i == 1 && j == 1
      ok = false unless point.include?([x[i], y[j]])
    end
  end
  puts ok ? "respectable" : "ugly"
else
  puts "ugly"
end

#!/usr/bin/env ruby
point,x, y = [], [], []
8.times do
  point << gets.split(' ').map(&:to_i)
  x << point[-1][0] unless x.include? point[-1][0]
  y << point[-1][1] unless y.include? point[-1][1]
end
if x.size == 3 && y.size == 3
  ok = true
  for i in 0...3
    for j in 0...3
      next if i == 1 && j == 1
      ok = false unless point.include?([x[i], y[j]])
    end
  end
  puts ok ? "respectable" : "ugly"
else
  puts "ugly"
end

#!/usr/bin/env ruby
point,x, y = [], [], []
8.times do
  point << gets.split(' ').map(&:to_i)
  x << point[-1][0] unless x.include? point[-1][0]
  y << point[-1][1] unless y.include? point[-1][1]
end
if x.size == 3 && y.size == 3
  if x.size > 1 && y.size > 1 && point.include?([x.sort[1], y.sort[1]])
    puts "ugly"
  else
    puts "respectable"
  end
else
  puts "ugly"
end

#!/usr/bin/env ruby
point,x, y = [], [], []
8.times do
  point << gets.split(' ').map(&:to_i)
  x << point[-1][0] unless x.include? point[-1][0]
  y << point[-1][1] unless y.include? point[-1][1]
end
if x.sort!.size == 3 && y.sort!.size == 3
  if point.uniq.size == point.size && point.include?([x[1], y[1]])
    puts "respectable"
  else
    puts "ugly"
  end
else
  puts "ugly"
end

points =[]
for i in 1..8
 temp=gets.chomp.split.collect{|a| a.to_i}
 points.push temp
end
xs=points.collect{|a| a.first}.uniq
ys=points.collect{|a| a.last }.uniq
#puts xs,ys
if xs.length!=3 ||ys.length!=3
   puts "ugly"
else
  avg=[xs[1],ys[1]]
 # puts avg
  if points.include? avg
     puts "ugly"
  else
      puts"respectable"
  end
end

points =[]
for i in 1..8
 temp=gets.chomp.split.collect{|a| a.to_i}
 points.push temp
end
xs=points.collect{|a| a.first}.uniq.sort
ys=points.collect{|a| a.last }.uniq.sort
#puts xs,ys
if xs.length!=3 ||ys.length!=3 || temp.uniq !=8
   puts "ugly"
else
  avg=[xs[1],ys[1]]
 # puts avg
  if points.include? avg
     puts "ugly"
  else
      puts"respectable"
  end
end

points =[]
for i in 1..8
 temp=gets.chomp.split.collect{|a| a.to_i}
 points.push temp
end
xs=points.collect{|a| a.first}.sort.uniq
ys=points.collect{|a| a.last }.sort.uniq
#puts xs,ys
if xs.length!=3 ||ys.length!=3 || points.uniq !=8
   puts "ugly"
else
  avg=[xs[1],ys[1]]
 # puts avg
  if points.include? avg
     puts "ugly"
  else
      puts"respectable"
  end
end

points =[]
for i in 1..8
 temp=gets.chomp.split.collect{|a| a.to_i}
 points.push temp
end
xs=points.collect{|a| a.first}.uniq.sort
ys=points.collect{|a| a.last }.uniq.sort
#puts xs,ys
if xs.length!=3 ||ys.length!=3
   puts "ugly"
else
  avg=[xs[1],ys[1]]
 # puts avg
  if points.include? avg
     puts "ugly"
  else
      puts"respectable"
  end
end

xy = []
8.times do
  x,y = gets.split(' ').map(&:to_i)
  xy << [x,y]
end

xs,ys = xy.transpose
xxs = xs.sort.uniq
yys = ys.sort.uniq

ok = true
xxs.each do |x|
  if xs.count(x) != 3
    ok = false
    break;
  end
end

yys.each do |y|
  if ys.count(y) != 3
    ok = false
    break;
  end
end if ok

if !ok || xxs.size != 3 || yys.size != 3 || xy.include?([xxs[1], yys[1]])
  puts "ugly"
else
  puts "respectable"
end

xy = []
8.times do
  x,y = gets.split(' ').map(&:to_i)
  xy << [x,y]
end

xs,ys = xy.transpose
xxs = xs.sort.uniq
yys = ys.sort.uniq

ok = true
xxs.each.with_index do |x,i|
  if xs.count(x) != (i == 1 ? 2 : 3)
    ok = false
    break;
  end
end

yys.each.with_index do |y,i|
  if ys.count(y) != (i == 1 ? 2 : 3)
    ok = false
    break;
  end
end if ok

if !ok || xxs.size != 3 || yys.size != 3 || xy.include?([xxs[1], yys[1]])
  puts "ugly"
else
  puts "respectable"
end

xy = []
8.times do
  x,y = gets.split(' ').map(&:to_i)
  xy << [x,y]
end

xs,ys = xy.transpose
xxs = xs.sort.uniq
yys = ys.sort.uniq

if xxs.size != 3 || yys.size != 3 || xy.include?([xxs[1], yys[1]])
  puts "ugly"
else
  puts "respectable"
end

def runb(list)
  x = list.map{|x,y| x}.uniq.sort
  y = list.map{|x,y| y}.uniq.sort

  return false unless x.size == 3
  return false unless y.size == 3
  return false if list.member?([x[1],y[1]])
  return true
end

def run(list)
  runb(list) ? "respectable" : "ugly"
end

def convert(n)
  n.split(' ').map(&:to_i)
end

n = gets
list = []
while n != nil
  list << convert(n)
  if list.size == 8
    puts run(list)
    list = []
  end
  n = gets
end

# http://codeforces.com/problemset/problem/334/B
list = []
list_x = []
list_y = []
8.times do |i|
  list << gets.chomp.split.map(&:to_i)
  list_x << list[i][0]
  list_y << list[i][1]
end

def eight_point_set(list, list_x, list_y)
  hash = Hash.new { |hash, key| hash[key] = 0 }
  for i in 0..7
    hash[list[i]] += 0

    if hash[list[i]] > 1
      return "ugly"
    end
  end

  sorted_list_x = list_x.sort
  sorted_list_y = list_y.sort
  avg_x, avg_y = 0, 0

  for i in 0..7
    avg_x += 1 if sorted_list_x[i] == sorted_list_x[3]
    avg_y += 1 if sorted_list_y[i] == sorted_list_y[3]
  end

  return avg_x == 2 && avg_y == 2 ? "respectable" : "ugly"
end

puts eight_point_set(list, list_x, list_y)

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

list_x = []
list_y = []
8.times do
  pair = gets.chomp.split
  list_x << pair[0].to_i
  list_y << pair[1].to_i
end

list_x = list_x.sort
list_y = list_y.sort

avg_x, avg_y = 0, 0

for i in 0..7
  avg_x += 1 if list_x[i] == list_x[3]
  avg_y += 1 if list_y[i] == list_y[3]
end

puts avg_x == 2 && avg_y == 2 ? "respectable" : "ugly"


str = gets.chomp
str[0] = str[0].capitalize
puts str

s = gets
puts s[0].upcase + s[1, s.length]

word = STDIN.read
puts word.sub(/\w/) {|c| c.capitalize}

s = gets.chomp
s[0] = s[0].upcase
puts s

a = gets.chomp
puts a[0].upcase + a[1..a.length]

s = gets.chop
puts s[0].upcase + s[1..s.size-1]

s = gets.chomp
print s[0].capitalize + s[1..-1]

str = gets.chomp
str1 = str[0]

print str1.capitalize
puts str[1..str.length]

str = gets.chomp
print str[0].capitalize , str[1..str.length]

s = gets
puts s[0].upcase + s[1...s.size]

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

word = gets.chomp
puts "#{word[0].upcase}#{word[1..(word.length - 1)]}"

input = gets.chomp
l = input.length
sov = Array.new
sov[0] = input[0].upcase
for i in 1...l
    sov.push(input[i])
end
print sov.join

word = gets.chomp.to_s
letters = word.split("")
print letters[0].capitalize
letters[0] = nil
letters.each do |letter|
	print letter
end

n = gets.split('')

n[0].upcase!

puts n.join('')

str = gets ; str[0] = str[0].to_s.upcase ; puts str

s = gets.strip
s = s[0].capitalize + s[1..s.length]
puts s

word = gets.chomp
word[0] = word[0].upcase
puts word

word = String(gets.chomp)
if word[0] == word[0].upcase
  puts word
else
  puts word[0].upcase + word[1...word.length]
end

s = gets.chomp
puts s[0].upcase + s[1..-1]

s = gets.chomp
s[0] = s[0].upcase
puts s

input_word = gets.chomp
input_word[0]=input_word[0].upcase
print input_word

str = gets
a = str[0].upcase
str[0]=a
puts str

str = gets.chomp
first = str[0,1]
first.upcase!
newstr = first + str[1,(str.length-1)]
puts newstr

x=gets.strip.chars.to_a; x[0]=x[0].upcase; puts x.join

a = gets.chomp.to_s
b = a[1..-1].scan(/[A-Z]/).length
c = a[0]
d = []
if c.capitalize == c && b >= 1
puts a
else
a[0] = a[0].upcase
puts a
end

s = gets.chomp.split("")
if s[0] == s[0].upcase
	puts s.join
else
	s0 = s[0].upcase
	s.delete_at(0)
	puts s0 << s.join
end

input =gets
input[0]=input[0].upcase
print input

cad = gets.chomp

cad[0] = cad[0].upcase

puts cad

a=gets.chomp
a=a[0].upcase+a[1..a.length-1]
puts  "#{a}"

n = gets.chomp
m = []
m = n.split("")
print m[0].capitalize
for i in m.drop(1) do
        print i
end

a = gets.chomp
b = a[0]
b = b.upcase
a[0] = b[0]
puts a

line = gets.chomp

line[0] = line[0].upcase
puts line

String word = gets.chomp
word[0]=word[0].capitalize
puts word

word = gets.chomp
first = word.split(//).first.upcase
word[0] = first
puts word

s = gets[0..-2]
code = s[0].ord
code -= 32 if code > "Z".ord
s[0] = code.chr
print s

#!/usr/bin/env ruby

gets.split.collect{|i| puts "#{i[0].upcase}#{i[1..-1]}"}

input = gets.strip

input[0] = input[0].upcase
puts input

string = gets
string[0] = string[0].capitalize
puts string

s = gets.chomp; s[0] = s[0].upcase; puts s

s = gets.chomp
s[0] = s[0].upcase
puts s

string = gets.chomp.split('')
string[0].upcase!

string.each do |item|
	print item
end

arr = gets.chomp.split("")
first_letter = arr.first.upcase
puts [first_letter, arr[1..-1]].flatten.join

a = gets.chomp
print a[0].upcase
print a[1..-1]

s = gets.chomp
s[0] = s[0].capitalize
puts s

str = gets.to_s.strip

def newlife(word)
	first_char = word[0]
	first_char.upcase!
	word[0] = first_char
	word
end

puts newlife(str)

input = gets.chomp

print input.slice!(0).capitalize, input

s = gets
puts s[0].capitalize + s[1..-1]

s = gets.strip
if s[0].ord >= 'a'.ord && s[0].ord <= 'z'.ord then
  s[0] = (s[0].ord - 32).chr
end
puts s

word = gets.chomp
puts word[0].upcase + word[1..-1]

def xenia()
  word = gets.chomp
  letter = word[0]
  letter.upcase!
  print "#{letter}#{word[1..-1]}"
end

xenia

a = gets.chomp
a[0] = a[0].upcase
puts a

#!/usr/bin/ruby1.9

word = STDIN.readline.strip
puts word[0].upcase+word[1..-1]

A = gets.chomp
A[0] = A[0].upcase
puts A

s = gets.chomp
f = s[0].capitalize
puts f + s[1..-1]

a = gets.chomp
b = a.capitalize
puts b[0] + a[1..-1]

str = gets.chomp
puts str[0].upcase + str[1..10**3]

def run(input = STDIN.read)
  line = input.strip
  line[0] = line[0].capitalize
  puts line
end
run

src = gets
src[0] = src[0].upcase
puts src

str = gets.chomp()
str[0] = str[0].upcase
puts str

t = $stdin.readline
tt = t.scan(/./)
tt[0] = t[0].capitalize
puts tt.join('')

s = gets.to_s
puts s[0].upcase + s[1..-1]

x = gets.chomp;
x[0]= x[0].upcase;
puts x;

def run
  line = $stdin.readline.split(//)
  line[0].upcase!
  puts line.join("")
end

run if $0 == __FILE__

inp = gets.chomp
inp = inp.sub(/^./) { |ch| ch.upcase }
puts inp

str = $stdin.gets

str[0] = str[0].upcase! if str[0].upcase!
puts str

w = gets.chomp

puts w[0].upcase + w[1..-1]

s = gets

s[0] = s[0].capitalize;

puts s

test = gets
test[0] = test[0].capitalize
puts test

a = gets.chomp()
puts a[0].upcase << a[1..-1]

s = gets.chomp
puts s[0].capitalize + s[1..-1]

s = gets.strip
t = ""
s.length.times do |i|
    if i == 0
        t += s[i].upcase
    else
        t += s[i]
    end
end
puts t

x = gets.chomp
puts "#{x[0].capitalize + x[1..-1]}"

#STDOUT.flush
#str = gets.chomp
#str_aux = "AEIOUYaeiouy"
#str.each_char { |out|
#	if !str_aux.include? out.to_s
#		print "."
#		print out.downcase
#	end
#}
#puts "\n"

STDOUT.flush
str = gets.chomp
print str[0].upcase
puts str[1..str.size()]

require 'set'
include Math
$stdin = File.open("./input.txt", "r") if ENV["USER"] == "new"
# ====================================

line = gets.strip
line[0] = line[0].upcase
puts line

s = gets.chomp.split(//)
s[0] = s[0].capitalize
puts s

#!/usr/bin/ruby1.9

word = STDIN.readline.strip.capitalize
puts word

def run(input = STDIN.read)
  line = input.strip
  puts line.capitalize
end
run

inp = gets.chomp
inp.sub(/^./) { |ch| ch.upcase }
puts inp

test = gets.chomp
final = test.capitalize
puts final

a = gets.chomp()
puts a[0].upcase!.to_s << a[1..-1]

a = gets.chomp()
b = a[0].upcase!.to_s
puts b << a[1..-1]

word = gets.chomp
word[0].upcase!
puts word

input_word = gets.chomp
print input_word[0].upcase

a = gets.chomp.to_s
b = a[1..-1].scan(/[A-Z]/).length
c = a[0]
if c.upcase == c && b >= 1
puts a
else
c.upcase!
puts a
end

a = gets.chomp.to_s
b = a[1..-1].scan(/[A-Z]/).length
c = a[0]
if c.upcase == c && b >= 1
puts a
else
puts a.capitalize
end

a = gets.chomp.to_s
b = a[1..-1].scan(/[A-Z]/).length
c = a[0]
if c.capitalize == c && b >= 1
puts a
else
puts a.capitalize
end

a = gets.chomp.to_s
b = a[1..-1].scan(/[A-Z]/).length
c = a[0]
if c.capitalize == c && b >= 1
puts a
else
puts a.capitalize!
end

String word = gets.chomp
word[0].capitalize!
puts word

String word = gets.chomp
word.capitalize!
puts word


#!/usr/bin/ruby
hash = {'9' => '0', '8' => '1','7' => '2','6' => '3','5' => '4'}
input_line = gets
res = ''
input_line.each_char do |ch|
    if hash[ch].nil?
        res+=ch;
    else
        if (ch == '9' && res == '')
            res+=ch
        else
            res+=hash[ch]
        end
    end
end

puts res

# coding: utf-8

# if __FILE__ == $0
# end

digits = gets.chomp.split(//).map { |i|
    i = i.to_i
    inverted = 9 - i
    if inverted < i
        inverted
    else
        i
    end
}

# remind leading zero!
if digits[0] == 0
    digits[0] = 9
end

puts digits.join

number = gets.chomp
digits = number.split("")

if digits[0].to_i >= 5 && digits[0].to_i != 9
	digits[0] = 9 - digits[0].to_i
end
if digits[digits.size - 1].to_i >= 5 && digits.size > 1
	digits[digits.size - 1] = 9 - digits[digits.size - 1].to_i
end
if digits.size == 2
	print digits[0].to_i
	print digits[1].to_i
elsif digits.size == 1
	print digits[0].to_i
else
	for i in (1..digits.size-2)
		if digits[i].to_i >= 5
			digits[i] = 9 - digits[i].to_i
		end
	end
	for i in (0..digits.size-1)
		print digits[i].to_i
	end
end

digits = gets.chomp.chars.map(&:to_i)
print digits.shift if digits[0] == 9
puts digits.map{|d| [d,9-d].min}.join

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

initial_num = ARGF.read

result = ''

initial_num.chars.each_with_index do |c, index|
	i = c.to_i
	if i >= 5
		if i == 9 and index == 0
			result << c
		else
			result << (9-i).to_s
		end
	else
		result << c
	end
end

puts result

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

digits = gets.chomp.chars.map(&:to_i)
inverted = digits.map.with_index do |n, idx|
  case idx
  when 0
    (9 - n) < n && n != 9 ? 9 - n : n
  else
    (9 - n) < n ? 9 - n : n
  end
end

puts inverted.join.to_i

s = gets.chomp.to_s
k = s[0]
for i in 0..s.length - 1
  if s[i].to_i>=5
      s[i] = (9 - s[i].to_i).to_s
  end
end
if s[0] == "0"
    s[0] = k
end
puts s

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

s = gets.chomp.to_s
(s.length).times{|i|
  if s[i].to_i >= 5
    if i == 0 and s[i].to_i == 9
      next
    end
    s[i] = (9 - s[i].to_i).to_s
  end
}
puts s

a = gets.strip.chars.each_with_index.map do |ci,i|
  d = ci.ord - '0'.ord
  if i == 0 && d == 9
    d
  elsif d >= 5
    9-d
  else
    d
  end
end
puts a.join

arr = gets.chomp.split("")
arr.each_with_index do |item, index|
  print item.to_i <= 4 ? item : index.to_i == 0 && item.to_i == 9 ? item : 9 - item.to_i
end

x = gets.chomp.chars.map(&:to_i)

tmp = x[0]
x = x[1..-1]

tmp = 9 - tmp if tmp > 4 and tmp < 9

x = x.map { |i|
  if i > 4
    9 - i
  else
    i
  end }

puts ([tmp] + x).join("")

str=gets.to_s
str.chomp!

for i in 0..str.length-1
  x=str[i].to_i
  y=9-x
  if x>y
    str[i]=y.to_s
  else
    str[i]=x.to_s
  end
end

if str[0]=="0"
  str[0]="9"
end

puts str

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

res = gets.chomp.chars.map(&:to_i).
         map{|x| [x, 9 -x].min}.map(&:to_s).join('')

res[0] = '9' if res[0] == '0'
puts res

s=gets.chomp
x=s.chars
t=x.shift

p1="8765".index(t)
if p1!=nil then
	t=[1,2,3,4][p1]
else
	t=t.to_i
end
ans=t
x.map{|e|
	ans*=10
	p2="98765".index(e)
	if p2==nil then
		ans=ans+e.to_i
	else
		ans=ans+[0,1,2,3,4][p2]
	end
}
puts ans

s = gets.chomp
if s[0] == '9'
	print '9'
else
	print [s[0].to_i,9-s[0].to_i].min
end
1.upto(s.length - 1) do |i|
	print [s[i].to_i , 9-s[i].to_i].min
end

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

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

puts gets.chomp.chars.map(&:to_i).
         map{|x| [x, 9 -x].min}.map(&:to_s).join('')

s=gets.chomp
x=s.chars
t=x.shift

p1="8765".index(t)
if p1!=nil then
	t=[1,2,3,4][p1]
	p t
else
	t=t.to_i
end
ans=t
x.map{|e|
	ans*=10
	p2="98765".index(e)
	if p2==nil then
		ans=ans+e.to_i
	else
		ans=ans+[0,1,2,3,4][p2]
	end
}
puts ans

s = gets.chomp
if s[0] == '9'
	print '9'
else
	print [s[0].to_i,9-s[0].to_i].min
end
1.upto(s.length - 1) do |i|
	print [s[0].to_i , 9-s[0].to_i].min
end

# coding: utf-8

# if __FILE__ == $0
# end

digits = gets.chomp.split(//).map { |i|
    i = i.to_i
    inverted = 9 - i
    if inverted < i
        inverted
    else
        i
    end
}

puts digits.join

number = gets.chomp
digits = number.split("")

if digits[0].to_i >= 5 && digits[0].to_i != 9
	digits[0] = 9 - digits[0].to_i
end
if digits[digits.size - 1].to_i >= 5
	digits[digits.size - 1] = 9 - digits[digits.size - 1].to_i
end
if digits.size == 2
	print digits[0].to_i
	print digits[1].to_i
elsif digits.size == 1
	print digits[0].to_i
else
	for i in (1..digits.size-2)
		if digits[i].to_i >= 5
			digits[i] = 9 - digits[i].to_i
		end
	end
	for i in (0..digits.size-1)
		print digits[i].to_i
	end
end

number = gets.chomp
digits = number.split("")

if digits[0].to_i >= 5 && digits[0].to_i != 9
	digits[0] = 9 - digits[0].to_i
end
if digits[digits.size - 1].to_i >= 5 && digits[digits.size - 1].to_i != 9
	digits[digits.size - 1] = 9 - digits[digits.size - 1].to_i
end
if digits.size == 2
	print digits[0].to_i
	print digits[1].to_i
elsif digits.size == 1
	print digits[0].to_i
else
	for i in (1..digits.size-2)
		if digits[i].to_i >= 5 && digits[i].to_i != 9
			digits[i] = 9 - digits[i].to_i
		end
	end
	for i in (0..digits.size-1)
		print digits[i].to_i
	end
end

number = gets.chomp
digits = number.split("")

if digits[0].to_i >= 5
	digits[0] = 9 - digits[0].to_i
end
if digits[digits.size - 1].to_i >= 5
	digits[digits.size - 1] = 9 - digits[digits.size - 1].to_i
end
if digits.size == 2
	print digits[0].to_i
	print digits[1].to_i
elsif digits.size == 1
	print digits[0].to_i
else
	for i in (1..digits.size-2)
		if digits[i].to_i >= 5
			digits[i] = 9 - digits[i].to_i
		end
	end
	for i in (0..digits.size-1)
		print digits[i].to_i
	end
end

number = gets.chomp
digits = number.split("")

if digits[0].to_i >= 5 && digits[0].to_i != 9
	puts "asdf"
	digits[0] = 9 - digits[0].to_i
end
if digits[digits.size - 1].to_i >= 5 && digits.size > 1
	digits[digits.size - 1] = 9 - digits[digits.size - 1].to_i
end
if digits.size == 2
	print digits[0].to_i
	print digits[1].to_i
elsif digits.size == 1
	print digits[0].to_i
else
	for i in (1..digits.size-2)
		if digits[i].to_i >= 5
			digits[i] = 9 - digits[i].to_i
		end
	end
	for i in (0..digits.size-1)
		print digits[i].to_i
	end
end

ans = gets.chomp.chars.map(&:to_i).map{|d| [d,9-d].min}.join.to_i
puts ans==0 ? 9 : ans

initial_num = ARGF.read

result = ''

initial_num.chars.each_with_index do |c, index|
    i = c.to_i
    if i >= 5
        result << (9-i).to_s unless i == 9 and index == 0
    else
        result << c
    end
end

puts result

c = gets.strip
if c == '9'
  puts 0
else
  a = c.chars.each_with_index.map do |ci,i|
    d = ci.ord - '0'.ord
    if i == 0 && d == 9
      d
    elsif d >= 5
      9-d
    else
      d
    end
  end
  puts a.join
end

x = gets.chomp.chars.map(&:to_i)

tmp = x[0]
x = x[1..-1]

tmp = 9 - tmp if tmp > 4 and tmp < 9

x = x.map { |i| 9 - i if i > 4 }

puts ([tmp] + x).join("")

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

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

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

puts digits.join.to_i

arr = gets.chomp.split("")
arr.each do |x| print x.to_i <= 4 ? x : arr[0] == '9' ? arr[0] :
  9 - x.to_i
end

n = gets.to_i
ans = ""
while n > 0 do
  dig = n % 10
  if 9 - dig < dig && 9 - dig != 0
    ans << (9 - dig).to_s
  else
    ans << dig.to_s
  end
  n /= 10
end
puts ans

n = gets.to_i
ans = ""
while n > 0 do
  dig = n % 10
  if 9 - dig < dig
    ans << (9 - dig).to_s
  else
    ans << dig.to_s
  end
  n /= 10
end
puts ans

arr = gets.chomp.split("")
arr.each do |x| print x.to_i <= 4 ? x : arr.size == 1 && arr[0] == '9' ? arr[0] :
  9 - x.to_i
end


a = Array.new(123, gets.split[1].to_i)
gets.chars{|c| a[c.ord] -= 1}
puts a.min < 0 ? :NO : :YES

n,k=gets.split.map &:to_i
h=Hash.new 0
gets.chomp.chars{|c|h[c]+=1}
puts h.values.any?{|e|e>k} ? :NO : :YES

n, k = gets.strip.split.map(&:to_i)
s = gets.strip
ans = "YES"
count = Array.new(26, 0)
n.times do |i|
    count[s[i].ord - 'a'.ord] += 1
end
max_count = count.max
ans = "NO" if max_count > k
puts ans

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

hs=Hash.new(0)
gets.chomp.chars.each{|e|
	hs[e]+=1
}

v=hs.values.sort.pop

if v<=f then
	puts "YES"
else
	puts "NO"
end

n,k=gets.split.map(&:to_i)
s = gets.chomp
h = Hash.new(0)
s.chars do |c|
    h[c] += 1
end

f = true
[*?a..?z].each do |c|
    if h[c] == 0
        next
    elsif (h[c] - 1) / k > 0
        f = false
        break
    end
end
puts f ? "YES" : "NO"

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

h=Hash.new(0)
s.each{|c| h[c]+=1}
ok=true
h.each_value do |v|
  ok&=v<=k
end

puts ok ? 'YES' : 'NO'

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

hs=Hash.new(0)
gets.chomp.chars.each{|e|
	hs[e]+=1
}

vs=hs.values
sum=0
while vs.size >1
	d=vs.shift
	vs=vs.map{|e|
		if d>=e then
			d-=e
			f-=e
			0
		else
			f-=d
			t=e-d
			d=0
			t
		end
	}.select{|e| e>0}
	vs.push(d) if d>0
end
if f<=0 then
	puts "YES"
else
	puts "NO"
end

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

hs=Hash.new(0)
gets.chomp.chars.each{|e|
	hs[e]+=1
}

vs=hs.values
sum=0
while vs.size >1
	d=vs.shift
	vs=vs.map{|e|
		if d>=e then
			d-=e
			f-=e
			0
		else
			f-=d
			t=e-d
			d=0
			t
		end
	}.select{|e| e>0}
	vs.push(d) if d>0
end
if vs.empty? && f>=0 then
	puts "YES"
else
	puts "NO"
end

n,f=gets.split.map{|e| e.to_i}
hs=Hash.new(0)
gets.chomp.chars.each{|e|
	hs[e]+=1
}
hs.each{|k,v|
	f-=(v/2).to_i
}
if f<=0 then
	puts "YES"
else
	puts "NO"
end

n,k=gets.split.map(&:to_i)
s = gets.chomp
h = Hash.new(0)
s.chars do |c|
    h[c] += 1
end

f = true
[*?a..?z].each do |c|
    if h[c] % 2 == 1
        f = false
        break
    end
end
puts f ? "YES" : "NO"

a = Array.new(123, gets.split[1].to_i)
gets.chars{|c| a[c.ord] -= 1}
p a.min < 0 ? 'NO' : 'YES'


# Input
n = gets.to_i # 2 <= n <= 100
a = gets.split(" ").map! { |b| b.to_i } # 1 <= b <= 100

# Processing
a.sort!
pairs = Array.new(n / 2) { |i| [a[2 * i], a[2 * i + 1]] }
sum = pairs.inject(0) { |mem, p| mem + (p[1] - p[0]) }

# Output
puts sum

class Main
  #def get_problem_link
  #  problem_link = "https://codeforces.com/problemset/problem/1092/B"
  #  return problem_link
  #end

  #def get_submission_link
  #  submission_link = ''
  #  return submisson_link
  #end

  #begin
  #of codeforces interface
  def run_interface
    n = gets.to_i
    k = gets.split(' ').map(&:to_i)
    puts solution(n, k)
  end
  #end
  #of codeforces interface

  def solution(n, students_array)
      res = 0
      students_array.sort!
      (0...students_array.length).step(2).each do |i|
          res = res + (students_array[i+1]-students_array[i]);
      end
      return res
  end

end

#then upload to codeforces uncomment this line:
Main.new.run_interface

n = gets.to_i
a = gets.split.map(&:to_i)
a.sort!
ans = 0
(n/2).times do |i|
  ans += a[2*i+1] - a[2*i]
end
p ans

def solution
  count = read_int
  ss = read_ints.sort
  p ss.each_slice(2).map{ |a, b| b - a }.reduce(0, :+)
end

def read_int
  gets.to_i
end

def read_ints
  gets.split.map(&:to_i)
end

def read_string
  gets.chomp
end

solution unless ENV['TEST__MODE']

n = gets.to_i
as = gets.split.map(&:to_i).sort
ans = 0
(0..(n/2-1)).each do |i|
  ans += (as[2*i] - as[2*i+1]).abs
end
puts ans

n = gets.to_i
arr = gets.split.map(&:to_i).sort
res = 0
arr.each_slice(2) do |slice|
  res += slice[1] - slice[0]
end
puts res

n = gets.to_i
a = gets.split.map(&:to_i).sort
ans = 0
(n/2).times do |i|
    ans += a[i*2+1]-a[i*2]
end
puts ans

# coding: utf-8

# if __FILE == $0
# end

n = gets.to_i
skills = gets.split.map { |i| i.to_i }
deltas = 0
skills.sort.each_slice(2) { |a| deltas += a[1] - a[0] }
puts deltas

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

def solution(n, a)
  skills = {}
  (0..(n - 1)).each do |i|
    skills[a[i]] = skills.fetch(a[i], 0) + 1
  end

  h = nil

  problems = 0
  100.times do |x|
    i = 100 - x

    next       if !skills.key?(i)
    next       if skills[i] % 2 == 0
    next h = i if h.nil?

    problems += h - i

    h = nil
  end
  return problems
end

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

puts solution(n, a)

n = gets.to_i
a = gets.split.map(&:to_i).sort
i, s = 0, 0
while i < a.size
    s += a[i + 1] - a[i]
    i += 2
end
puts s


#!/usr/bin/ruby
n=gets.chomp
p [n,*(1...n.size).map{|i|
	(n[0,i].to_i-1).to_s+'9'*(n.size-i)
}].max_by{|e|[e.chars.map(&:to_i).reduce(:+),e.to_i]}.to_i

def sum(x)
    x.split('').map(&:to_i).inject(0) { |sum, x| sum + x }
end

x = gets.to_i

sx = x.to_s

ans = x
sans = sx

sx.length.times do |i|
    sy = sx[0...i] + (sx[i].to_i - 1).to_s + '9' * (sx.length - i - 1)

    y = sy.to_i
    sy = y.to_s

    if (sum(sy) > sum(sans) || (sum(sy) == sum(sans) && y > ans))
        ans = y
        sans = sy
    end
end

puts sans

#!/usr/bin/ruby
n=gets.chomp
puts [n,*(1...n.size).map{|i|
	(n[0,i].to_i-1).to_s+'9'*(n.size-i)
}].max_by{|e|[e.chars.map(&:to_i).reduce(:+),e.to_i]}

#!/usr/bin/ruby
n=gets.to_i
r=0
d=1
while r<=n
	r=r*10+9
	d*=10
end
d/=10
r-=d while r>n
p [n,r].max_by{|e|[e.to_s.chars.map(&:to_i).reduce(:+),e]}

#!/usr/bin/ruby
n=gets.chomp
puts [n,*(1...n.size).map{|i|
	(n[0,i].to_i-1).to_s+'9'*(n.size-i)
}].max_by{|e|[e.chars.map(&:to_i).reduce(:+),e.to_i,e]}