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