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

int main(){
  int n,i,j,x,w;
  int *A;
  scanf("%d",&n);
  A=(int *)malloc((n+1)*sizeof(int));
  for(i=1;i<=n;i++) scanf("%d",&A[i]);
  x=A[n];
  i=0;
  
  for(j=1;j<=n-1;j++){
    
    if(A[j]<=x){
      i++;
      w=A[i];
      A[i]=A[j];
      A[j]=w;
    }
  }
  w=A[i+1];
  A[i+1]=A[n];
  A[n]=w;
  
  for(i=1;i<=n;i++){
    if(A[i]==x)printf("[%d]",A[i]);
    else printf("%d",A[i]);
    if(i!=n) printf(" ");
  }
  printf("\n");
  return 0;
}

