#include<stdio.h>
#define MAX 100000

void partition(int [], int);

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

  scanf("%d", &n);

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

  partition(A, n - 1);

  return 0;
}

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

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

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

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