#include <stdio.h>

int main(void){
  int i,j,x,p,r,temp1,temp2,n,q;
  int A[100001];

  scanf("%d",&n);
  p = 0;
  r = n-1;
  for(i = p ; i <= r ; i++){
    scanf("%d",&A[i]);
  }
  x = A[r];
  i = p-1;

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