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

int main(){
  int n;
  int *A;
  int x;
  int i,j;
  int p;
  int r;
  int change;

  
  scanf("%d",&n);
  A=(int *)malloc((n+1)*sizeof(int));

  for(i=1;i<=n;i++)scanf("%d",&A[i]);
  r=n;
  x=A[r];
  p=1;
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      change=A[i];
      A[i]=A[j];
      A[j]=change;
    }
  }
  change=A[i+1];
  A[i+1]=A[r];
  A[r]=change;

  for(j=1;j<i+1;j++)printf("%d ",A[j]);
  printf("[%d] ",A[j]);
  for(j=j+1;j<n;j++)printf("%d ",A[j]);
  printf("%d\n",A[j]);
  return 0;
}


  

