#include <stdio.h>

#define MAX 100000

void Partition(int A[],int p,int r)
{
    int x = A[r];
    int i = p-1,j,l = l;
    int temp;
    
    for(j = p; j < r-1; j++)
    {
        if(A[j] <= x)
        {
            i++;
            temp = A[i];
            A[i] = A[j];
            A[j] = temp;
        }
    }
    temp = A[i];
    A[i] = A[r];
    A[r] = temp;
    
    for(j = l ; j <= r ; j++){
    if(j > l){ printf(" "); }
    if(j == i){
      printf("[%d]",A[j]);
    }else{
      printf("%d",A[j]);
    }
  }
  printf("\n");
}


int main(void){
    int i;
    int n,A[MAX];
    
    scanf("%d",&n);
    for(i = 0; i < n; i++) scanf("%d",&A[i]);
    
    Partition(A,0,n-1);
    
}
