#include <stdio.h>
#include <string.h>
#include <math.h>


/*
 * *A int type array
 * left head index of array *A
 * right tail index of array *A
 */
int partition(int *A, int left, int right){
    
    int x = A[right];
    int i = left - 1;
    int j,tmp;
    
    for (j=left; j<right; j++) {
        if (A[j] <= x) {
            i = i+1;
            /* A[i] ??¨ A[j] ????????? */
            tmp = A[i];
            A[i] = A[j];
            A[j] = tmp;
        }
    }
    
    /* A[i+1] ??¨ A[r] ????????? */
    tmp = A[i+1];
    A[i+1] = A[right];
    A[right] = tmp;
    
    return i+1;   
}

int main( ){
    
    int i, n,axis;
    
    scanf("%d", &n);
    int A[n];
    
    
    for (i=0; i<n; i++) {
        scanf("%d", &A[i]);
    }
    
    axis = partition(A, 0, n-1);
    
    for (i=0; i<n; i++) {
        if (i == axis) {
            printf("[%d]", A[i]);
        }
        else{
            printf("%d", A[i]);
        }
        if (i != n-1) {
            printf(" ");
        }
    }
    printf("\n");
    
    
    return 0;
}