#include <stdio.h>

int main() {

  int n,i,j,x,y,temp,A[100001];
  
  scanf("%d",&n);
  for(i = 1; i < n+1; i++) {
    scanf("%d",&A[i]);
  }

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

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

  return 0;
}

