#include <stdio.h>
#define exchange(a,b) {typeof(a) __tmp=a;a=b;b=__tmp;}

int Partition(int A[], int p, int r) {
  int i,j;
  int x;
  x = A[r];
  i = p-1;
  for(j = p; j < r; ++j) {
    if(A[j] <= x) {
      i = i+1;
      exchange(A[i], A[j]);
    }
  }
  exchange(A[i+1], A[r]);
  return i+1;
}


int main() {
  int i;
  int n, p;
  int A[100001];
  scanf("%d", &n);
  for(i = 1; i <= n; ++i)
    scanf("%d", A+i);
  p = Partition(A,1,n);
  for(i = 1; i <= n; ++i) {
    if(i-1) printf(" ");
    if(i == p)
      printf("[%d]", A[i]);
    else
      printf("%d", A[i]);
  }
  printf("\n");
  return 0;
}