#include <stdio.h>
#define MAX 100000

int array[MAX];

int partition(int,int);

int main(){

  int n, i, ans;

  scanf( "%d", &n);

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

  ans = partition(0,n-1);

  for( i=0; i<ans; i++){
    printf("%d ", array[i]);
  }

  printf("[%d] ", array[ans]);

  for( i=ans+1; i<n-1; i++){
    printf("%d ", array[i]);
  }

  printf("%d\n", array[n-1]);

  return 0;
}

int partition(int p, int r){

  int x, i, j, tmp;

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

  for( j=1; j<r; j++){
    if( array[j] <= x ){
      i++;
      tmp = array[i];
      array[i] = array[j];
      array[j] = tmp;
    }
  }

  tmp = array[i+1];
  array[i+1] = array[r];
  array[r] = tmp;
  
  return i+1;
}