#include <stdio.h>
#include <stdlib.h>
#define MAX 100001
#define VMAX 100000

int main(){
  unsigned short *A;
  int i, j, x, r, n, m, q, p= 1;

  scanf("%d", &m);

  A = malloc(sizeof(short)*m+1);

  for(i = p; i <= m; i++){
    scanf("%hu", &A[i]);
  }
  x = A[m];
  i = p-1;
  for(j = p; j <= m-1; j++){
    if(A[j] <= x){
      i = i+1;
      n = A[i];
      A[i] = A[j];
      A[j] = n;
    }
  }
  n = A[i+1];
  A[i+1] = A[m];
  A[m] = n;
  q = i+1;
  
  for(j = p; j <= q-1; j++){
    printf("%u ", A[j]);
  }
  printf("[%u]", A[q]);
  for(j = q+1; j <= m; j++){
    printf(" %u", A[j]);
  }
  printf("\n");

  return 0;
}

