#include<stdio.h>

int A[100001];
int Partition(int p,int r){
  int i,j,x,key;
  x=A[r];
  i=p-1;
  
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      key=A[i];
      A[i]=A[j];
      A[j]=key;
    }
  }
  
  key=A[i+1];
  A[i+1]=A[r];
  A[r]=key;
  return i+1;
}

int main(){
 
  int n,i,k;

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

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