#include<stdio.h>

int partition(int,int);

int A[100000];
int point;
int main(){

  int n;
  int i;
  scanf("%d",&n);

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

  point = partition(1,n);

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

int partition(int p,int r){

  int x,y;
  int i,j;

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

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