#include<stdio.h>
#define N 100000
int partition(int a[],int,int);
int n,a[N];

int partition(int a[],int p,int r) {
  int x,i,j,tmp1,tmp2;
  x = a[r];
  i = p -1 ;
  
  for(j=p;j<=r-1;j++) {
    if(a[j] <= x){
      i++;
      tmp1 = a[i];
      a[i] = a[j];
      a[j] = tmp1;
    }
  }

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

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

  m = partition(a,0,n-1);
  
  for(i=0;i<m;i++)
    printf("%d ",a[i]);
  
  printf("[%d] ",a[m]);
  
  for(i=m+1;i<n-1;i++)
  printf("%d ",a[i]);
  
  printf("%d\n",a[n-1]);
  
  return 0;
}