#include <stdio.h>
#define N 1000001

int Partition(int, int );
int A[N];

int main(void){
int i,n,y;
 
 scanf("%d",&n);

 for(i=1;i<=n;i++){
   scanf("%d",&A[i]);
 }
 
 y=Partition(1,(n));
 
 for(i=1;i<n;i++){

   if (i==y){
     printf("[%d] ",A[i]);
   }
   else printf("%d ",A[i]);
 }
 
 printf("%d\n",A[n]);
 
 return 0;
 
}

int Partition(int p, int r){
  int i, j, x, k;
  
  x=A[r];
  i=p-1;
  for(j=p;j<=r-1;j++){

    if(A[j]<=x){
      i++;      
      k=A[i];
      A[i]=A[j];
      A[j]=k; 
    }

  }
  k=A[i+1];
  A[i + 1] = A[r];
  A[r]=k;
  return i+1;
  
}