#include <stdio.h>

int A[1000000];

int  main(){
  int i,n,key,temp,big=0,sml=0;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);

  key = A[n-1];
 
  for(i=0;i<n;i++){
    if(i == 0 && key >= A[i]){
      sml++;
      big++;
    }
    else if(key >= A[i]){
      temp = A[i];
      A[i] = A[sml];
      A[sml] = temp;
      sml++;
      big++;
    }
    else
      big++;
  }
  
  temp = key;
  A[n-1] = A[sml];
  A[sml] = temp;

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

  return 0;
}
