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

int main(){

    int n, i, j, r;
    int t;
    int a[100000];

    scanf( "%d", &n );

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


    r = n-1;
    i=-1;

    for( j=0; j<(n-1); j++ ){
        if( a[j] <= a[r] ){
            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( j=0; j<n; j++ ){
        if( j == i ) printf( "[%d] ", a[j] );
        else printf( "%d ", a[j]  );
    }
    printf( "\n" );
    

    return 0;
}

