#include<stdio.h>

#define N 100000

int partition(void);
void swap(int*,int*);

int n,A[N];

int main(){
  int i, r;
  
  scanf("%d", &n);
  for(i = 0; i < n; i++) scanf("%d", &A[i]);
  
  r = partition();
  
  for(i = 0; i < n; i++){
    if( i != 0 ){
      printf(" ");
    }
    if(r==i) printf("[%d]" ,A[i]);
    else printf("%d",A[i]);
  }
  printf("\n");
  
  return 0;
}
int partition(void){
  int i, j, p, r;
  
  r = A[n - 1];
  i = -1;
  
  for(j = 0; j < n - 1; j++){
    if(A[j] <= r){
      i++;
      swap(&A[i], &A[j]);
    }
  }
  
  swap(&A[i+1], &A[n-1]);
  
  return i + 1;
}

void swap(int *x, int *y){
  int tmp;
  
  tmp = *x;
  *x = *y;
  *y = tmp;
  return ;
}