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

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

  scanf("%d",&n);

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

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

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

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

