#include <stdio.h>
#define N 100001

int main() {
  int n, i, j, x, tmp, A[N];

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

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

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

  return 0;
}