def partition(arr,p,r)
  x=arr[r]
  i= p - 1
  #puts arr
  for j in p..r-1
    if(arr[j] <= x)
      i+=1
      arr[i],arr[j]=arr[j],arr[i]
    end
  end
  arr[i+1],arr[r]=arr[r],arr[i+1]
  @num=i+1
end
n=gets.to_i
arr=gets.split.map(&:to_i)
partition(arr,0,n-1)
0.upto(n-2) do |i|
  if i!=@num
    print "#{arr[i]} "
  else
    print "[#{arr[i]}] "
  end
end
puts "#{arr[n-1]}"