#include<stdio.h>
#define N 20000000

int A[N];

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(" ");
  }


  return 0;

}


int partition(int p,int r){

int i=0,j,e=0;


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

e = A[r];
A[r] = A[i];
A[i] = e;

return i;
}