#include<stdio.h>
int partition(int*, int, int);
main(){
  int a[100001],i,n,han;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d", &a[i]);
    }
  han = partition(a,0,n-1);
  for(i=0;i<n;i++)
    {
      if(i == han)
	{
	  printf("[%d]",a[i]);
	}
      else
	{
          printf("%d",a[i]);
	}
	if(i!=n-1)
	  {
	  printf(" ");
	  }
     }
  printf("\n");
  return 0;
}

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