#include <stdio.h>
#include <stdlib.h>
int main(void){
    int h,i,j,k;
    int *p;
    scanf("%d",&h);
    p = (int*)malloc(sizeof(int)*h);
    for(i=0;i<h;i++){
        scanf("%d",&p[i]);
    }
    k=-1;
    for(i=0;i<h-1;i++){
        if(p[i]<=p[h-1]){
            k++;
            j=p[i];
            p[i] = p[k];
            p[k] = j;
        }
    }
    j = p[k+1];
    p[k+1] = p[h-1];
    p[h-1]=j;
    j=k+1;
    for(i=0;i<h;i++){
        if(j==i){printf("[");}
        printf("%d",p[i]);
        if(j==i){printf("]");}
        if(i!=h-1){
            printf(" ");
        }
    }
    printf("\n");
    free(p);
    return 0;
}


