//Partition

#include<stdio.h>

#define swap(type, x ,y)    do{type t = x; x = y; y = t;} while(0)


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


int main(void){
    int n;
    int ptr;
    int i;
    int a[100001];
    
    scanf("%d", &n);
    for(i = 0; i < n; i++)  scanf("%d", &a[i]);
    
    ptr =  partition(a, 0, n-1);
   
    printf("%d", a[0]);
    for(i = 1; i < n; i++) {
        if(ptr == i) printf(" [%d]", a[i]);
        else printf(" %d", a[i]);
    }
    putchar('\n');
   
    return 0;
}