#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
  int n, i, j, q, tmp;
  int *A;
  int x;

  scanf("%d", &n);
  A = (int *)malloc(sizeof(int) * n);
  for (i = 0; i < n; i++) scanf("%d", &A[i]);

  x = A[n-1];
  i = -1;
  for (j = 0; j < n - 1; j++) {
    if (A[j] <= x) {
      i++;
      tmp = A[j];
      A[j] = A[i];
      A[i] = tmp;
    }
  }
  tmp = A[n-1];
  A[n-1] = A[i+1];
  A[i+1] = tmp;
  q = i+1;

  for (i = 0; i < n; i++) {
    if (i != n - 1) {
      if (i == q) printf("[%d] ", A[i]);
      else printf("%d ", A[i]);
    } else {
      if (i == q) printf("[%d]\n", A[i]);
      else printf("%d\n", A[i]);
    }
  }

  return 0;
}