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


int main(){
int *A;
int n,i,j,x,p,swap[2],k;

  scanf("%d",&n);

  A=malloc(sizeof(int)*n+1);

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

  x=A[n];
  i=0;

  for(j=1;j<n;j++){
    if(A[j]<=x){
      i++;
      swap[0]=A[i];
      A[i]=A[j];
      A[j]=swap[0];
     }
}
      swap[1]=A[i+1];
      A[i+1]=A[n];
      A[n]=swap[1];

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

  return 0;
}


   

  