#include<stdio.h>

int main(){
  int i,p,r,n,q=0,x,s=0,u=0,j;

  scanf("%d",&n);
  int A[n+1];
  A[0]=0;
  r=n;
  for(i=1;i<n+1;i++){
    scanf("%d",&A[i]);
  }
  p=1;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i=i+1;
      s=A[i];
      A[i]=A[j];
      A[j]=s;
    }
  }
  u=A[i+1];
  A[i+1]=A[r];
  A[r]=u;
  q=i+1;
  for(i=1;i<q;i++){
    printf("%d ",A[i]);
  }
  printf("[%d] ",A[q]);
  for(i=q+1;i<n+1;i++){
  if(i<n){
    printf("%d ",A[i]);
  }
  else printf("%d",A[i]);
  }
  printf("\n");
  return 0;
  
}




