#include<stdio.h>

#define MAX 100000

int main(){
  int n, i, x, A[MAX], p, j, r, m;
  scanf("%d",&n);

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

  p = 1;
  r = n;
  x = A[r];
  i = p-1;

  for(j=p ; j<r ; j++){
    if(A[j] <= x){
      i = i+1;
      m = A[i];
      A[i] = A[j];
      A[j] = m;
    }
  }
    m = A[i+1];
    A[i+1] = A[r];
    A[r] = m;

    r = i+1;
    
    for(i=1 ; i<=n ; i++){
      if(i!=1)printf(" ");
      if(i == r)printf("[");
      printf("%d",A[i]);
      if(i == r)printf("]");
    }

    printf("\n");
    return 0;
}

