#include<stdio.h>
#include<math.h>

#define MAX 100000

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

int main(){
	int n,k = 0;
	int val[MAX];
	
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%d",&val[i]);
	}
	int index = partition(val, 0, n-1);
	
	printf(index==0?"[":"");
	printf("%d",val[0]);
	printf(index==0?"]":"");
	for(int i = 1;i < n; i++){
		printf(" ");
		printf(index==i?"[":"");
		printf("%d",val[i]);
		printf(index==i?"]":"");
	}
	printf("\n");
	return 0;
}
