#include <stdio.h>
#define MAX 100000

int partition(int a,int b);
int K[MAX],kazu;

int main()
{
int i,j;
scanf("%d",&kazu);
for(i=0;i<kazu;i++)scanf("%d",&K[i]);

j=partition(0,kazu-1);
for(i=0;i<kazu;i++)
{
  if(i)printf(" ");
  if(i==j)printf("[");
  printf("%d",K[i]);
  if(i==j)printf("]");
}
printf("\n");
return 0;
}

int partition(int a,int b)
{
int l,i,j,s;
l=K[b];
i=a-1;
for(j=a;j<b;j++)
{
  if(K[j]<=l){
    i++;
    s=K[i];K[i]=K[j];K[j]=s;
  }
}
s=K[i+1];K[i+1]=K[b];K[b]=s;
return i+1;
}

