import scala.io.StdIn.{readInt,readLine}

object Main {

  def exchange(a:Array[Int],i:Int,j:Int) = {
    val temp = a(i)
    a(i) = a(j)
    a(j) = temp
  }

  def partition(a:Array[Int],p:Int,r:Int) = {
    val x = a(r)
    var i = (p-1)
    for(j<-p until r) {
      if(a(j) <= x) {
        i+=1
        exchange(a,i,j)
      }
    }
    exchange(a,i+1,r)
    i+1
  }

  def main(args:Array[String]) = {
    val n = readInt
    val a = readLine.split(" ").map(_.toInt)
    val pivot = partition(a,0,n-1)
    val list = a.zipWithIndex.map{ e =>
      if(e._2==pivot) "["+e._1.toString + "]" else e._1.toString
    }.mkString(" ")
    println(list)
  }
}