#include <stdio.h>
#define M 100005

int A[M],n;

int partition(int p,int r){
    int x=A[r],kari;
    int j= p -1;
    for(int i=p;i<r;i++){
        if(A[i]<= x){
            j++;
            kari= A[i];
            A[i] = A[j];
            A[j] = kari;
        }
    }
    kari = A[j+1];
    A[j+1]= A[r];
    A[r] = kari;
    return j+1;
}
int main(void){
    int i,q;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
    }

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


