#include<stdio.h>
int partition(int*,int,int);
int main(){
  int N,i,j;
  scanf("%d",&N);
  int a[N];
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
  }
  j=partition(a,0,N-1);
  printf("%d",a[0]);
  for(i=1;i<N;i++){
    if(i==j)printf(" [%d]",a[i]);
    else printf(" %d",a[i]);
  }
  printf("\n");
  return 0;
}
 int partition(int A[],int p,int r){
   int i,x,j,d,e;
  x=A[r];
  i=p-1;
  for(j=p;j<=r-1;j++){
    if(A[j]<=x){
      i=i+1;
      e=A[i];
      A[i]=A[j];
      A[j]=e;
    }
  }
  d=A[i+1];
  A[i+1]=A[r];
  A[r]=d;
  return i+1;
}

