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

int Partition(int p,int r){
  int a,R=0,L=0,i,j;
  a=A[r];
  i=p-1;
  for(j = p ; j <= r-1 ; j++){
    if(A[j] <= a){ 
      i = i+1;
      R = A[i];
      A[i] = A[j];
      A[j] = R;
    }
  }
    L = A[i+1];
    A[i+1] = A[r];
    A[r] = L;
    return i+1;
}