# include <stdio.h>

void part( int [], int ,int ); 
int n;
int main(){
  int i;
  scanf("%d" , &n);
  int input[n];

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

  
  return 0;
}

void part (int a[] ,int p ,int r){
  int x = a[r] ,t ,k;
  int j, i = p-1;
  for ( j = p ; j < r ; j++ ){
    if ( a[j]  <= x){
      i++;
      t = a[i]; a[i] = a[j]; a[j] =t;
    }
  }
  t = a[i+1]; a[i+1] = a[r] ; a[r]=t;

  
  for ( k = 0; k <= i; k++ ){
    printf("%d " ,a[k]);
  }printf("[%d] " , x);k++;
  for (; k < n; k++ ){
    printf("%d" ,a[k]);
    if( k != i-1){printf(" ");}
  }
  printf("\n");
}

