#include <stdio.h>
#include <stdlib.h>
#define MAX 100000
#define VMAX 100000

int main(){
  unsigned short *A;
  int n, i, j,x,temp;

  scanf("%d", &n);

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

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

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

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


  return 0;
}


