#include<stdio.h>

int partition(int *,int,int);

int main(){
  int n,i,k;
  scanf("%d",&n);
  int A[n];
  for(i=0;i<n;i++) scanf("%d",&A[i]);

  k=partition(A,0,n);

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

  return 0;
}

int partition(int *A,int o,int n){
  int x,i,j,k;
  x=A[n-1];
  i=o;

  for(j=o;j<n-1;j++){
    if(A[j]<=x){
      k = A[j];
      A[j] = A[i];
      A[i] = k;
      i++;
    }
  }

  k=A[i];
  A[i]=A[n-1];
  A[n-1]=k;

  return i;
}
    
  

