#include <stdio.h>
#include <stdlib.h>


int Partition(int *A, int p, int r)
{
	int x;
	int i, j, k;


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

	for(j = p; j < r; j++){
		if(A[j] <= x){
			i++;
			if(i != j){
				A[i] ^= A[j];
				A[j] ^= A[i];
				A[i] ^= A[j];
			}
		}
	}

	A[i + 1] ^= A[r];
	A[r] ^= A[i + 1];
	A[i + 1] ^= A[r];

	return i + 1;
}


int main()
{
	int n;
	int *box;
	int partition_n;
	int i;


	scanf("%d", &n);

	box = (int *)malloc(sizeof(int) * n);

	for(i = 0; i < n; i++)
		scanf("%d", &box[i]);


	// 分割処理
	partition_n = Partition(box, 0, n - 1);

	// 表示
	for(i = 0; i < n; i++){
		if(i == partition_n)
			printf("[");
		printf("%d", box[i]);
		if(i == partition_n)
			printf("]");
		if(i != n - 1)
			printf(" ");
	}
	printf("\n");

	return 0;
}
