#include <stdio.h>

#define N 100000

void swap(int *a, int *b) {
	int tmp;

	tmp = *a;
	*a = *b;
	*b = tmp;
}

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

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

	for (j = p; j < r; ++j) {
		if (A[j] <= x) {
			i++;
			swap(&A[i], &A[j]);
		}
	}
	swap(&A[i + 1], &A[r]);

	return i + 1;
}

int main() {
	int i, n, pivot, A[N];

	scanf("%d", &n);

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

	pivot = partition(A, 0, n - 1);

	for (i = 0; i < pivot; ++i) {
		printf("%d ", A[i]);
	}

	printf("[%d]", A[pivot]);

	for (i = pivot + 1; i < n; i++) {
		printf(" ");
		if (A[i] > A[pivot]) printf("%d", A[i]);
	}

	printf("\n");

	return 0;
}