#include <stdio.h>
#define MAX 100000

int A[MAX];
int partition(int[],int,int);

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

  return 0;
}

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

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

  return i+1;
}