#include <stdio.h>
#include <string.h>
 
#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
    int n = 0, c = gc();
    do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
    return n;
}
 
int partition(int *a, int lo, int hi)
{
    int i, j, x, t;
 
    x = a[hi], i = lo-1;
    for (j = lo; j < hi; j++) {
        if (a[j] <= x) i++, t = a[i], a[i] = a[j], a[j] = t;
    }
    t = a[++i], a[i] = a[hi], a[hi] = t;
    return i;
}
 
int a[100002];
 
int main()
{
    int n, i, k;
     
    n = in(); for (i = 0; i < n; i++) a[i] = in();
    k = partition(a, 0, n-1);
    printf((!k? "[%d]": "%d"), a[0]);
    for (i = 1; i < n; i++) {
        putchar(' ');
        printf((k==i? "[%d]": "%d"), a[i]);
    }
    putchar('\n');
    return 0;
}
