#include<stdio.h>


int Partition(int *,int,int);

int A[1000000],key;

int main(){
int n,i=1;

scanf("%d",&n);
while(i<=n){

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

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

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

int Partition(int *A,int p,int r){

int size,j,x,temp;

x = A[r];
size = p-1;

for(j = p; j < r; j++){
if(A[j] <= x){
size++;
      
temp = A[size];
A[size] = A[j];
A[j] = temp;
}

}

temp = A[r];
A[r] = A[size+1];
  A[size+1] = temp;
  
  
  return size+1;
  
}

