#include <stdio.h>
#define buf 100000
int partition(int A[],int p,int r);

int main(void){
	int n,i,base;
	int A[buf];

	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&A[i]);
	base=partition(A,0,n-1);
	for(i=0;i<n;i++){
		if(i) printf(" ");
		if(i==base)
			printf("[%d]",A[i]);
		else
			printf("%d",A[i]);
	}
	printf("\n");
	return 0;
}
int partition(int A[],int p,int r){
	int x=A[r];
	int i=p-1;
	int j,c;
	for(j=p;j<r;j++){
		if(A[j]<=x){
			i++;
			c=A[i];
			A[i]=A[j];
			A[j]=c;
		}
	}
	c=A[i+1];
	A[i+1]=A[r];
	A[r]=c;
	return i+1;
}