#include<stdio.h>
#define N 100000

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

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