#include<stdio.h>
  
#define N 100001
  
void Partition(int A[], int p, int r)
{
  int x,i,j,tmp;

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

      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  
  tmp = A[i + 1];
  A[i + 1] = A[r];
  A[r] = tmp;

  for(j = 0;j <= r;j++)
  {
    if(j == i + 1)printf("[%d]",A[j]);
    else printf("%d",A[j]);
    if(j != r)printf(" ");
  }
  printf("\n");
 
}
  
int main()
{
  int n,i,s=0,r;
  int A[N];
  
  for(i = 0; i < n; i++)scanf("%d",&A[i]);
  r = n - 1;
  
  Partition(A,s,r);
  
  return 0;
}