#include <stdio.h>

int main()
{
  int i, j = 0, n, A[100000], x, a;

  scanf("%d",&n);
  for (i = 0; i < n; i++)
    scanf("%d",&A[i]);
  for (i = 0; i < n; i++)
    if (A[i] <= A[n-1]){
      x = A[i];
      A[i] = A[j];
      A[j] = x;
      j++;
    }
  for (i = 0; i < n; i++){
    if (i == j-1)
      printf("[%d]",A[i]);
    else
      printf("%d",A[i]);
    if (i < n-1)
      printf(" ");
  }
  printf("\n");
  
  return 0;
}

