#include<stdio.h>
????
#define N 100001
????
void Partition(int A[], int p, int r){
????int x, i, j;
????int temp;
????
????x = A[r];
????i = p-1;
????
????for(j = p; j <= r-1; j++){
????????if(A[j] <= x){
????????????i = i + 1;
????????????temp = A[i];
????????????A[i] = A[j];
????????????A[j] = temp;
????????}
????}
????
????temp = A[i + 1];
????A[i + 1] = A[r];
????A[r] = temp;
??

????for(j = 0; j <= r; j++){
????????if(j == i + 1) printf("[%d]", A[j]);
????????else printf("%d", A[j]);
????????if(j != r) printf(" ");
????}
????printf("\n");
??
}
????
int main(){
????int n, i, p = 0, r;
????int A[N];
????
????scanf("%d", &n);
????for(i = 0; i < n; i++) scanf("%d", &A[i]);
????r = n - 1;
????
????Partition(A, p, r);
????
????return 0;
}