#include<stdio.h>

int main(){

  int A[100000],n,i,j,r,p,q,x,stac;
  
 scanf("%d",&n);
 for(i=1;i<=n;i++){
   scanf("%d",&A[i]);
 }
 q=A[n];
 p=1;
 r=n;
 x=A[r];
 i=p-1;
 for(j=p;j<=r-1;j++){
   if(A[j]<=x){
     i=i+1;
   stac=A[i];
   A[i]=A[j];
   A[j]=stac;
   }
 }
 stac=A[i+1];
 A[i+1]=A[r];
 A[r]=stac;
 
 for(i=1;i<=n;i++){
   if(i>1){
     printf(" ");
   }
   if(q==A[i])
     printf("[%d]",A[i]);
   else
   printf("%d",A[i]);
 }
 
 return 0;
}