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

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

  s=i+1;
  
  for(i=0;i<n;i++){
    if(i==s)
      printf("[%d]",A[i]);
    else
      printf("%d",A[i]);
    if(i<n-1)
      printf(" ");
  }
  printf("\n");
  
  return 0;
}