#include<stdio.h>

 void part(int n,int A[]){
       int i,j,key,tmp,k;
       key=A[n-1];
       j=0;
       i=j-1;
       while(j != n-1){
               if(A[j]>=key){j++;}
               else {
                     i++;
                     tmp=A[j];A[j]=A[i];A[i]=tmp;
                     j++;
                     }
                }
       i++;
       tmp=A[j];A[j]=A[i];A[i]=tmp;
       for(k=0;k<i-1;k++){
               printf("%d ",A[k]);
               }
       printf("[%d] ",A[i]);
       for(k=i+1;k<=j;k++){
               printf("%d%c",A[k],(k==j)?'\n':' ');
               }
       }
       
                

 int main(){
       int i,n,A[100001];
       scanf("%d",&n);
       for(i=0;i<n;i++){
                 scanf("%d",&A[i]);
                 }
       part(n,A);
       return 0:
       }


