#include <stdio.h>
#include <math.h>

#define MAX 200000
#define SENTINEL 2000000000

int L[MAX / 2 + 2], R[MAX / 2 + 2];
static int C[MAX];
int B[MAX];


long long mergeSort(int A[],int n){
	int mid;
	int j;
	int k;
        int i;
	int value;
	//??????????????????
	j = 0;

	printf("%d \n", A[n - 1]);
	for (i = 0; i < n; i++){

		if (A[n - 1] >= A[i]){
			value = A[i];
			A[i] = A[j];
			A[j] = value;
			j++;
		}

	}

	return 0;
}

int main(){
	int A[MAX], n, i;
	scanf("%d", &n);
	int value;

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

	value = A[n - 1];

	long long ans = mergeSort(A,n);

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

		else printf(" %d", A[i]);

	}

	return 0;

}