#include<stdio.h>
 
int A[2000000];
int i,p=1,r,j,x,n,t=0;
int part();
 
int main (void){
   
  scanf("%d",&r);
  for(i = 1;i <= r;i++){
    scanf("%d",&A[i]);
  }

  part();
 
  for(i = 1;i <= t;i++){
    printf("%d ",A[i]);
  }

  printf("[%d] ",A[i]);

  for(i = t+2;i <= r;i++){
    printf("%d",A[i]);
    if(i!=r)printf(" ");
  }

  printf("\n");
 
  return 0;
}
 
int partition(){
  x = A[r];
  i = p-1;

  if(i>r)return -1;

  for(j = p;j <= r-1;j++){
    if(A[j] <= x){
      i = i+1;
      n = A[i];
      A[i] = A[j];
      A[j] = n;
      t++;
    }
  }