#include<stdio.h>

int Partition(int *,int,int);

main(){
  int n,i,x;
  scanf("%d",&n);
  int A[n];
  for(i=0 ; i<n ; i++) scanf("%d",&A[i]);

  x = Partition(A,0,n-1);

  for(i=0 ; i<n ; i++){
    if(i!=0) printf(" ");
    if(x==i) printf("[%d]",A[i]);
    else printf("%d",A[i]);
  }
  printf("\n");

  return 0;
}

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

  return i+1;
}