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

