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

int main(){
  int n,i,x,j,r,t;
  int *a;
  scanf("%d",&n);
   a = malloc(sizeof(int)*n+1);

   for(i = 0; i < n; i++){
     scanf("%d",&a[i]);
   }
   x = a[i-1];
   r = i-1;
   i = 0 - 1;
   for(j = 0; j < r; j++){
     if( a[j] <= x){
       i = i + 1;
       t = a[j];
       a[j] = a[i];
       a[i] = t;
     }
   }
     t = a[i+1];
     a[i+1] = a[r];
     a[r] = t;
   

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