#include<stdio.h>

int main(){
  int i, j, n, p, r, x, A[100000], temp;

  scanf("%d", &n);
  if(n <= 100000 && n >= 1){
    for(i = 0; i < n; i++){
      scanf("%d", &A[i]);
      if(A[i] > 100000 || A[i] < 0) break;
    }
    p = 0;
    r = n-1;

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

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

