#include <stdio.h>

#define N 131072

int A[N] = {0};

void swap(int *x, int *y) {
  int tmp;

  tmp = *x;
  *x = *y;
  *y = tmp;
}

int partition(int p, int r) {
  int i, j, x;

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

int main(void){
  int i, n, q;
  const char *sp;

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

  for (i = 0, sp = ""; i < n; i++) {
    if (i == q)
      printf("%s[%d]", sp, A[i]);
    else
      printf("%s%d", sp, A[i]);
    sp = " ";
  }
  puts("");

  return 0;
}