#include<stdio.h>
#include<stdlib.h>
 
int partition(int *,int ,int);

int a[100000];

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

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

  //a = (int *)malloc(n*sizeof(int));

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

  q = partition(&a[0],0,n - 1);

  printf("%d",a[0]);
  for(i = 1; i < n; i++) {
    if(a[i] == q ){
      printf(" [%d]",a[i]);
      continue;
    }
    printf(" %d",a[i]);
  }
  printf("\n");
  return 0;
}

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

  x = a[r];
  i = p - 1;
  
  for(j = p; j < r; j++) {
    
    if(a[j] <= x){
      i = i + 1;
      
      v = a[i];
      a[i] = a[j];
      a[j] = v;
    }
  }
  v = a[i+1];
  a[i+1] = a[r];
  a[r] = v;
  
  return j;
}

