#include <stdio.h>
#define N 100000
int times(void);
int partition(int*, int, int);
void temp(int*,int*);
void view(int*,int,int);
int main() {
	int n,i,A[N],q;
	n = times();
	for (i = 0;i < n;i++) {
		scanf("%d", &A[i]);
	}
	q = partition(A, 0, n);
	view(A, n, q);
}
int partition(int*A, int p, int r) {
	int x, i,j;
	x = A[r-1];
		i = p;
		if (A[i] <= x)i++;
		for (j = p+1; j < r; j++) {
			if (A[j] <= x) {
				//A[i] �� A[j] ������
				temp(&A[i],&A[j]);
				i++;
			}
		}
   return i;
}
void temp(int* x, int* y) {
	int t;
	t = *x;
	*x = *y;
	*y = t;
}
int times() {
	int n;
	scanf("%d",&n);
	return n;
}
void view(int*A,int n,int q) {
	int i;
	for (i = 0; i < n; i++) {
		if (i)printf(" ");
		if (i == q-1)printf("[");
		printf("%d",A[i]);
		if (i == q-1)printf("]");
	}
	printf("\n");
}
