#include <stdio.h>

int main(){
  int n,i,a[100000],p=0,q=0,x,t;

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

  x=a[n-1];
  for(i=0;i<n;i++){
    if(a[i]<=x){
      t = a[i];
      a[i] = a[p];
      a[p] = t;
      p++;
    }
  }

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

  return 0;
}

