#include<stdio.h>
#define N 100001
int Partition(int, int);
int A[N], n;

int main(void){
  int i, k;
  scanf("%d", &n);
  for(i=1; i<=n; i++)scanf("%d", &A[i]);
  
  k =  Partition(i, n);
  
  for(i=1; i <= n; i++) {

    if(k == i) {
      printf("[%d] ", A[i]);
      continue;
    }
    printf("%d", A[i]);
    if(i < n)printf(" ");
    
  }
  
  printf("\n");
  
  return 0;
}


int Partition(p, r){
  int i, j, x, a;
  x = A[r];
  i = p-1;

  for(j = p; j <= r-1; j++){

    if(A[j]<=x){
      i++;
      a = A[i];
      A[i] = A[j];
      A[j] = a; 
    }

  }

  a = A[i+1];
  A[i+1] = A[r];
  A[r] = a; 
  return i+1;
    }