#include <stdio.h>

#define MAX 100000

int partition(int *, int, int);
void swap(int *, int *);

int main(void)
{
	int i, n, pi, A[MAX];
	
	scanf("%d",&n);
	for (i=0; i<n; i++) {
		scanf("%d",&A[i]);
	}
	
	pi = partition(A, 0, n-1);
	
	for (i=0; i<n; i++) {
		if(i>0) printf(" ");
		if(i==pi) printf("[%d]",A[i]);
		else printf("%d",A[i]);
	}
	printf("\n");
	
	return 0;
}

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

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