#include <stdio.h>
#define N 100000

int main(){
  int A[N];
  int i,j,n,x,r,tmp,cnt=0,flag=0;
  
  scanf("%d",&n);
  if(n<0 || n>100001) printf("Error\n");
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    if(A[i]<0 || A[i] > 100001) printf("Error\n");
  }
  
  r = i-1;
  x = A[i-1];
  
  for(i=0;i<r;){
    for(j=0;j<r;){
      if(A[j] <= x){
	if(A[j] == x) cnt++;
	tmp = A[i];
	A[i] = A[j];
	A[j] = tmp;
	i++;
      }
      j++;
    }
    if(j == r){
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
      break;
    }
  }
  
  for(i=0;i<n;i++){
      if(cnt == flag){
	if(i == n-1){
	  printf("[%d]\n",A[i]);
	  continue;
	}
	else {
	  printf("[%d] ",A[i]);
	  continue;
	}
      }
      else flag++;
    }
      if(i == n-1) printf("%d\n",A[i]);
      else printf("%d ",A[i]);
      return 0;
}
/*for(i=0;i<n;i++){
    if(A[i] == x){
      if(cnt == flag){
	if(i == n-1){
	  printf("[%d]\n",A[i]);
	  continue;
	}
	else {
	  printf("[%d] ",A[i]);
	  continue;
	}
      }
      else flag++;
    }
      if(i == n-1) printf("%d\n",A[i]);
      else printf("%d ",A[i]);
      }*/

