#include <stdio.h>
#include <stdlib.h>
#define N 100000
 
int Partition(int [], int, int);

int main(void){
  int n,i,a[N],q;

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

  q = Partition(a,1,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 x,i,j,tmp;

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

  for(j = p; j <= r-1; j++){
    if(A[j] <=  x){
      i =  i + 1;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;

  return i+1; 
}