#include<stdio.h>
#define LEN 100010

int partion(int *, int, int);

int main()
{
  int n, A[LEN];
  int p, r;
  int i, j, k;

  //read
  scanf("%d", &n);
  for(i=0; i<n; i++)scanf("%d", &A[i]);

  //partion
  p=0;
  r=n-1;
  j=partion(&A[0], p, r);

  //print
  printf("%d ", A[0]);
  for(i=1; i<n; i++)
    {
      if(i==j)printf("[%d] ", A[i]);
      else printf("%d ", A[i]);
    }
  printf("\n");

  return 0;
}

//partion
int partion(int *A, int p, int r)
{
  int x = A[r];
  int i = p-1;
  int j, k;

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

  k=A[i+1];
  A[i+1]=A[r];
  A[r]=k;
  return i+1;
}