#include<stdio.h>

int main(){
  int N,A[100000];
  int i,j,key,swt;
  
  scanf("%d",&N);
  for(i=0;i<N;i++) scanf("%d",&A[i]);
  key=A[N-1];
  i=-1;
  
  for(j=0;j<N-1;j++){
    if(key>=A[j]){
      i++;
      swt=A[i];
      A[i]=A[j];
      A[j]=swt;
    }
  }

  
  
  key=A[i+1];
  A[i+1]=A[N-1];
  A[N-1]=key;

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


