#include <stdio.h>

int main(){

  int i,j,x=0,p=0,n,temp;

  scanf("%d",&n);
  int A[n];
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  x = A[n-1];
  
 
  i =p - 1;

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

      temp=A[i];
    A[i] = A[j];
    A[j] = temp;
    } 
  }

  temp = A[i+1];
  A[i+1] = A[n-1];
  A[n-1] = temp;

  for(j=0;j<n-1;j++){

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