#include <stdio.h>
int main() {
  int i=-1, j=0, k, l, n, A[100000];
  scanf("%d", &n);
  for(l = 0; l < n; l++) {
    scanf("%d", &A[l]);
  }
  for(j = 0; j < n-1; j++) {
    if(A[j] <= A[n-1]) {
      i++;
      k = A[j];
      A[j] = A[i];
      A[i] = k;
    }
  }
  
  k = A[n-1];
  A[n-1] = A[i+1];
  A[i+1] = k;
  for(j = 0; j < n; j++) {
    if(j == i+1) printf("[%d] ", A[j]);
    else {
      printf("%d", A[j]);
      if(j != n-1) printf(" ");
    }
  }
  printf("\n");
  return 0;
}