#include<stdio.h>
#include<stdlib.h>

int main(){
  int n,i,k;
  unsigned short *A;
  scanf("%d",&n);

  A=malloc(sizeof(short)*n+1);

  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    if(k<=A[i]){
      k=A[i];
    }
  }
  int x=A[n-1];
  int j=0,temp;
  for(i=0;i<n-1;i++){
    if(x>A[i]){
      temp=A[j];
      A[j]=A[i];
      A[i]=temp;
      j++;
    }
  }
  temp=A[j];
  A[j]=A[n-1];
  A[n-1]=temp;

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

  return 0;
}

