#include<stdio.h>
#define N 100000


int partition(int *A,int c,int d){
  int x,y,i,j;
  x=A[d];
  i=c-1;
  for(j=c;j<d;j++){
    if(A[j]<=x){
      i++;
      y=A[i];
      A[i]=A[j];
      A[j]=y;
    }
  }
  y=A[i+1];
  A[i+1]=A[d];
  A[d]=y;
  return i+1;
}


int main(){
  int A[N+1],b,n,i;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    
    scanf("%d",&A[i]);
  }
  b=partition(A,1,n);
  for(i=1;i<b;i++){
    
    printf("%d ",A[i]);
    
  }
  
  printf("[%d] ",A[b]);
  
  for(i=b+1;i<n;i++){
    
    printf("%d ",A[i]);
    
  }
  printf("%d\n",A[n]);
  return 0;
}

