	#include<stdio.h>

	int A[100000];

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

	int main(){
	  int n,i,ip;
	scanf("%d",n);
	for(i=0;i<n;i++){
	scanf("%d",&A[i]);
	}
	ip = partition(A,0,n);
	for(i=0; i<n; i++){
	if(i == ip)
	 printf("[%d]",A[i]);
	else printf("%d",A[i]);
	putchar(i < n -1? ' ' : '\n');
	}
	}




	


