#include <stdio.h>
#include <stdlib.h>
#define N 100000
  
int Partition(int [], int, int);
 
int main(void){
  int n,i,A[N],q;
 
  scanf("%d",&n);
  for(i = 1; i < n+1; i++){
    scanf("%d",&A[i]);
  }
 
  q = 1+Partition(A,1,n);
 
  for(i = 1; i < n; i++){
    if(i == q){
      printf("[%d] ",A[i]);
    }else{
      printf("%d ",A[i]);
    }
  }
   
  printf("%d\n",A[i]);
 
  return 0;
}
 
int Partition(int A[], int b, int c){
  int x,i,k,tmp;
 
  i=b-1;


  x = A[c];
  
 
  for(k = b; k <= c-1; k++){
    if(A[k] <=  x){
      i =  i + 1;
      tmp = A[i];
      A[i] = A[k];
      A[k] = tmp;
    }
  }
  tmp = A[i+1];
  A[i+1] = A[c];
  A[c] = tmp;
 
  return i; 
}