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

int main(){
  int i, j, x, p, q, n, tmp;

  scanf("%d", &n);
  int *a;
  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[i+1];
  a[i+1] = a[n-1];
  a[n-1] = tmp;

  for(j = 0; j < i+1; j++)
      printf("%d ", a[j]);
  printf("[%d] ", a[j]);
  for(j = j+1; j < n-1; j++)
    printf("%d ", a[j]);
  printf("%d\n", a[j]);

  free(a);
  return 0;
}