#include <stdio.h>
#define MAX (int)1e5+1

int A[MAX];

void swap(int *a, int *b) { int tmp = *a; *a = *b; *b = tmp; }

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

int main() {
    int i, q, n;

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }

    q = partition(0, n - 1);

    for (i = 0; i < n; i++) {
        if (i == q) printf("[");
        printf("%d", A[i]);
        if (i == q) printf("]");
        printf( (i == n - 1) ? "\n" : " ");
    }

    return 0;
}