#include <stdio.h>



int main(){
  int r, x, n, i = 0, j, reserve;
  int A[100000];

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

  r = n-1;

  for(j = 0; j < r-1; j++){
    if(A[j] <= A[r]){
      reserve = A[j];
      A[j] = A[i];
      A[i] = reserve;
      i++;
    }
  }

  reserve = A[i];
  A[i] = A[r];
  A[r] = reserve;

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

  return 0;

}