#include<stdio.h>
#define MAX 100000

int partition(int X[],int n,int p,int r){
  int y,z;
  int i,tmp;
  y = X[r];
  z = p - 1;
  
  for (i=p; i<r; i++){
    if ( X[i] <= y ){
      
      z++;
      tmp = X[z];
      X[z] = X[i];
      X[i] = tmp;
      
    }
  }
  tmp = X[z+1];
  X[z+1] = X[r];
  X[r] = tmp;
  return z+1;
}


int main(){
  int x[MAX],n,number;
  int i;
  scanf("%d",&n);
  for ( i=0; i<n; i++ )
    scanf("%d",&x[i]);
  
  number=partition(x,n,0,n-1);

  for ( i=0; i<n; i++) {
    if (i!=0)
      printf(" ");
    
    if (i==number)
      printf("[");
    
    printf("%d",x[i]);
    
    if (i==number)
      printf("]");
  }
  printf("\n");

  return 0;
}

