#include  <stdio.h>
#define MAX 100001

void Partition(int *A, int left, int right);
void Swap(int *x, int i, int j);

int main()
{     
  int A[MAX], n, i, pivot;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  pivot=A[n-1];
  Partition(A, 0, n-1);
  i=0;
  while(pivot!=A[i]){
    printf("%d ",A[i]);
    i++;
  }
  printf("[%d]",A[i++]);
  while(i!=n-1){
    printf(" %d",A[i]);
    i++;
  }
  printf(" %d\n",A[i]);
  return 0;
}

void Partition(int *A, int left, int right)
{
  int i, j, x;
    x = A[right];
    i = left-1;
    for(j=left; j<right; j++){
      if(A[j]<=x){
	i++;
	Swap(A, i, j);
      } 
    }
    Swap(A, i+1, right);
}

void Swap(int *x, int i, int j)
{
    int temp;
    temp = x[i];
    x[i] = x[j];
    x[j] = temp;
}