#include<stdio.h>
int Partition(int*, int, int);
int A[10000];

int main(void){
  int i, n, x;
  scanf("%d",&n);
  for(i=1; i<=n; i++){
  scanf("%d",&A[i]);
  }
  x = A[n];
  Partition(A, 1, n);
for(i=1; i<=n; i++){
  if(A[i] == x) printf("[");
  printf("%d",A[i]);
  if(A[i] == x) printf("]");
  if(i < n) printf(" ");
      }
  printf("\n");
  return 0;
}


int Partition(int *A, int p, int r){
  int x, y, i, j;
   x = A[r];
   i = p-1;
   for(j=p; j<=r-1; j++){
     if(A[j] <= x){
       i = i+1;
       y = A[i];
       A[i] = A[j];
       A[j] = y;
     } 
   }
   y = A[i+1];
   A[i+1] = A[r];
   A[r] = y;
   return i+1;
}