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

int partition(int *,int);

int main(){
  int *A,n,i,box;

  scanf("%d",&n);
  A = (int *)malloc(1 + n * sizeof(int));
  for(i = 1;i < n + 1;i++) scanf("%d",&A[i]);

  box = partition(A,n);


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

int partition(int *A,int n){
  int x,i,j,hako;
  x = A[n];
  i = -1;
  for(j = 0;j < n;j++){
    if(A[j] <= x){
      i += 1;
      hako = A[i];
      A[i] = A[j];
      A[j] = hako;
    }
  }
  hako = A[i + 1];
  A[i + 1] = A[n];
  A[n] = hako;
  
  return i + 1;
}

