#include <stdio.h>
#include <stdlib.h>
int main(){
  int i,j,n,tmp,x,*A;

  scanf("%d",&n);

  A=malloc(sizeof(int)*(n+1));

  for(i=1;i<n+1;i++)
    scanf("%d",&A[i]);

  i=0;
  for(j=1;j<n;j++)
    if(A[j]<=A[n]){
      i++;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
    }
  tmp=A[i+1];
  A[i+1]=A[n];
  A[n]=tmp;
  x=i+1;

  for(i=1;i<x;i++)
    printf("%d ",A[i]);
  printf("[");
  printf("%d]",A[x]);
  for(i=x+1;i<n;i++)
    printf(" %d",A[i]);
  printf("\n");

  return 0;
}