#include <stdio.h>
#define N 100000
int Partition(int * ,int ,int );
int A[N];
 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,z;
 
  scanf("%d",&n);
 
  for(i = 0 ; i < n ; i++ ){
    scanf("%d",&A[i]);
  }
 
   z = Partition(A,0,n-1);
 
  for(i = 0 ; i < n ; i++ ){
    if(i != 0) printf(" ");
    if(i == z) printf("[%d]",A[i]);
    else printf("%d",A[i]);
  }
 
  printf("\n");
 
  return 0;
   
}
 