//Partition

#include<stdio.h>
#define N 100000

int main()
{
  int n = 0;
  int i = 0;
  int arr[N];
  int a = 0;
  int b,k;
  int x = 0;
  int swit = 0;
  int p = 0;
  int y = 0;
  
  
  //input data
  scanf("%d",&n);
  for(i = 0; i < n; i++)
    {
      scanf("%d",&arr[i]);
    }

  //work
 
  a = p - 1;
  x = arr[n - 1];


  for(b = p; b <= n - 1; )
    {
     
      if(b == n - 1)
	{
	  swit = arr[b];
	  arr[b] = arr[a + 1];
	  arr[a + 1] = swit;

	  y = a + 1;
	  
	}
    
      if(arr[b] <= x)
	{
	  a++;
	  swit = arr[b];
	  arr[b] = arr[a];
	  arr[a] = swit;
	  b++;
	}
      if(arr[b] > x)
	{
	  b++;
	}
      
    }

  //output data
  printf("%d",arr[0]);
  for(k = 1; k < n; k++)
    {
      if(k == y)
	{
	  printf(" [");
	  printf("%d",x);
	  printf("]");
	}
      if(k != y)
	{	
	  printf(" %d",arr[k]);
	}
    }
  printf("\n");
  
  return 0;
}

