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

int *A;

int partation(p, r){
    int i, par_small = 0, par_end = 0, temp;

    for(i = 0; i < p; i++){
        if(r < A[i]){
            par_end++;
        }
        else{
            temp = A[par_small];
            A[par_small] = A[i];
            A[i] = temp;
            par_small++;
            par_end++;
        }
    }
    return par_small;
}

int main(){

    int n, i, center;

    scanf("%d",&n);
    A = malloc(sizeof(int) * n);
    for(i = 0; i < n; i++) scanf("%d",&A[i]);

    center = partation(n, A[n-1]);
    for(i = 0; i < n; i++){
        if(i == center - 1){
            printf("[");
        }
        printf("%d",A[i]);
        if(i == center - 1){
            printf("]");
        }
        if(i < n-1) printf(" ");
    }
    printf("\n");
    return 0;
}
