#include <stdio.h>

int main()
{
  int i,j,n,x,r,p;
  int A[100000],temp,temp2;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  p=0;
  r=n-1;
  //partition(A, p, r)
  //for(i=0;i<20;i++){   
  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;
    }
  }
  temp2=A[i+1];
  A[i+1]=A[r];
  A[r]=temp2;
  //}

  for(j=0;j<i+1;j++) printf("%d ",A[j]);
  printf("[%d]",A[i+1]);
  for(j=i+2;j<n;j++) printf(" %d",A[j]);
  printf("\n");
  
  return 0;
}