#include <stdio.h>
#include <stdlib.h>

int main(){

  int a,i,j,tmp,n,x,A[100000];

  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++;
      tmp = A[j];
      A[j] = A[i];
      A[i] = tmp;
    }
  }
  tmp = A[n-1];
  A[n-1] = A[i+1];
  A[i+1] = tmp;
  a = i+1;
  for(i=0;i<n;i++){
    if(i)printf(" ");
    if(i==a)printf("[%d]",A[i]);
    else printf("%d",A[i]);
  }
  printf("\n");
  return 0;
}

