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

