#include<stdio.h>


int partition(int *A, int p, int r){
    int i,j,buf,x;
    x = A[r];
    i = p-1;
    
   for (j = p; j < r-1; j++){
     if (A[j] <= x){
        i = i+1;
        buf = A[i];
        A[i] = A[j];
        A[j] = buf;
     }
   
    }
     buf = A[i+1];
    A[i+1] = A[r];
     A[r] = buf;
   return i+1;
}
int main(){
    int i,l,A[100000];
    scanf("%d",&l);
    for(i = 0; i < l; i++)
        scanf("%d",&A[i]);
    partition(A,l,l-1);
    for(i = 0;i<l-1;i++)
        printf("%d ",A[i]);
    printf("%d\n",A[l-1]);
    return 0;
}

