#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>


static int Partition(int A[], int p, int r) {
    int x = A[r];
    int i = p - 1;

    for ( int j = p; j < r; j++ ) {
        if ( A[j] <= x ) {
            i = i + 1;
            int t = A[i];
            A[i] = A[j];
            A[j] = t;
        }
    }
    int t = A[i+1];
    A[i+1] = A[r];
    A[r] = t;

    return i + 1;
}

int main(void) {
    int i;
    int n;
    int r;
    int k = 0;
    int *A;

    scanf("%d\n", &n);
    A = malloc(sizeof(int) * (n + 1));

    for ( i = 0; i < n; i++ ) {
        int d;
        scanf("%d", &d);
        A[i] = d;
        if ( d > k ) {
            k = d;
        }
        (void)fgetc(stdin);
    }

    r = Partition(A, 0, n - 1);

    for ( i = 0; i < n; i++ ) {
        if ( i == r ) {
            printf("[%d]", A[i]);
        } else {
            printf("%d", A[i]);
        }
        if ( i + 1 < n ) {
            printf(" ");
        }
    }
    printf("\n");

    free(A);

    return 0;
}

