#include <stdio.h>

#define MAX 100000

int
partition(int array[], int p, int r)
{
        int i, j;
        int a;
        int standard_num;

        standard_num = array[r];
        i = p - 1;

        for (j = p; j < r; j++) {
                if (array[j] <= standard_num) {
                        i++;
                        a = array[i];
                        array[i] = array[j];
                        array[j] = a;
                }
        }
        a = array[i + 1];
        array[i + 1] = array[r];
        array[r] = a;

        return i + 1;
}

int
main(void)
{
        int array[MAX];
        int array_len;
        int i;
        int standard;

        scanf("%d", &array_len);

        for (i = 0; i < array_len; i++)
                scanf("%d", &array[i]);

        standard = partition(array, 0, (array_len - 1));

        for (i = 0; i < array_len; i++) {
                if (i)
                        printf(" ");
                if (i == standard)
                        printf("[");

                printf("%d", array[i]);

                if (i == standard)
                        printf("]");
        }

        printf("\n");

        return 0;
}

