#include<iostream>
#include<algorithm>
using namespace std;
int a[100000];
int partition(int n,int key) {
	int i = 0;
	for (int j = 0; j < n - 1; j++) {
		if (a[j] <= key) {
			swap(a[i], a[j]);
			i++;
		}
	}
	swap(a[i], a[n - 1]);
	return i;
}
int main(void) {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int k=partition(n, a[n - 1]);
	for (int i = 0; i < n; i++) {
		if (i) cout << " ";
		if (i == k)cout << "[" << a[i] << "]";
		else
		{
			cout << a[i];
		}
	}
	cout<<endl;
	return 0;
}
