#include <stdio.h>

int A[100000];

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

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

  return 0;
}
