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

int main(){

  int i,j,change;
  int sumdata;
  int index;
  int *A;

  scanf("%d",&sumdata);

  A = malloc(sizeof(int) * (sumdata + 1));

  for(i = 0; i < sumdata; i++){

    scanf("%d",&A[i]);

  }

  i = 0;
  j = 0;
  index = A[sumdata - 1];

  while(j != sumdata-1){

    if(index >= A[j]){

      change = A[i];
      A[i] = A[j];
      A[j] = change;

      i = i + 1;
      j = j + 1;

    }

    else if(index < A[j]){

      j = j + 1;

    }


  }

  change = A[sumdata -1];
  A[sumdata -1] = A[i];
  A[i] = change;

  for( j = 0; j < i; j++){

    printf("%d ",A[j]);

  }

  printf("[%d] ",A[i]);

  for(j = i + 1; j < sumdata -1; j++){

    printf("%d ",A[j]);

  }

  printf("%d",A[sumdata -1]);

  return 0;

}