#include <stdio.h>
#define Max 100000
#define AMax 100000

int A[Max],n;

int partition(int q, int r){
    int x,i,j,kari;
    x=A[r];
    for(j=0;j<r;j++){
      if(A[j]<=x){
        kari=A[q];
        A[q]=A[j];
        A[j]=kari;
        q++;
      }
    }
    kari=A[q];
    A[q]=A[r];
    A[r]=kari;
    return q;
}

int main(int argc, char const *argv[]) {
  int i,s;
  scanf("%d\n",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);

  s=partition(0,n-1);

  for(i=0;i<n;i++){
    if(i==n-1) printf("%d\n",A[i]);
    else {
      if(i==s) printf("[%d] ",A[i]);
      else printf("%d ",A[i]);
    }
  }
  return 0;
}