#include<stdio.h>

int partition(int);
int A[100000];

int main()
{

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

  j=partition(n);

  for(i=1; i<j; i++){
    printf("%d ",A[i]);
  }

  printf("[%d] ",A[j]);

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

  printf("%d\n",A[n]);
  
  return 0;
}

int partition(int r){
  int x,i,j,temp,p=1;

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

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

  temp = A[i+1];
  A[i+1] = A[r];
  A[r] = temp;

  return i+1;
}
      

