#include <stdio.h>
#define MAX 100000
#define VMAX 100000

int main(){
    int n, i, j, A[MAX], tmp, x ;

    //input
    scanf("%d", &n);
    for(i=0; i<n; i++) scanf("%d", &A[i]);
    x = A[n-1];
    //sort
    for(i=-1, j=0; j<n-1; j++){
	if(A[j] <= x){
	    i++;
	    tmp = A[i];
	    A[i] = A[j];
	    A[j] = tmp;
	}
    }
    tmp = A[i+1]; A[i+1] = A[n-1]; A[n-1] = tmp;
    //display
    for(j=0; j<n; j++){
	if(j == i+1) printf("[");
	printf("%d", A[j]);
	if(j == i+1) printf("]");
	if(j < n-1) printf(" ");
    }
    printf("\n");
    return 0;
}

