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

int Partition(int, int);

int A[100000];

int main(){
  int i, n, standard;

  scanf("%d",&n);
  if( n<1 || 100000<n ) exit(0);

  for( i=0 ; i<n ; i++ ){
    scanf("%d",&A[i]);
    if( A[i]<0 || 100000<A[i] ) exit(1);
  }

  standard = Partition(0, n);

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

int Partition(int p, int r){
  int i, j, x, tmp;

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

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

  return i+1;
}