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

#define NMAX 100000

int partition (int *,int,int);
int n;

int main (void)
{
  int *a,p,q,r,i;

  //input n
  scanf ("%d",&n);

  //ヒープメモリ確保
  a = malloc(sizeof(int) * NMAX);

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

  p = 0;
  r = n - 1;

  //partition関数へ移動
  q = partition (a,p,r);

  //output
  for (i = 0 ; i < n ; i++){
    if (a[i] != a[q])
      printf ("%d",a[i]);
    else if (a[i] == a[q])
      printf ("[%d]",a[i]);
    if (i < n - 1)
      printf (" ");
    else
      printf ("\n");
  }

  //ヒープメモリ解放
  free(a);

  return 0;
}

int partition (int *a,int p,int r)
{
  int i,j,x,m,n;

  x = a[r];
  i = p - 1;

  for (j = p ; j < r ; j++){
    if (a[j] <= x){
      i = i + 1;
      //a[i]とa[j]を交換
      m = a[i];
      n = a[j];
      a[i] = n;
      a[j] = m;
    }
  }

  //a[i+1]とa[r]を交換
  m = a[i + 1];
  n = a[r];
  a[i + 1] = n;
  a[r] = m;

  return i + 1;
}