#include <stdio.h>
#include <stdlib.h>
#define MAX 100000
#define VMAX 100000

int partition(int *A, int p, int r){
  int i, j;
  int x, a;

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

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

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

  return i+1;
}

int main(){
  int *A;
  int n, i, q;

  scanf("%d", &n);

  A = malloc(sizeof(int)*(n+1));

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

  q = partition(A, 1, n);

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


  if(i == q) printf("[%d]\n",A[i]);
  else printf("%d\n",A[i]);

  free(A);

  return 0;
}

