#include<stdio.h>

#define N_MAX 2000005
#define k 10005

int A[N_MAX];
int B[N_MAX];
int C[k];
int n;

int main()
{
  int i, j, x, r, work;
  
  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d", &A[i]);
  }
  
  i = 0;
  r = n-1;
  x = A[r];
  
  for(j=0; j<r; j++){
    if(A[j] <= x){
      work = A[i];
      A[i] = A[j];
      A[j] = work;
      i+=1;
    }
  }

    work = A[i];
    A[i] = A[r];
    A[r] = work;

  for(j=0; j<n; j++){

    if(j==i){
      printf("[%d] ", A[j]);
      continue;
    }
      
    printf("%d", A[j]);
        
    if(j!=(n-1))
      printf(" ");
    else
      printf("\n");
  }

  return 0;
}