#include <stdio.h>
int main(){
  int i,j,k,num,change,array[100000];

  scanf("%d",&num);
  for(i=0;i<num;i++) scanf("%d",&array[i]);
  i=-1;
  for(j=0;j<num-1;j++){
    if(array[j]<=array[num-1]){
      i++;
      change=array[i];  /*exchange array[i] array[j]*/
      array[i]=array[j];
      array[j]=change;
    }
  }
  change=array[i+1];   /*exchange array[i+1] array's last num*/
  array[i+1]=array[num-1];
  array[num-1]=change;
  k=i+1;
  for(i=0;i<num;i++){
    if(i>0) printf(" ");
    if(i==k)printf("[");
    printf("%d",array[i]);
    if(i==k)printf("]");
  }
  printf("\n");
  return 0;
}

