#include <stdio.h>
#include <stdlib.h>
#define MAX 100000
 
int Partition(int [], int, int);
 
int q;
 
int main(void){
 
  int A[MAX+1];
  int i, p, n;
 
  scanf("%d",&n);
 
  for(i=1;i<=n;i++) scanf("%d",&A[i]);
 
  p = 1;
  q = Partition(A,p,n);
 
 
  for(i=1;i< n;i++){
    if(i==q) printf("[%d] ",A[i]);
    else printf("%d ",A[i]);
  }
 
  printf("%d\n",A[i]);
 
  return 0;
}
 
 
int Partition(int A[], int p, int r){
 
  int i, j, x;
  int tmp;
 
  x = A[r];
  i = p - 1;
 
  for(j = p;j<r;j++){
    if(A[j] <= x){
      i = i + 1;
      tmp = A[j];
      A[j] = A[i];
      A[i] = tmp;
    }
  }
   
  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;
 
  return i+1;
}