#include<stdio.h>

int n,A[100000];

void partition(int,int);
main(){
  int i,a;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  a=partition(0,n-1);
  for(i=0;i<=n;i++){
    if(i == z)printf("[%d]",A[i]);
    else if(i != 0) printf("%d",A[i]);
    else pritnf(" ");
  }
  printf("\n");
  return 0;
}

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