#include <stdio.h>
#define MAX 100000
//int partition(A, p, r)

int main()
{
  int n,c,A[MAX],x,i=0,j,chang1,chang2,k;
  scanf("%d",&n);
  for(c=1;c<=n;c++)
    {
      scanf("%d",&A[c]);
    }
  x=A[n];
  //i=p-1;
  for (j=1;j<=n-1;j++)
    {
      if (A[j]<=x)
	{
	  i = i+1;
	  //A[i] と A[j] を交換
	  chang1=A[i];
	  A[i]=A[j];
	  A[j]=chang1;
	}
    }
  chang2=A[i+1];
  A[i+1]=A[n];
  A[n]=chang2;
  for(k=1;k<=n;k++)
    {
      if(k==i+1)
	{
	  printf("[%d] ",A[k]);
	}
      else if(k==n)
	{
	  printf("%d",A[k]);
	}
      else
	{
	  printf("%d ",A[k]);
	}
    }
  printf("\n");
  return 0;
}

/*
  partition(A, p, r)
  {
  int chang1,chang2;
  x=A[r];
  //i=p-1;
  for (j=1;j<=r-1;j++)
  {
  if (A[j]<=x)
  {
  i = i+1;
  //A[i] と A[j] を交換
  chang1=A[i];
  A[i]=A[j];
  A[j]=chang1;
  }
  }
  //A[i+1] と A[r] を交換
  chang2=A[i+1];
  A[i+1]=A[r];
  A[r]=chang2;
  return i+1;
  }
  for(k=1;k<=n;k++)
  {
  if(k==i+1)
  {
  printf("[%d] ",A[k]);
  }
  else if(k==n)
  {
  printf("%d",A[k]);
  }
  else
  {
  printf("%d ",A[k]);
  }
  }
*/

