#include<stdio.h>


int A[100000];

int partition(int A[],int p,int r){
  int x,i,j,exs;

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

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

  return i+1;

}


int main(void){

  int i,j;
  int num;
  int q;

  scanf("%d",&num);
  for(i = 0 ; i < num ; i++)
    scanf("%d",&A[i]);
  q = partition(A,0,num-1);
  for( i = 0 ; i < num-1 ; i++){
    if(i == q){
      printf("[%d]",A[q]);
      continue;
    }
    printf("%d ",A[i]);
  }
  printf("%d",A[i]);
  return 0;
}