#include<stdio.h>

#define NUM 100000

int main(){
  int i,j,n,p=0,r,x,y;
  int A[NUM];

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

  for(j=0;j<r-1;j++){
    if(A[j]<=x){
      i=i+1;
      y=A[i];
      A[i]=A[j];
      A[j]=y;
    }
  }
  y=A[i+1];
  A[i+1]=A[r-1];
  A[r-1]=y;
  
    
  
  
  for(i=0;i<n/2+1;i++){
    printf("%d",A[i]);
    if(i!=n){
      printf(" ");
    }
  }
  printf("[%d]",A[i]);
  if(i==n/2+1) printf(" ");
  for(i=i+1;i<n;i++){
    printf("%d",A[i]);
    if(i!=n){
      printf(" ");
    }
  }
  

  printf("\n");




  return 0;
}

