#include<stdio.h>
#include<stdlib.h>
#define MAX 100001

main()
{
  short *A, change, x;
  int i, j, r, n, p=0, kakko;

  scanf("%d", &n);
  A = malloc(sizeof(short)*n + 1);

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

  r = i-1;
  x = A[r];
  i = p - 1;
  for(j=p; j<r; j++)
    {
      if(A[j] <= x)
	{
	  i = i + 1;
	  change = A[j];
	  A[j] = A[i];
	  A[i] = change;
	}
    }
  change = A[r];
  A[r] = A[i+1];
  A[i+1] = change;
  kakko = i+1;

  for(i=0; i<n; i++)
    {
      if(i == kakko)
	{
	  printf("[%d] ", A[i]);
	  continue;
	}

      printf("%d", A[i]);
      if(i != n-1)
	{
	  printf(" ");
	}
    }
  printf("\n");

  return 0;
}