#include <stdio.h>
#define n_MAX 100001
int main(){
  int A[n_MAX];
  int x,n,j,tmp1=0,tmp2=0,i;
  scanf("%d",&n);
  for(i = 1;i<=n ;i++){
    scanf("%d",&A[i]);
  }
  
  x = A[n];
  i = 0;
  for(j = 1 ;j<=n-1;j++){
    if(A[j] <=x){
      i = i+1;
    tmp1 = A[j];
    A[j] =A[i];
    A[i] =tmp1;
    }
  }
    tmp2 = A[n];
    A[n] = A[i+1];
    A[i+1] = tmp2;
    
  for(j = 1 ;j<=n ;j++){
    if(j == n){
      printf("%d\n",A[j]);}
    if(j==i+1){ printf("[%d] ",A[j]);}
    else printf("%d ",A[j]);
  }
  return 0;
}

