#include<stdio.h>
#define n 100001
//void swap(int ,int);

int A[n],key;
int partition(int ,int);
/*void swap(int x, int y)
{
  int temp;
  temp = x;
  x = y;
  y = temp;
}
*/
int main()
{
  int num,i;
  scanf("%d",&num);

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

  key = partition(0,num-1);

  printf("%d",A[0]);

  for(i = 1 ; i < num ; i++)
    {
      if(key == i)printf(" [%d]",A[i]);
      else printf(" %d",A[i]);
    }

  printf("\n");


  return 0;
}


int partition(int p,int r)
{
  int x,i,j;
  int temp;

  x = A[r];
  i = p - 1;
  for(j = p ; j <= r-1 ; j++)
    {
      if(A[j] <= x){
	i = i + 1;
	temp = A[i];
	A[i] = A[j];
	A[j] = temp;
	
	//swap(A[i],A[j]);
      }
    }
  //swap(A[i+1],A[r]);
 
  temp = A[i+1];
  A[i+1] = A[r];
  A[r] = temp;




 return i+1;
}