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

int partition(int *,int,int);

int main(void){

  int *A,n,p=0,q,r,i;

  scanf("%d",&n);
  A = malloc(sizeof(int)*n);

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

  r = n-1;
  q = partition(A,p,r);
  
  for(i=0;i<q;i++){
    printf("%d ",A[i]);
  }
  printf("[%d] ",A[i]);
  for(i=q+1;i<=r;i++){
    printf("%d",A[i]);
    if(i!=r){
      printf(" ");
    }
  }
  printf("\n");
  return 0;
}

int partition(int *A,int p,int r){

  int i,j,x,temp;

  x = A[r];
  i = p-1;

  for(j=p;j<r;j++){
    if(A[j] <= x){
      i = i+1;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
    }
  }
  temp = A[i+1];
  A[i+1] = A[r];
  A[r] = temp;
  return i+1;
}