 #include<stdio.h>
 #define MAX 100000
 int partition(int, int);
 int A[MAX];
 int main(){
     int n,i,j,k,A[MAX],x,p=0,r,s,z;
        scanf("%d",&n);
     for(i=0; i<n; i++){
        scanf("%d",&A[i]);
     }
     r=n-1;
     
    x=A[r];
    i=p-1;
    for(j=p; j<=r-1; j++){
        if(A[j]<=x){
            i=i+1;
            s=A[i];
            A[i]=A[j];
            A[j]=s;
        }
    }
    s=A[i+1];
    A[i+1]=A[r];
    A[r]=s;
    z=i+1;
    
     for(k=0; k<n; k++){
         if(k)printf(" ");
         if(k==z)printf("[");
         printf("%d",A[k]);
         if(k==z)printf("]");
     }
     printf("\n");
     return 0;
 }
