#include<stdio.h>
#define MAX 1000000

int A[MAX];
int Partition(int);

int Partition(int r)
{
  int i=-1,j=0,q,hold;
  q = A[r];
  for( j = 0; j < r; j++)
    {
      if( A[j] <= q )
	{
	  i++;
	  hold = A[i];
	  A[i] = A[j];
	  A[j] = hold;
	  
	}
    }
  hold = A[i+1];
  A[i+1] = A[r];
  A[r] = hold;

  return i+1;  
}

int main()
{
  int i,n,key;

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

  key = Partition(n-1);
  for( i = 0; i < n-2; i++ )
    {
      if( i == key )
	printf("[%d] ",A[i]);
      else
	printf("%d ",A[i]);
    }
  printf("%d\n",A[n-1]);

  return 0;
}

