#include <stdio.h>
#define max 100000

int a[max] , n;

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

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

