#include <stdio.h>

int space[100000];

int partition(int *toPart, int p, int r) {
  int x=toPart[r], i=p-1, swap, j;
  for ( j = p; j < r; j++ )
    if ( toPart[j] <= x ) {
      i++;
      swap = toPart[i];
      toPart[i] = toPart[j];
      toPart[j] = swap;
    }
  swap = toPart[i+1];
  toPart[i+1] = toPart[r];
  toPart[r] = swap;
  return i+1;
}

int main(void) {
  int n, i, posn;
  scanf(" %d", &n);
  for ( i = 0; i < n; i++ )
    scanf(" %d", space+i);
  posn = partition(space, 0, n-1);
  for ( i = 0; i < n; i++ ) {
    if ( i == posn )
      printf("[%d]", space[i]);
    else
      printf("%d", space[i]);
    printf("%c", i==n-1 ? '\n' : ' ');
  }
  return 0;
}

