#include <stdio.h>
#include <stdlib.h>

int *A;

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

  A[r] = A[i+1];
  A[i+1] = x;

  return i+1;
}

int main(){
  int n,i,x;
  
  scanf("%d",&n);
  A = malloc(sizeof(int) * n + 1);
  for(i = 1;i <= n;i++)scanf("%d",&A[i]);
  
  x = partition(1,n);
  
  for(i = 1;i <= x-1;i++)printf("%d ",A[i]);
  printf("[%d] ",A[x]);
  for(i = x+1;i <= n-1;i++)printf("%d ",A[i]);
  printf("%d\n",A[n]);
  
  return 0;
}

