#include <stdio.h>
#define NUM 100000

int n;
int A[NUM];

int pertion(int X[],int p,int r);


int main()
{
  int i,x;

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%d",&A[i]);
  }
  x = A[n-1];
  pertion(A,0,n-1);
  printf("%d",A[0]);
  for(i = 1;i < n;i++){
    if(A[i] == x && A[i+1] > x) printf(" [%d]",A[i]);
    else printf(" %d",A[i]);
  }
  printf("\n");

  return 0;
}

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

  return i+1;
}



