#include<stdio.h>

int A[2000000];
int i,p=1,r,j,x,n,t=0;
int pqrtition();

int main (void){
  
  scanf("%d",&r);
  for(i=1;i<=r;i++){
    scanf("%d",&A[i]);
  }
  partition();

  for(i=1;i<=t;i++){
    printf("%d ",A[i]);
  }
  printf("[%d] ",A[i]);
  for(i=t+2;i<=r;i++){
    printf("%d",A[i]);
    if(i!=r)printf(" ");
  }
  printf("\n");

  return 0;
}

int partition(){
  x=A[r];
  i=p-1;
  if(i>r)return -1;
  for(j=p;j<=r-1;j++){
    if(A[j]<=x){
      i=i+1;
      n=A[i];
      A[i]=A[j];
      A[j]=n;
      t++;
    }
  }
  n=A[i+1];
  A[i+1]=A[r];
  A[r]=n;
  p++;
  return i++;
}