#include<stdio.h>
#include<stdlib.h>
#define N 1000000

int main()
{
    int i,j,a,n,tmp;
    int A[N],B[N];

    scanf("%d",&n);
    if(n < 1 || n > N)exit(1);

    for(i = 0 ; i < n ; i++){
        scanf("%d",&A[i]);
        if(A[i] < 0 || A[i] > N)exit(1);
    }
    i = -1;
    a = A[n-1];
    for(j = 0 ; j < n-1 ; j++){
        if(A[j] <= a){
            i++;
            tmp = A[i];
            A[i] = A[j];
            A[j] = tmp;
        }
        }
    tmp = A[i+1];
    A[i+1] = A[n-1];
    A[n-1] = tmp;

    for(j = 0 ; j < n ; j++){
        if(j)printf(" ");
        if(j == i + 1)printf("[%d]",A[j]);
        else printf("%d",A[j]);
    }
    printf("\n");
    return 0;
}

