#include<stdio.h>
#define N 100001

int partition(int *, int, int);

int main(){

  int A[N];
  int n,k,num,num2;

  scanf("%d",&n);

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

  num=n-1;

  num2=partition(A,0,n-1);

  for(k=0;k<num2;k++){

    printf("%d ",A[k]);
    

  }
   
    
  printf("[%d] ",A[num2]);

  for(k=num2+1;k<n;k++){

    printf("%d",A[k]);

    if(k==n-1) printf("\n");
    else printf(" ");

  }


 return 0;

  
}

int partition(int *A,int p,int r){

  int i,j,x,temp1,temp2;

  x=A[r];
  i=p-1;
  
  for(j=p;j<=r-1;j++){

    if(A[j]<=x){
      i=i+1;
      temp1=A[i];
      A[i]=A[j];
      A[j]=temp1;
      
    }

  }

  temp2=A[i+1];
  A[i+1]=A[r];
  A[r]=temp2;

  return i+1;
    
}

