#include<stdio.h>
#define MAX 100000

int main(){
  int n,i,A[MAX],temp,j,k;
  scanf("%d", &n);
  for(i = 0; i < n; i++) scanf("%d", &A[i]);

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

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

  return 0;
}
