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

int main(){
    int n,i,j,k,x,swap,*A;

    scanf("%d",&n);

    A = (int *) malloc ( sizeof(int) * n);

    for(j=0;j<n;j++) scanf("%d",&A[j]);

    i=-1;

    for(j=0;j<n-1;j++){
        if(A[j] <= A[n-1]) {
            i++;
            swap=A[i];
            A[i]=A[j];
            A[j]=swap;
        }
    }

    swap=A[i+1];
    A[i+1]=A[n-1];
    A[n-1]=swap;

    for(j=0;j<=i;j++) printf("%d ",A[j]);
    printf("[%d]",A[i+1]);
    for(j=i+2;j<n;j++) printf(" %d",A[j]);
    printf("\n");

    return 0;    
}
