#include <stdio.h>
#define MAX 100000
int main(){
  int n;
  int A[MAX];
  int i,j;
  int point;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  point = partitionSort(A,0,n);

  for(i=0;i<point;i++){
    printf("%d ",A[i]);
  }
  printf("[%d] ",A[i]);
  for(i=point+1;i<n-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[i]);
}

int partitionSort(int *A,int p,int r){
  int x;
  int i,j;
  int tmp;
  x = A[r-1];
  //  printf("x =  %d\n",x);
  i = p - 1;
  for(j=p;j<r-1;j++){
    if(A[j] <= x ){
      i = i + 1;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }
  /*
  for(j=0;j<r;j++){
    printf("%d ",A[j]);
  }
  printf("\n");
  */
  tmp = A[i+1];
  A[i+1] = A[r-1];
  A[r-1] = tmp;
  return i+1;
}

