#include<stdio.h>

int partition(int *,int);

int main()
{
  int n,i,q;
  scanf("%d",&n);
  int A[n];
  for(i = 1;i <= n;i++)
    {
      scanf("%d",&A[i]);
    }
  q = partition(A,n);
  for(i = 1;i < q;i++)
    {
      printf("%d ",A[i]);
    }
  printf("[%d] ",A[q]);
  for(i = q+1;i <= n;i++)
    {
      printf("%d",A[i]);
      if(i != n)
	{
	  printf(" ");
	}
    }
  printf("\n");
}

int partition(int A[],int n)
{
  int x,i,j,temp;
  x = A[n];
  i = 0;
  for(j = 1;j < n;j++)
    {
      if(A[j] <= x)
	{
	  i = i+1;
	  temp = A[i];
	  A[i] = A[j];
	  A[j] = temp;
	}  
    }
    temp = A[i + 1];
    A[i + 1] = A[n];
    A[n] = temp;
    
  return i+1;
}

