#include <stdio.h>



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

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

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

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

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

  return 0;

}