#include <stdio.h>
#define N 100000

int main(){
  int A[N], i, j, num;
  int x, p, temp;
  
  scanf("%d", &num);

  for(i = 0 ; i < num; i++){
    scanf("%d", &A[i]);
  }

  x = A[num-1];
  i = -1;
  
  for(j = 0; j < num-1; j++){
    if(A[j] <= x){
      i = i+1;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
    }
  }
  
  temp = A[i+1];
  A[i+1] = A[num-1];
  A[num-1] = temp;

  for(i = 0; i < num-1; i++){
    if(A[i] == x){
      printf("[%d] ", A[i]);
    }
    else{
      printf("%d ", A[i]);
    }
  }
  printf("%d\n", A[i]);
  
  return 0;
}

