#include<stdio.h>

#define N 100000

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

