#include<stdio.h>

void func(int *,int);
int r,a[2000001];

int main(){
  int x,i,j;

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

  func(a,x);

  return 0;
}

void func(int *a,int x){
  int i=1,j=1,n,key = x;
  while(j <= r){
    if(a[j] <= x){
        n = a[i];
        a[i] = a[j];
        a[j] = n;
      i++;
    }
    j++;
  }

  for(i=1;i<=r;i++){
    if(i>1) printf(" ");
    if(a[i] == key){
      printf("[%d]",a[i]);
    }
    else printf("%d",a[i]);
  }
  printf("\n");
}

