#include<stdio.h>
#define MAX 1000000
int Partition(int *,int,int);

int A[MAX],key;
main(){
  int n,i;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
    
  }
  
  key = Partition(A,0,n);
  
  
  for(i = 1; i < key; i++){ 
    printf("%d ",A[i]);
  }
  printf("[%d] ",A[key]);
  for(i = key+1;i<=n;i++){
    if(i == n){
      printf("%d\n",A[n]);
    }else{
      printf("%d ",A[i]);
    }
  }
  
  return 0;
}

int Partition(int *A,int p,int r){  
  int i,j,x,tmp;
  x = A[r];
  i = p-1;
  for(j = p; j < r; j++){
    if(A[j] <= x){
      i++;
      
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[r];
  A[r] = A[i+1];
  A[i+1] = tmp;
  
  
  return i+1;
  
}