#include<stdio.h>

int main()
{
  int i,j,a,b,r,p,q,x,n,A[100000];

  scanf("%d",&n);

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

  r = n - 1;
  p = 0;
  
  x = A[r];
  i = p - 1;

  for(j = p;j <= r - 1;j++)
    {
      if(A[j] <= x)
	{
	  i = i + 1;
	  a = A[i];
	  A[i] = A[j];
	  A[j] = a;
	}
    }
  b = A[i + 1];
  A[i + 1] = A[r];
  A[r] = b;

  q = i + 1;

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

