#include <stdio.h>
int A[10000];
int partition(p, r){
  int x = A[r];
  int i = p-1,j;
  int y;
  for (j = p;j < r;j++){
    if (A[j] <= x){
      i = i+1;
      y=A[j];
      A[j]=A[i];
      A[i]=y;
    }
  }
  A[r]=A[i+1];
  A[i+1]=x;
  return i+1;
}

int main(){
  int i,n,q;
  scanf("%d",&n);
  for(i=0;i < n;i++){
    scanf("%d",&A[i]);
  }
  q=partition(0,n-1);

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

  return 0;
}


