#include <stdio.h>

int partition(int *,int,int);

int main(){
	int i,A[100000],num,center;
	
	scanf("%d",&num);
	
	for(i=0;i<num;i++){
		scanf("%d",&A[i]);
	}
	
	center = partition(A,1,num);
	
	for(i=0;;i++){
		printf("%d",A[i]);
		if(i>=num){
			break;
		}
		printf(" ");
	}
	return 0;
}

int partition(int A[],int p,int r){
	int x = A[r];
	int i = p-1,tmp;
	
	for(j = p; j < r; j++){
		if(A[j] <= x){
			i = i + 1;
			tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}
	
	tmp = A[i+1];
	A[i+1] = A[r];
	A[r] = tmp;
	
	return i+1;
}