#include<stdio.h>
#define MAX 100000

int a[MAX],n;

int paetition(int p,int r){
    int x,i,j,t;
    x=a[r];
    i=p-1;
    
    for(j=p;j<r;j++){
        if(a[j]<=x){
            i++;
            t=a[i];
            a[i]=a[j];
            a[j]=t;
        }
    }
    t=a[i+1];
    a[i+1]=a[r];
    a[r]=t;

    return i+1;
}

int main(void){
    int i,q;
    scanf("%d",&n);
    for(i=0;i<n;i++)scanf("%d",&a[i]);

    q=paetition(0,n-1);

    for(i=0;i<n;i++){
        if(i)printf(" ");
        if(i==q)printf("[");
        printf("%d",a[i]);
        if(i==q)printf("]");

    }
    printf("\n");

    return 0;
}
