#include<stdio.h>
#define MAX 100000
#define VMAX 100000

int main(){
  int n,x,temp,i,j,p=0;
  int A[MAX];

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  x=A[n-1];
  i=p-1;
  for(j=p;j<n-1;j++){
    if(A[j]<=x){
      i=i+1;
      temp=A[i];
      A[i]=A[j];
      A[j]=temp;
    }
  }
  temp=A[i+1];
  A[i+1]=A[n-1];
  A[n-1]=temp;
  
  for(i=0;i<n;i++){
    if(x==A[i]){
      if(x!=A[i+1]){
	printf("[%d]",A[i]);
      }
      else printf("%d",A[i]);
    }
    else printf("%d",A[i]);
    if(i!=n-1) printf(" ");
  }
  printf("\n");
  return 0;
}

