#include<stdio.h>
int n;
void partition(int *,int,int);
int main(){
  int i;
  int A[100001];
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  partition(A,0,n);
  return 0;
}

void partition(int A[],int p,int r){
  int x = A[r-1];
  int i,j,tmp;
  j=p;
  for(i=p;i<r;i++){
    if(A[i]<=x){
      tmp = A[i];
      A[i] = A[j];
      A[j]=tmp;
      j++;
    }
  }
  for(i=p;i<r;i++){
    if(i==j-1) printf("[%d]",A[i]);
    else printf("%d",A[i]);
    if(i!=r-1) printf(" ");
  }
  printf("\n");
}
    

