#include<stdio.h>
#include<stdlib.h>

#define key int





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



int main(){
  int n;
  scanf("%d",&n);
  int *A;
  int i,k;
  A=malloc(n*sizeof(int));
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  k=partition(A,0,n-1);
  for(i=0;i<k;i++) printf("%d ",A[i]);
  printf("[%d] ",A[k]);
  for(i=k+1;i<n-1;i++)  printf("%d ",A[i]);
  printf("%d\n",A[n-1]);
  return 0;
}