#include<stdio.h>
int partition(int *,int,int);
void quicksort(int *,int,int);
int main(){
  int i,n,p=0,par;
  scanf("%d",&n);
  int r=n-1;
  int A[n];
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  par = partition(A,p,r);
  for(i=0;i<n;i++){
    if(i==n-1 && i != par) printf("%d\n",A[i]);
    else if(i==par) printf("[%d] ",A[i]);
    else printf("%d ",A[i]);
  }
  return 0;
}
int partition(int *A,int p,int r){
  int j,temp;
  int x = A[r];
  int i = p-1;
  for(j = p;j<=r-1;j++){
    if(A[j] <= x){
      i = i+1;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
    }
  }
  temp = A[i+1];
  A[i+1] = A[r];
  A[r] = temp;
  return i+1;
}
