#include<stdio.h>
#define N 100000
int main(){
  int i,j=0,a[N],n,tmp,p,q;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
    for(i=0;i<n;i++){
      if(a[i]<=a[n-1]){
	if(i==n-1){
	tmp = a[i];
	a[i] = a[j];
	a[j] = tmp;
	p = j-1;
	q = p+1;
	break;
	}
	tmp = a[i];
	a[i] = a[j];
	a[j] = tmp;
	j++;
      }
    }
  for(i=0;i<n;i++){
    printf("%d",a[i]);
    if(i==p)printf(" [");
    if(i==q)printf("] ");
    if(i!=n-1 && i!=p && i!=q)printf(" ");
    else if(i==n-1) printf("\n");
  }
  return 0;
}

