#include<stdio.h>

int partition();

int a[100000] = {}, n;

int main() {
  int i, p;

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

  p = partition();

  for(i = 0; i < n; i++){
    if(i == p) printf("[%d]", a[i]);
    else printf("%d", a[i]);
    if(i != n-1) printf(" ");
  }
  printf("\n");

  return 0;
}

int partition() {
  int i, j, temp;
  i = -1;

  for(j = 0; j < n-1; j++){
    if(a[j] <= a[n-1]){
      i++;
      temp = a[i];
      a[i] = a[j];
      a[j] = temp;
    }
  }
  temp = a[i+1];
  a[i+1] = a[n-1];
  a[n-1] = temp;
  return i + 1;

}

