#include<stdio.h>

int main(){
  int A[100000];
  int i,j,tmp,n,r,x,p;

  
scanf("%d", &n);
 for(i=0;i<n;i++){
   scanf("%d",&A[i]);
 }
 r=n-1;
 p=0;
 
 x = A[r];
 i = p-1;

 for(j=p;j <= r; j++){
   if(A[j] <= x){
     i=i+1;
     tmp = A[i];
     A[i] = A[j];
     A[j] = tmp;
    
   }
   
   tmp=A[i+1];
   A[i+1] = A[r];
   A[r]=tmp;
   
 }

 for(i=0;i<n;i++){
   printf("%d ",A[i]);
 }
 printf("\n");
 //printf("%d\n",i+1);
 
}

