#include<stdio.h>

#define N 100000

int partition(int A[], int p, int r){
  int temp,x,i,j;
  
  x = A[r];
  i = p-1;
  for (j = p; j< r; 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[r];
  A[r] = temp;
  
  return i+1;
}
  

void print(int A[], int n,int mid){
  int i;
  for ( i = 1; i <=n; i++ ){
    if ( i > 1 ) printf(" ");
    if (i==mid) printf("[");
    printf("%d", A[i]);
    if (i==mid) printf("]");
  }
  printf("\n");
}

int main(){
  int n, i, j;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <=n; i++ ) scanf("%d", &A[i]);
  int mid = partition(A, 1, n);
  
  print(A, n, mid);

  return 0;
}
