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

int partition(int *,int,int);

int main(){
  int n,i,le,ri,arr[100000],basei,base,tmp;

  scanf("%d",&n);
  if(n>100000) exit(2);
  for(i=0;i<n;i++){
    scanf("%d",&arr[i]);
  }
  basei = partition(arr,0,n-1);
  for(i=0;i<n;i++){
    if(i>0) printf(" ");
    if(basei==i) printf("[");
    printf("%d",arr[i]);
    if(i==basei) printf("]");
  }
  printf("\n");
  return 0;
}

int partition(int arr[],int left,int right){
  int i,le=0,ri=0,tmp;
  for(i=left;i<right;i++){
    if(arr[i]<=arr[right]){
      tmp=arr[le];
      arr[le]=arr[i];
      arr[i]=tmp;
      ri++;
      le++;
    }else{
      ri++;
    }
  }
  tmp=arr[le];
  arr[le]=arr[right];
  arr[right]=tmp;
  return le;
}

