#include<stdio.h>

int main(){
  int A[100000];
  int n,i,j,p,r,x,num;

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

  r = n-1;
  p = 0;
  x = A[r];
  i = p-1;

  for(j = p; j < r;j++){
    if(A[j] <= x){
      i = i+1;
      num = A[i];
      A[i] = A[j];
      A[j] = num;
    }
  }
  num = A[i+1];
  A[i+1] = A[r];
  A[r] = num;

  for (j = 0 ;j <= i; j++) printf("%d ",A[j]);
  printf("[%d] ",A[i+1]);
  for (j = i + 2 ;j < r; j++) printf("%d ",A[j]);
  printf("%d\n",A[r]);
}

