#include<stdio.h>

int main(){
  int i,j,k,q,n,x,p=1,r;

  scanf("%d",&n);
  int A[n+1];
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  r=n;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i=i+1;
      k=A[i];
      A[i]=A[j];
      A[j]=k;
    }
  }
  k=A[i+1];
  A[i+1]=A[r];
  A[r]=k;
  q=i+1;
  for(i=1;i<q;i++){
    printf("%d ",A[i]);
  }
  printf("[%d] ",A[q]);
  for(i=q+1;i<n+1;i++){
    if(i<n){
      printf("%d ",A[i]);
    }
    else{
      printf("%d\n",A[i]);
    }
  }
}

