#include <stdio.h>

int main(){
  int n,i,j,k,A[100000];
  int x,p=0,r,temp;
  scanf("%d",&n);
  for(i=0;i<n;i++){
  scanf("%d",&A[i]);
  }
  r = n-1;

  x = A[r];
  i = p-1;
  for(j=p;j<=r-1;j++){
    if (A[j]<=x) {
      i=i+1;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
    }
  }
    temp = A[i+1];
    A[i+1] = A[r];
    A[r] = temp;

  

  for(k=0;k<n-1;k++){
    if(A[k] == x) printf("[%d] ",A[k]);

else    printf("%d ",A[k]);

  }


  printf("%d\n",A[k]);




  return 0;
}