#include <stdio.h>

int main(){

  int i,j,n,A[100000],temp,p,par;

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

  p = 0;
  i = p-1;

  for(j=p;j<n-1;j++){
    if(A[j] <= A[n-1]){
      i = i+1;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
    }
  }
  temp = A[i+1];
  A[i+1] = A[n-1];
  A[n-1] = temp;

  par = i+1;

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

  if(n-1 == par){
      printf("[%d]\n",A[n-1]);
    }else{
      printf("%d\n",A[n-1]);
  }
  return 0;
}
 