#include <stdio.h>
#define MAX 2000000

int partition(int,int);
int a[MAX];

int main(){
  
  int i,n,q;

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

  q = partition(0,n-1);

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

  return 0;
}

int partition(int p,int r){
  int i,j,x,temp;

  x=a[r];
  i=p-1;

  for(j=p;j<r;j++){
    if(a[j]<=x){
      i=i+1;
      
      temp=a[i];
      a[i]=a[j];
      a[j]=temp;
    }
  }

  temp=a[i+1];
  a[i+1]=a[r];
  a[r]=temp;
  
  return i+1;
}