#include <stdio.h>

void swap(int *x, int *y){ int t = *x; *x = *y; *y = t;}

int partition(int *a, int p, int r){
  int x , i, j;
  x = a[r];
  i = p - 1;
  for(j = p; j < r; ++j)
    if(a[j] <= x)
      swap(&a[++i], &a[j]);
  swap(&a[++i], &a[r]);
  return i;
}

int main(){
  int  n, a[100001], i, r, q;

  scanf("%d", &n);
  for(i = 0;i < n; ++i) scanf("%d", a + i);
  q = partition(a, 0, n - 1);

  for(i = 0; i < n; i++){
    if(i != 0) putchar(' ');
    printf(i != q ? "%d" : "[%d]", a[i]);
  }
  puts("");
  return 0;
}

