#include <stdio.h>
#define MAX 100000

int Partition(int *,int);

int main() {
  int i,n,A[MAX],m;

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

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

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

  return 0;
}

int paritition(int *A, int n) {
  int x,i,j,a;
  x = A[n];
  i = 0;
  for(j = 0; j < n; j++) {
    if(A[j] <= x) {
      a = A[i];
      A[i] = A[j];
      A[j] = a;
      i++;
    }
  }
  A[n] = A[i];
  A[i] = x;
  printf("%d\n",i);
  return i;
}