#include<stdio.h>
#include<stdlib.h>
#define N 100000
  
int A[N];
int Partition(int A[],int p,int r);
int main(){
    
  int i,j,n,x;
    
  scanf("%d",&n);
  /*
    A = malloc(sizeof(int)*n+1);
    B = malloc(sizeof(int)*n+1);
  */
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
    
  x=Partition(A,0,n-1);
  for(i=0;i<x;i++){
    printf("%d ",A[i]);   
  }
  printf("[%d] ",A[x]);
  for(i=x+1;i<n;i++){
    printf("%d",A[i]);
    if(i!=n-1)
      printf(" ");    
  }
  printf("\n");
  return 0;
}
  
int Partition(int A[],int p,int r){
  int x,i,j,n;
  x=A[r];
  i=p-1;
  for(j=p;j<=r-1;j++){
    if(x>=A[j]){
      i=i+1;
      n=A[j];
      A[j]=A[i];
      A[i]=n;
    }
  }
  n=A[r];
  A[r]=A[i+1];
  A[i+1]=n;
  return i+1;
}