#include <stdio.h>
#include <stdlib.h>

int main() {
  int *A, n, i, j, p=0, r, x, temp;

  scanf( "%d" , &n );
  A = malloc(n * sizeof(int));
  for ( j=0; j<n; j++ ) scanf( "%d" , &A[j] );

  r = n-1;
  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;

  for ( j=0; j<(i+1); j++ ) printf( "%d " , A[j] );
  printf( "[%d] " , A[i+1] );
  for ( j=(i+2); j<(n-1); j++ ) printf( "%d " , A[j] );
  printf( "%d\n" , A[n-1] );

  return 0;
}

