#include<stdio.h>
#include<stdlib.h>
int main(){
  int i,j,tmp,X,n,*A;
  scanf("%d",&n);
  A = malloc(sizeof(int)*n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);

  X=A[n-1];
  i=-1;
  for(j=0;j<n-1;j++){
    if(X >=A[j]){
      i++;
      tmp=A[j];
      A[j]=A[i];
      A[i]=tmp;
    }
  }
  tmp=A[n-1];
  A[n-1]=A[i+1];
  A[i+1]=tmp;

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