#include<stdio.h>

int main()
{

  int n,A[100000],i,j,pivot,small,big,swap;
  scanf("%d",&n);
  for(i= 0 ;i<n;i++)scanf("%d",&A[i]);
  i = -1;
  
    for(j = 0 ;j <n ; j++)
      {
	if(A[j] <= A[n-1])
	  {
	    i++;
	    swap = A[j];
	    A[j] = A[i];
	    A[i] = swap;
	  }
	
      }
  A[i+1] = A[n-1];
  
  for(i = 0 ; i<n ; i++)
    {
      if(i == n -1)
	{
	  printf("%d\n",A[i]);
	  break;
	}
      printf("%d ",A[i]);
	}
  
}

