/*
 * Problem
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_B&lang=jp
 *
 * Author
 * Leonardone @ NEETSDKASU
 */
#include <stdio.h>

void exchange(int A[], int i, int j) {
	int tmp = A[i];
	A[i] = A[j];
	A[j] = tmp;
}

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

int main(void) {
	int A[100001];
	int n, i, q;
	
	scanf("%d", &n);
	for (i = 1; i <= n; ++i) {
		scanf("%d", &A[i]);
	}
	
	q = Partition(A, 1, n);
	
	for (i = 1; i <=n ; ++i) {
		if (i > 1) {
			putchar(' ');
		}
		if (i == q) {
			printf("[%d]", A[i]);
		} else {
			printf("%d", A[i]);
		}
	}
	putchar('\n');
	
	return 0;
}