#include <stdio.h>
#define N 100000

int n;
int Partition(int ,int);
int A[N];

int Partition(int p,int r){
  int i,j,x,tmp;
  x = A[r];
  i = p-1;
  for( j = p ; j < r-1 ; j++ ){
    if(A[j] <= x){
      i++;
      tmp=A[j];
      A[j]=A[i];
      A[i] = tmp;
    }
    tmp=A[r];
    A[r]=A[i+1];
    A[i+1]=tmp;
    return i+1;
  }
}


main(){
  int i,r,ans;
  int p=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  r=n-1;
  ans=Partition(p,r);
  for(i=0; i< ans;i++)printf("%d",A[i]);
  printf("[%d] ",A[ans]);
  for(i=ans+1; i< n;i++){
    printf("%d", A[i]);
    if(i+1<n){
      printf(" ");
    }
  }
  printf("\n");
  return 0;
}
 