#include<stdio.h>

int main(){
  int i,n,x,y,j;
  scanf("%d",&n);
  int a[n];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  x=a[n-1];
  i=-1;
  for(j=0;j<n;j++){
    if(a[j]<=x){
      i=i+1;
      y=a[i];
      a[i]=a[j];
      a[j]=y;
    }
  }
 
  for(j=0;j<i;j++){
    printf("%d ",a[j]);
  }
  printf("[%d] ",a[i]);
  for(j=i+1;j<n-1;j++){
    printf("%d ",a[j]);
  }
  printf("%d\n",a[n-1]);
  return 0;
}