#include<stdio.h>

#define N 100000

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

int main(){
  int n, i;
  int p, r;
  int A[N];
  scanf("%d", &n);
  for(i = 0; i < n; i++) scanf("%d", &A[i]);
  p = 0;
  r = n - 1;
  partition(A, p, r);
  return 0;
}