#include<stdio.h>

#define MAX 100000
int partition(int *,int ,int );

int main()
{
  int k,n,q;
  int A[MAX+1];

  scanf("%d",&n);
  for(k=0;k<n;k++)
    {
      scanf("%d",&A[k]);
    }
 
  q=partition(A,0,n-1);

  for(k=0;k<n;k++)
    {
      if(k>0)printf(" ");
      if(k==q)printf("[");
      printf("%d",A[k]);
      if(k==q)printf("]");
    }
  printf("\n");

  return 0;

 
}

int partition(int A[],int p,int r)
{
  int x,y,i,j;
 
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++)
    {
      if(A[j]<=x)
	{
	  i=i+1;
	  y=A[i];
	  A[i]=A[j];
	  A[j]=y;
	}
    }
  y=A[i+1];
  A[i+1]=A[r];
  A[r]=y;
  return i+1;
}

