#include<stdio.h>

int main(){
  int n,i,A[100000],x,ch,j;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  x=A[n-1];
  i=-1;
  for(j=0;j<n-1;j++){
    if(A[j]<=x){
      i++;
      ch=A[i];
      A[i]=A[j];
      A[j]=ch;
    }
  }
  ch=A[i+1];
  A[i+1]=A[n-1];
  A[n-1]=ch;

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

  return 0;
}

