#include<stdio.h>

#define MAX 100000

int main() {

	int i = 0, j = 0, k, n, tmp, arr[MAX];

	scanf("%d", &n);

	int m = n - 1;

	for (i = 0; i < n; i++)
		scanf("%d", &arr[i]);
	i = 0;
	while (1) {
		
			if (j == m)
			break;
			
		if (arr[j] < arr[m]) {
			
			tmp = arr[i];
			arr[i] = arr[j];
			arr[j] = tmp;
			i++;
			j++;		
			
			continue;
		}
		
			
		else {
			
			j++;
					
			continue;
		}
			
	}
			tmp = arr[i];
		arr[i] = arr[m];
		arr[m] = tmp;
	
		for (k = 0; k < n; k++) {
	
				if(arr[k] == arr[i]){
				
				printf("[%d] ",arr[k]);
				continue;
				}
			
			printf("%d", arr[k]);

			if (k != n - 1)
				printf(" ");
				
		}
			printf("\n");
			return 0;
	}