#include<stdio.h>
int main(){
  int q,temp,i,j,n,a[100000],x;

  scanf("%d",&n);

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

  x=a[n];
  i=0;
  for(j=1;j<=n-1;j++){
    if(a[j]<=x){
      ++i;
      temp=a[i];
      a[i]=a[j];
      a[j]=temp;
    }
  }
  temp=a[i+1];
  a[i+1]=a[n];
  a[n]=temp;
  q=i+1;

  for(i=1;i<=n;i++){
    if(i-1)printf(" ");
    if(i==q)printf("[");
    printf("%d",a[i]);
    if(i==q)printf("]");
  }
  printf("\n");

  return 0;
}
  

