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

main(){
  int n, *a, p, r, x, i, j, k;

  scanf("%d", &n);

  a = malloc(sizeof(int)*n+1);

  for(i = 0;i < n;i++) scanf("%d", &a[i]);
  p = 0;
  r = n - 1;

  x = a[r];
  i = p - 1;
  
  for(j = p;j <= r-1;j++){
    if(a[j] <= x){
      i = i+1;
      k = a[j];
      a[j] = a[i];
      a[i] = k;
    }
  }
  k = a[r];
  a[r] = a[i+1];
  a[i+1] = k;

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