#include<stdio.h>

int A[20000000];

int partition(int, int);

main(){
  int k, r, mid;
  int i;

  scanf("%d", &k);

  for(i = 0; i < k; i++){

    scanf("%d",&A[i]);

  }

  r = k - 1;

  mid = partition(0, r);

  for(i =0; i < mid; i++){

    printf("%d ",A[i]);

  }
  printf("[%d] ", A[mid]);

  for(i = mid+1; i <= r; i++){
    printf("%d", A[i]);
    if(i != r)printf(" ");
  }

  printf("\n");

  return 0;

}


int partition(int p, int r){

int i = 0 , j, ex=0;


for(j = p; j < r; j++){
  if(A[j] <= A[r] ){
    
    ex = A[i];
    A[i] = A[j];
    A[j] = ex;
    i++;
  } 
 }

ex = A[r];
A[r] = A[i];
A[i] = ex;

return i;
}