#include<stdio.h>
#define N 100000

int partition( int a[] , int p , int r ){
  int i = -1;
  int j;
  int key;
  int count = a[r];

  for( j = 0 ; j < r ; j++ ){
    if(count>=a[j]){
      i++;
      key = a[i];
      a[i] = a[j];
      a[j] =  key;
    }
  }
  key = a[r];
  a[r] = a[i+1];
  a[i+1] = key;
  return i+1;
}

int main(){
  int i,n,count=0;
  int a[N];

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

  count = partition(a,0,n-1);

  for(i=0;i<n-1;i++){
    if(count==i) printf("[%d] ",a[i]);
    else printf("%d ",a[i]);
  }

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

  return 0;
}