#include<stdio.h>

int A[100000];

int main(){
  int n,i,j,p,q,r,x;

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

  r = n - 1;
  x = A[r];
  p = 0;
  i = p - 1;

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

  for(i = 0;;){
    if(A[i] == x){
      printf("[%d]",A[i]);
    }
    else{
      printf("%d",A[i]);
    }
    i++;
    if(i >= n)break;
    printf(" ");
  }
  printf("\n");

  return 0;
}