#include <stdio.h>

int main (){
    int n,i,A[100000],x,p,r,j,tmp;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    r=n-1;
    p=0;
    x=A[r];
    i=p-1;
    for(j=p;j<r;j++){
        if(A[j]<=x){
            i++;
            tmp=A[i];
            A[i]=A[j];
            A[j]=tmp;
        }
    }
    tmp=A[i+1];
    A[i+1]=A[r];
    A[r]=tmp;
    for(j=0;j<n;j++){
        if(j)printf(" ");
        if(j==i+1){
            printf("[%d]",A[j]);
        }
        else printf("%d",A[j]);
    }
    printf("\n");
    return 0;
}
