#include<stdio.h>


int main(){
  int x,i,A[100000],p,n,r,key,j;

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

  r=n-1;
  p=0;
  
  x=A[r];
  i=p-1;
  for(j=p;j<r-1;j++){
    if(A[j]<=x){
      i++;
      key=A[i];
      A[i]=A[j];
      A[j]=key;
    }
  }
  key=A[i+1];
  A[i+1]=A[r];
  A[r]=key;


  for(j=0;j<=i;j++){
    printf("%d ",A[j]);
  }
  printf("[%d] ",A[i+1]);
  for(j++;j<n-1;j++){
    printf("%d ",A[j]);
  }
  printf("%d\n",A[n-1]);
  return 0;
}

    

      

