#include <stdio.h>

int main(){
  int n;
  scanf("%d", &n);
  int A[n], x, y, z, i, j;
  int p = 0;
  int r = n-1;
  for(i=0;i<n;i++)scanf("%d", &A[i]);
  x = A[r];
  i = p - 1;
  for(j=p;j<=r-1;j++){
    if(A[j]<=x){
      i = i + 1;
      y = A[i];
      A[i] = A[j];
      A[j] = y;
    }
  }
  z = A[i+1];
  A[i+1] = A[r];
  A[r] = z;
  for(j=0;j<n-1;j++){
    if(j==i+1) printf("[");
    printf("%d", A[j]);
    if(j==i+1) printf("]");
    printf(" ");
  }
  printf("%d\n", A[n-1]);
  return 0;
}
