#include <stdio.h>
#include <stdlib.h>

#define MAX 100000

int partition(int);
void swap(int, int);
void printa(int, int);

int *a;

int main(){
 
  int n, i, p;

  scanf("%d", &n);

  a = malloc(sizeof(int)*n+1);

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

int partition(int n)
{
  int i, count=0;
  
  for( i = 0; i < n-1; i++)
  {
    if(a[i] <= a[n-1])
      {
	if(i >= count)
	  {
	    swap(i,count);
	    count++;
	  }
      }


  }
  if(a[count] > a[n-1])swap(count,n-1);
  else swap(++count,n-1);
  
    return count;
}
void swap(int i, int count)
{
  int temp;

  temp = a[i];
  a[i] = a[count];
  a[count] = temp;

  return;
}

void printa(int p, int n)
{
  int i;
  
for(i = 0; i < p; i++)
    {
      printf("%d ", a[i]);
    }

 printf("[%d] ", a[i]);
 i++;
 
  for(; i < n-1; i++)
    {
      printf("%d ", a[i]);
    }
  printf("%d", a[i]);
  printf("\n");
  

}

