#include<stdio.h>

int main()
{

  int i, j, n, x, y, A[100000];

  scanf("%d", &n);

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

  x = A[n-1];
  i = -1;

  for(j = 0; j < n-1; j++){
    if(A[j] <= x){
      i = i + 1;
      y = A[i];
      A[i] = A[j];
      A[j] = y;
    }
  }
  y = A[i+1];
  A[i+1] = A[n-1];
  A[n-1] = y;

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

  printf("%d\n", A[n-1]);

  return 0;
}