#include<stdio.h>
main(){
  int i,p,q,n,x,taihi;
  int A[100001]
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  x = A[n-1];
  p=-1;
  for(i=0;i<n;i++){
    if(A[i]<= x){
      p++;
      taihi =A[p];
      A[p]=A[i];
      A[i]=taihi;
    }
  }
  taihi= A[p+1];
  A[p+1]=A[n-1]
    A[n-1]=taihi;
  for(i=0;i<ni++){
    if(i==p+1)printf("[%d]",A[p+1]);
    printf("%d",A[i]);
    if(i<n-1)printf(" ");
  }
  printf("?\n");
  return 0;
}