#include<stdio.h>

int main (){
  int a,b[100000],c=0,d,i;
  scanf("%d",&a);
  for(i=0;i<a;i++)scanf("%d",&b[i]);
  for(i=0;i<a-1;i++){
    if(b[a-1]>=b[i]){d=b[i];b[i]=b[c];b[c]=d;c++;}
  }
  d=b[a-1];b[a-1]=b[c];b[c]=d;
  for(i=0;i<a;i++){
    if(i==c)printf("[%d]",b[i]);
    else printf("%d",b[i]);
    if(i==a-1)printf("\n");
    else printf(" ");
  }
}

