#include<stdio.h>

int A[100000];

int partition(int A[], int p, int r){
    int x = A[r-1];
    int i = p;
    for(int 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(void){
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++)
        scanf("%d", &A[i]);
    int ip = partition(A, 0, n);
    for(int i=0; i<n; i++){
        if(i == ip)
            printf("[%d]", A[i]);
        else
            printf("%d", A[i]);
        putchar(i < n - 1 ? ' ' : '\n');
    }
}

