#include <stdio.h>
#define N 100000

int main(){
  int n,i,put,base,s=0,f=0;
  int a[N];

  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%d",&a[i]);
  }
  base = a[n-1];
  for(i = 0;i < n-1;i++){
    if(base == a[i]) f++;
    if(base >= a[i]){
      put = a[i];
      a[i] = a[s];
      a[s] = put;
      s++;
    }
  }
    put = a[n-1];
    a[n-1] = a[s];
    a[s] = put;

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

  return 0;
}

