/*Partition*/
#include <stdio.h>
#include <stdlib.h>
#define N 2000001

int main(){
  int A[N];
  int k, i, j, tmp, n;

  scanf("%d", &n);
  for (i=0; i<n; i++){
    scanf("%d", &A[i]);
  }
  k = A[n-1];

  j=0;
  for (i=0; i<n; i++){
    if(A[i] <= k){
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
      j++;
    }
    else continue;
  }

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

