#include <stdio.h>
#include <stdlib.h>
int Partition(int*,int,int);
int main() {
  int i,n,j;
  int *A;
  scanf("%d",&n);
  if(n<1 || n>100000) exit(8);
  A=malloc(n*sizeof(int));
  
  for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
      if(A[i]<0 || A[i]>100000) exit(8);
    }
  i = Partition(A,0,n-1);

  for(j=0;j<i;j++)
    {
      printf("%d ",A[j]);
    }
  printf("[%d] ",A[j]);
  for( j= j+1;j<n-1;j++)
    {
      printf("%d ",A[j]);
    }
  printf("%d\n",A[j]);
  return 0;
}
int Partition(int *A,int p,int r){
  int x,i,j,tmp;
  x = A[r];
  j=p-1;
  for(i=0;i<r-p;i++)
    {
      if(A[i]<=x)
	{
	  j++;
	  tmp = A[i];
	  A[i] = A[j];
	  A[j] = tmp;
	}
    }
  A[r] = A[j+1];
  A[j+1] = x;
  return j+1;
}
	  

