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

int main(){

  int r,i,j,x,tr,p=0;
  int *A;
  scanf("%d",&r);

  A = (int *)malloc(sizeof(int)*r);
  
  for(i = 0 ; i < r ; i++)
    scanf("%d",&A[i]);


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

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

  tr = A[i+1];
  A[i+1] = A[r-1];
  A[r-1] = tr;

  tr = i+1;
  
  for(i = 0 ; i < r ; i++){
    if(i == tr) printf("[");
    printf("%d",A[i]);
    if(i == tr) printf("]");
    if(i < r-1) printf(" ");
    
  }

  printf("\n");

  return 0;

}
  