#include <stdio.h>
int partition(int, int);
int A[100000];
int main(){
  int v,n,p,j;
 
  scanf("%d",&n);
  for(j=0; j<n; j++){
    scanf("%d", &A[j]);
  }
  p=0;
  v=partition(p, n-1);
  for(j=0; j<n; j++){
    if(j!=0){
      printf(" ");}
    if(v==j){
      printf("[%d]", A[j]);}
    else printf("%d", A[j]);
    }
  
  printf("\n");
  return 0;
}
 
int partition(int p, int r)
{
  int a,c,i,j;
  i = p-1;
  a = A[r];
  for(j=p; j<r; j++){
    if (A[j] <= a){
      i = i+1;
      c = A[i];
      A[i] = A[j];
      A[j] = c;
    }
  }
  c = A[i+1];
  A[i+1] = A[r];
  A[r] = c;
  return i+1;
}

