#include<stdio.h>

#define N 1000000

int main(){
  int A[N],i,j=0,n,tmp;

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

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

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

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