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

int main(){
  int *A,p,r,n,x,i,j,k;

  scanf("%d",&n);
  A = malloc(sizeof(int)*(n+1));
  for(i=1; i<=n; i++)
    scanf("%d",&A[i]);
  p = 1;
  r = n;

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

  j = i+1;

  for(i=1; i<=n; i++){
    if(i>1) printf(" ");
    if(i==j) printf("[");
    printf("%d",A[i]);
    if(i==j) printf("]");
  }
  printf("\n");
  return 0;
}