#include<stdio.h>


void Partition(int *,int,int);

main() {

  int i,x;
  scanf("%d",&x);

  int *A;
  A = malloc(sizeof(int)*x);
  for(i=0;i<x;i++){
    scanf("%d",&A[i]);
  }
  Partition(A,0,x-1);

  return 0;
}

void Partition(int *A,int p,int r){
  int i,j,x,y;
  x = A[r];
  i = p ;
  for(j=p;j<=r-1;j++){
    if(A[j] <= x){    
      y = A[i];
      A[i] = A[j];
      A[j] = y;
      i = i+1;
    }
  }
  
  y = A[i];
  A[i] =A[r];
  A[r] = y;
  
  
  for(j=0;j<=r;j++){
    if(j == i){
       printf("[%d]",A[j]);
    }
    else printf("%d",A[j]);
    if(j<r) printf(" ");
  }
    printf("\n");
  
}