#include<stdio.h>
#include<stdlib.h>

#define N 100000

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

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

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

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

  for(j = 0; j < n; j++){
    if(j > 0)
    printf(" ");

    if(j == q)
      printf("[");
    printf("%d", A[j]);
    if(j == q)
      printf("]");
  }

  printf("\n");

  return 0;
}

