#include <stdio.h>

int A[100000];

int  partition(int p, int r){
    int x = A[r];
    int i = p-1;
    for( int j = p; j < r; j++){
        if( A[j] <= x){
            i++;
            int o = A[j];
            A[j] = A[i];
            A[i] = o;
        }
    }
    A[r] = A[i+1];
    A[i+1] = x;
    return i+1;
}

int main(){
    int n;
    scanf("%d", &n);
    for( int k = 0; k < n; k++){
        scanf("%d", &A[k]);
    }
    int q = partition( 0, n-1);

    for( int l = 0; l < n; l++){
    	if( l ) printf(" ");
        if( l == q ) printf("[");
        printf("%d", A[l]);
        if( l == q) printf("]");
    }
    printf("\n");
    return 0;
}
