#include<stdio.h>

int main(){
  //counter
  int i,j;

  //input
  int n;
  scanf("%100000d",&n);

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

  //PartitionSort

  int p = 0;
  int r = n-1;
  int x = A[r];
  int temp;

  i = p-1;

  for(j=p;j<=(r-1);j++){
    if(A[j]<=x){
      i++;
      //exchange A[i] and A[j]
      temp = A[i]; A[i] = A[j]; A[j] = temp;
    }
  }
  //exchange A[i+1] and A[r]
  temp = A[r]; A[r] = A[i+1]; A[i+1] = temp;

  
  
      
      

  


  //Output

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

  
  return 0;
}

