#include <stdio.h>
#define N 100000
int main() {
  int n,i,j,A[N],key,smallf=0,bigf=0,cnt;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  key=A[n-1];
  j=0;
  for(i=0;i<n-1;i++){
    if(A[i]<=key){
      cnt=A[i];
      A[i]=A[bigf];
      A[bigf]=cnt;
      bigf++;
    }
    else;
  }
  for(i=0;i<n;i++){
    if(i==bigf){
      cnt=A[bigf];
      A[bigf]=A[n-1];
      A[n-1]=cnt;
      printf(" [%d]",A[i]);
      continue;
    }
    if(i>0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  return 0;
}

