def swap!(c, b)
  raise ArgumentError unless c.between?(0, self.count-1) && b.between?(0, self.count-1)

  self[c], self[b] = self[b], self[c]

  self
end

def swap(c, b)
  self.dup.swap!(c, b)
end
n = gets.chomp.map(&:to_i)
a = gets.chomp.split(' ').map(&:to_i)
n -=2
for 1..n |i|
    if a[i-1] > a[i] || a[i] > a[i+1]
      a.swap(i,i+1)
    
    elsif a[i-1] < a[i] || a[i] > a[i+1]
      a.swap(i,i+1)
    end
end

puts a