#include<stdio.h>

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

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