#include<stdio.h>
#define N 100001

int main(){
  
  int x,n,A[N],i,j,y,z;

  scanf("%d",&n);

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

  x = A[n];
  i = 0;

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

  z = A[n];
  A[n] = A[i+1];
  A[i+1] = z;

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

