#include<stdio.h>

int partition(int* A,int p,int r){
int j,x,i,t;
x = A[r];
i = p-1;
for(j=p;j<r-1;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(){
    int A[100000],i,count=0,n,t;

scanf("%d",&n);

for(i = 0 ; i < n ; i++){

scanf("%d",&A[i]);

}
t = partition(A, 0 ,n);


for(i = 0 ; i < t ; i++){

    printf("%d ",A[i]);
}
printf("%d ",A[t]);

for(i=t+1;i<n;i++){
    count++;
printf("%d",A[i]);

if(count != n-1)
printf(" ");

}
printf("\n");

return 0;
}



