#include<stdio.h>

#define N 100000

int main(){
  int loop,last,temp,point,init;
  int i,j;
  int Part[N];

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

  last=Part[loop-1];
  init=-1;

  for(j=0;j<loop-1;j++){
    
    if(last>=Part[j]){
      init+=1;
      temp=Part[init];
      Part[init]=Part[j];
      Part[j]=temp;
    }
    
  }

  temp=Part[init+1];
  Part[init+1]=Part[loop-1];
  Part[loop-1]=temp;
  
  point=init+1;

  for(i=0;i<point;i++){
    printf("%d ",Part[i]);
  }

  printf("[%d] ",Part[point]);

  for(i=point+1;i<loop-1;i++){
    printf("%d ",Part[i]);
  }

  printf("%d\n",Part[loop-1]);
  
  return 0;
}

