#include<stdio.h>

#define Max 100001

int main(){
  int i, j, n, A[Max], a1, a2, x;

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

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

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

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

  return 0;
}