#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

#define UTIL_SWAP(x, y)                                                                                                                    \
  do {                                                                                                                                     \
    typeof(x) _a = x;                                                                                                                      \
    x = y;                                                                                                                                 \
    y = _a;                                                                                                                                \
  } while (0)


size_t partition(int32_t data[], size_t len, int32_t pivot)
{
  size_t index = 0;

  if (data == NULL) return index;

  uint32_t i;
  for (i = 0; i < len; i++) {
    if (data[i] <= pivot) {
      UTIL_SWAP(data[index], data[i]);
      index++;
    }
  }

  return index;
}

#if !defined(TEST)
#include <stdio.h>
static int32_t data[1000000];

int32_t main(void)
{
  int32_t num;
  scanf("%d", &num);

  int32_t i;
  for (i = 0; i < num; i++) {
    scanf("%d", &data[i]);
  }

  size_t index = partition(data, num - 1, data[num - 1]);

  for (i = 0; i < index; i++) {
    if (i != 0) printf(" ");
    printf("%d", data[i]);
  }
  printf(" [%d] ", data[num - 1]);

  for (i = index; i < (num - 1); i++) {
    if (i != index) printf(" ");
    printf("%d", data[i + 1]);
  }
  printf("\n");

  return 0;
}

#endif