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

int main()
{
  int i, j, x, tmp;
  int *A, r, n;

  
  scanf("%d", &n);

  A = 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[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }

  tmp = A[n-1];
  A[n-1] = A[i+1];
  A[i+1] = tmp;


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

  
  return 0;
}

