#include <stdio.h>

int partition(int *,int,int);

int main(){
  int c,i,n,A[100000];
  
  scanf("%d", &n);
  
  if(n < 1 || n > 100000)return 0;
   for(i = 0; i < n; i++){
     scanf("%d", &A[i]);
     if(A[i] < 0 || A[i] > 100000)return 0;
   }
  c = partition(A,0,n-1);
  
  for(i = 0; i < n; i++){
    if(i > 0)printf(" ");
    
    if(i == c)printf("[%d]",A[c]);
    else printf("%d",A[i]);
  }
   printf("\n");
  return 0;
}

int partition(int A[],int p,int r){
  int c,x,i,j;
  i = p-1;
  x = A[r];
  
  for(j = p; j < r;j++){
    if(A[j] <= x){
      i += 1;
      c = A[j];
      A[j] = A[i];
      A[i] = c;
    }
  }
  c = A[i+1];
  A[i+1] = A[r];
  A[r] = c;

  return i+1;
}

