#include<stdio.h>
int partition(int a[],int p,int r){
  int x,i,j,v;
  x=a[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(a[j]<=x){
      i++;
      v=a[i];
      a[i]=a[j];
      a[j]=v;
    }
  }
  v=a[i+1];
  a[i+1]=a[r];
  a[r]=v;
  return i+1;
}

int main(){
  int i,n,a[100000],p;

  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&a[i]);
  p=partition(a,0,n-1);
  for(i=0;i<n-1;i++){
    if(i==p)printf("[%d] ",a[i]);
    else printf("%d ",a[i]);
  }
  if(n-1==p)printf("[%d]\n",a[n-1]);
  else printf("%d\n",a[n-1]);
  return 0;
}

