#include<stdio.h>
#define N 100000

int main(){
  
  int array[N], n, i, num, temp, partition;
  
  scanf("%d",&n);

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

  num = array[n - 1];
  partition = 0;

  for(i = 0; i < n; i++)
    {
      if(array[i] <= num)
	{
	  temp = array[i];
	  array[i] = array[partition];
	  array[partition] = temp;
	  partition++;
	}
    }

  for(i = 0; i < n; i++)
    {
      if(i != 0)printf(" ");
      if(i == partition - 1)printf("[");
      printf("%d",array[i]);
      if(i == partition - 1)printf("]");
    }

  printf("\n");
  
  return 0;
}

