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

int main(){

    int n, i, j, k;
    int x, t;
    int *a;

    scanf( "%d", &n );

    a = (int*)malloc(sizeof(int)*n);

    for( i=0; i<n; i++ )
        scanf( "%d", &a[i] );


    x = a[n-1];
    i=-1;

    for( j=0; j<(n-1); j++ ){
        if( a[j] <= x ){
            i++;
            t = a[i];
            a[i] = a[j];
            a[j] = t;
        }
    }
    i++;
    t = a[i]; a[i]=a[n-1]; a[n-1]=t;

    for( k=0; k<n; k++ ){
        if( k == i ) printf( "[" );
        printf( "%d", a[k]  );
        if( k == i ) printf( "]" );
        printf( "%c", ((n-1>k))?' ':'\n' );
    }
    

    free( a );
    return 0;
}

