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

#define MAX 1000

int partition(int [],int,int);
int x,i,p=1;

int main(){

  int A[MAX];
  int n,p=1,q;

  scanf("%d",&n);

  for( i = 1 ; i <= n ; i++ ) {
    scanf("%d",&A[i]);
  }
  
  //for( i = 1 ; i <= n ; i++ ) {
    q = partition(A,p,n);

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

  printf("%d\n",A[i]);

  return 0;
}
  
int partition(int A[],int p,int n){
  int j,key;

  x = A[n];
  i = p-1;
  for( j = p ; j <= n-1 ; j++ ){
    if( A[j] <= x ){
      i = i+1;
      key = A[j];
      A[j] = A[i];
      A[i] = key;
    }
  }
      key = A[n];
      A[n] = A[i+1];
      A[i+1]= key;
  return i+1;
}