
#include <stdio.h>
#define A 100001

int partition(int a[],int b,int c){
  int x,i,t,j;
  x=a[c];
  i=b-1;

  for(j=b;j<c;j++){
    if(a[j]<=x){
      i++;
      t=a[i];
      a[i]=a[j];
      a[j]=t;
    }
  }
  t=a[i+1];
  a[i+1]=a[c];
  a[c]=t; 
  return i+1;

}

int main(){
  int i,n,b[A],x;

  scanf("%d",&n);

  for(i=0;i<n;i++)scanf("%d",&b[i]);

  x=partition(b,0,n-1);

  for(i=0;i<n;i++){
    if(i==x)printf("[%d]",b[i]);
    else printf("%d",b[i]);
    if(i<n-1)printf(" ");

  }
  printf("\n");


  return 0;
}

