#include <stdio.h>

int A[100000];

int partition(int [],int,int);
int main(){
  int i,j,n,p=0,r;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  r = n-1;
  j = partition(A,p,r);

  for(i=0;i<n-1;i++){
    if(i==j){
      printf("[%d] ",A[i]);
    }else{
      printf("%d ",A[i]);
    }
  }
  printf("%d\n",A[n-1]);

  
  return 0;
}

int partition(int A[],int p,int r){
  int x,i,j,change;

  x = A[r];
  i = p-1;

  for(j=p;j<r;j++){
    if(A[j]<=x){
      i = i+1;
      change = A[i];
      A[i] = A[j];
      A[j] = change;
    }
  }
  change = A[i+1];
  A[i+1] = A[r];
  A[r] = change;

  return i+1;
}

