#include<stdio.h>
#include<stdlib.h>

int n,x;

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

int main(void){
  int i;
  int *A;
  scanf("%d",&n);
  A=malloc(n*sizeof(int));
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  pertition(A,0,n-1);
  for(i=0;i<n;i++){
    if(A[i]==x) printf("[%d]",A[i]);
    else printf("%d",A[i]);
    if(i!=n-1) printf(" ");
  }
  printf("\n");
  free(A);
  return 0;
}