#include<stdio.h>

void swap(int *a, int *b){
int temp;

temp=*a;
*a=*b;
*b=temp;

}





int partition(int A[],int left,int right){
int i,j,x;

x=A[right];

i=left; j=right-1;
while(i<j){
 while(A[i]<x){i++;}
 while(A[j]>x){j--;}
 if(i<=j){swap(&A[i],&A[j]);}
}

swap(&A[i],&A[right]);
return i;
}





int main(){
int n,i;
int index;
int right,left;
int A[100000];

scanf("%d",&n);

for(i=0;i<n;i++){scanf("%d",&A[i]);}

left=0;
right=n-1;
index=partition(A,left,right);

for(i=0;i<index;i++){printf("%d ",A[i]);}
printf("[%d] ",A[index]);
for(i=index+1;i<n-1;i++){printf("%d ",A[i]);}
printf("%d",A[n-1]);



return 0;
}