#include<stdio.h>
#define M 100000

int S[M];

int partition(int,int);

int main(){

  int i,n,m;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&S[i]);
    }
  m = partition(0,n-1);
  
  for(i=0;i<n;i++)
    {
      if(i) printf(" ");
      if(i==m)printf("[");
      printf("%d",S[i]);
      if(i==m)printf("]");
    }
  printf("\n");
  return 0;
}
int partition(int p,int r)
{
  int x,i,j,tmp=0;

  x = S[r];
  i = p-1;
  for(j=p;j<r;j++)
    {
      if(S[j]<=x)
	{
	  i = i+1;
	  tmp=S[i];
	  S[i]=S[j];
	  S[j]=tmp;
	}
    }
  tmp=S[i+1];S[i+1]=S[r];S[r]=tmp;
  return i+1;
}

      