/*
 * FileName:     partition
 * CreatedDate:  2020-08-13 01:31:30 +0900
 * LastModified: 2020-08-13 01:49:28 +0900
 */

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

int main(void){
    int n;scanf("%d", &n);
    int *A = malloc(n*sizeof(int));
    for(int i=0; i<n; i++)scanf("%d", A+i);
    int swap_obj = 0;
    int pivot = A[n-1];
    for(int i=0; i<n-1; i++){
        if(pivot >= A[i]){
            int tmp = A[i];
            A[i] = A[swap_obj];
            A[swap_obj++] = tmp;
        }
    }
    int tmp = A[n-1];
    A[n-1] = A[swap_obj];
    A[swap_obj] = tmp;
    printf("%d", A[0]);
    for(int i=1; i<n; i++){
        if(i==swap_obj){
            printf(" [%d]", A[i]);
        }
        else{
            printf(" %d", A[i]);
        }
    }
    printf("\n");
    free(A);
    return 0;
}

