#include <stdio.h>
#define N 100000

int A[N];

int main(){
  int i,j,n,y;

  scanf("%d",&n);

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

  y = partition(0,n-1);

  for(i=0;i<n;i++){
    if(i != 0){
      printf(" ");
    }

    if(i == y){
      printf("[");
    }
    printf("%d",A[i]);
    if(i == y){
      printf("]");
    }

  }
  printf("\n");

  return 0;
}

int partition(int m, int n){
  int i,j,x,tmp;

  x = A[n];
  i = m-1;

  for(j=m;j<n;j++){
    if(x >= A[j]){
      tmp  = A[j];
      A[j] = A[i+1];
      A[i+1] = tmp;
      i++;
    }
  }

  tmp = A[i+1];
  A[i+1] = A[n];
  A[n] = tmp;

return n+1;
}
