#include<stdio.h>
#define N 100001
  
void Partition(int A[], int p, int q){
  int x, i, j;
  int temp;
  
  x = A[q];
  i = p-1;
  
  for(j = p; j <= q-1; j++){
    if(A[j] <= x){
      i = i + 1;
 
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
 
    }
  }
 
  temp = A[i + 1];
  A[i + 1] = A[q];
  A[q] = temp;

  for(j = 0; j <= q; j++){
    if(j == i + 1) printf("[%d]", A[j]);
    else printf("%d", A[j]);
    if(j != q) printf(" ");
  }
  printf("\n");
 
}
  
int main(){
  int n, i, p = 0, q;
  int A[N];
  
  scanf("%d", &n);
  for(i = 0; i < n; i++) scanf("%d", &A[i]);
  q = n - 1;
  
  Partition(A, p, q);
  
  return 0;
}