#include<stdio.h>

#define MAX 100000

int a[MAX];
int n;

int partition(int,int);

int main()
{
  int i,q;

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++)
    {
      scanf("%d",&a[i]);
    }

  q = partition(0,n - 1);

  for(i = 0 ; i < n ; i++)
    {
      if(i)printf(" ");

      if(i == q)printf("[");
      printf("%d",a[i]);
      if(i == q)printf("]");
    }
  printf("\n");

  return 0;
  
}

int partition(int p,int r)
{
  int x,i,j,t;

  x = a[r];
  i = p - 1;
  for(j = p ; j < r ; j++)
    {
      if(a[j] <= x)
	{
	  i++;
	  t = a[i];
	  a[i] = a[j];
	  a[j] = t;
	}
    }

  t = a[i + 1];
  a[i + 1] = a[r];
  a[r] = t;

  return i + 1;
}

