#include<stdio.h>

int main(){
  int i, j, r, n, temp, index;
  int A[100001];
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);
  r=n-1;
  i=0-1;
  for(j=0;j<r;j++){
    if(A[j]<=A[r]){
      i++;
      temp=A[i];
      A[i]=A[j];
      A[j]=temp;
    }
  }
  temp=A[i+1];
  A[i+1]=A[r];
  A[r]=temp;
  index=i+1;
  for(i=0;i<n;i++){
    if(i==index) printf("[%d] ",A[i]);
  else if(i==n-1) printf("%d\n",A[i]);
  else printf("%d ",A[i]);
  }

  return 0;
}

