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

 int main(){
   unsigned short *a, *b;
   int n, i, j,u=0,x,m,p;

   scanf("%d", &n);

   a = malloc(sizeof(short)*n+1);
   for(i=1;i<n+1;i++){
     scanf("%hu",&a[i]);
   }

   x=a[n];
   u = 1;
   /*for( j = 1 ;j< n;j++){
     if( a[j] <= x){
       u++;
       m=a[u];
       a[u]=a[j];
       a[j]=m;
   }
       m=a[u+1];
       a[u+1]=a[n];
       a[n]=m;

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

     }*/

     for( j = 1 ;j< n+1;j++){
       if(j==n){
         p=u+1;
       }
       if( a[j] <= x){
         m=a[u];
         a[u]=a[j];
         a[j]=m;
         u++;
     }
   }

   for(i=1;i<n+1;i++){
     if(i>1){
       printf(" ");
     }
     if(i==u-1){
       printf("[%d]",a[u-1]);
       continue;
     }
   printf("%d",a[i]);
 }
 printf("\n");
 }

