n=gets.to_i
a=gets.split(' ').map(&:to_i)
def par(a)
  x = a[-1]
  i = -1
  for j in 0..a.size-2
    if a[j] <= x
      i += 1
      a[j],a[i] = a[i],a[j]
    end
  end
  a[i+1], a[-1] = [a[-1]], a[i+1]
end
par(a)
ans = ""
count = 0
a.each do |i|
  count += 1
  ans += "#{i}"
  if count != a.size
    ans += " "
  end
end
puts ans