#include<stdio.h>
#define MAX 100000

int partition(int K[], int n, int o, int W){
  int x, i, j, t;
  x = K[W];
  i = o-1;
  for (j=o;j<W;j++){
    if (K[j]<=x){
      i++;
      t=K[i];K[i]=K[j];K[j]=t;
    }
  }
  t=K[i+1];K[i+1]=K[W];K[W]=t;
  return i+1;
}
main(){
  int K[MAX], n, i, a;
  scanf("%d", &n);
  for (i=0;i<n;i++) scanf("%d", &K[i]);
  a = partition(K, n, 0, n-1);
  for (i=0;i<n;i++) {
    if ( i ) printf(" ");
    if ( i == a ) printf("[");
    printf("%d", K[i]);
    if ( i == a ) printf("]");
  }
  printf("\n");

  return 0;
}

