#include<stdio.h>
#define N 100001

int n,A[N];

int Patition(int , int);

main(){

  int i,index;

  scanf("%d",&n);

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

  index = Partition(0, n-1);
  
 for(i = 0; i < n; i++){
   if(i == index){
     printf("[%d] ",A[i]);
   } else if(i == n-1){
     printf("%d\n",A[i]);
   } else {
     printf("%d ",A[i]);
   }
 }
   return 0;
  
}

int Partition(int p, int num){

  int x,i,j,temp;

   x = A[num];
   i = p - 1;
 
  for(j = 0; j < num; j++){

     if(A[j] <= x){
       i = i + 1;
       temp = A[j];
       A[j] = A[i];
       A[i] = temp;
     }
 
  }

  temp =  A[num];
  A[num] =  A[i+1];
  A[i+1] =  temp;

  //  printf("%d\n",i+1);

  return i+1;

}