#include<stdio.h>
int partition(int p, int r);

int A[100000],n;

int main(){
  int i,k;
  
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);

  k=partition(0,n-1);
  
  printf("[%d] ",A[k]);
  
  for(i=k+1;i<n-1;i++)
    printf("%d ",A[i]);
  printf("%d\n",A[i]);
  
  return 0;
}
int partition(int p, int r){
  int tmp,x,i,j;
  
  x = A[r];
  i = p-1;
  for (j =p;j<r;j++){
    if (A[j] <= x){
      i = i+1;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
      printf("%d ",A[i]);
    }
  }
  
  tmp=A[r];
  A[r]=A[i+1];
  A[i+1]=tmp;

  return i+1;
}
	   

