#include <stdio.h>
int Partition(int * ,int ,int );
int A[100000];
 int Partition(int *A, int p,int r){
  int x,i,h,j;
  
  x = A[r];
  i = p - 1;
  for(j = p ; j <= r - 1; j++){
    if(A[j] <= x){
      i = i + 1;
    h = A[i];
    A[i] = A[j];
    A[j] = h;
    }
  }
  h = A[i + 1];
  A[i + 1] = A[r];
  A[r] = h;
  
  return i + 1;
}
main(){
  
  int i,n,a;
  
  scanf("%d",&n);
 n=n-1;
  for(i = 0 ; i <=n ; i++ ){
    scanf("%d",&A[i]);
  }
  
   a = Partition(A,0,n);
  
  for(i = 0 ; i <=n ; i++ ){
    if(i != 0) printf(" ");
    if(i == a) printf("[%d]",A[i]);
    else printf("%d",A[i]);
  }
  
  printf("\n");
  
  return 0;
    
}