#include <stdio.h>

struct elem{
    unsigned int i;
    double v;
};

int partition(
        struct elem* ary,
        int p, int r)
{
    int i =0;
    int j = 0;
    struct elem x, buf;
    x = ary[r];
    i = p;
    for (j = p; j < r; j++) {
        if (ary[j].v <= x.v) {
            buf = ary[j];
            ary[j] = ary[i];
            ary[i] = buf;
            i++;
        }
    }
    buf = x;
    ary[r] = ary[i];
    ary[i] = buf;
    return i;
}

void quick_arg_sort(
        // input
        const double *ary,
        // output
        int *sorted_index) {
}


struct elem A[100010];
int main() {
    int i, n, k;
    scanf("%d ", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &(A+i)->v);
    }
    k = partition(A, 0, n-1);
    for (i = 0; i < n; i++) {
        if (i) {
            printf(" ");
        }
        if (i == k) {
            printf("[");
        }
        printf("%d", A[i].v);
        if (i == k) {
            printf("]");
        }
    }
    return 0;
}
