#include<stdio.h>
#define n 100001
void swap(int ,int);

int A[n],key;
int partition(int ,int);
void swap(int x, int y)
{
  int temp;
  temp = x;
  x = y;
  y = temp;
}


int main()
{
  int num,i;
  scanf("%d",&num);

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

  key = partition(0,num-1);

  printf("%d",A[0]);

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

  printf("\n");


  return 0;
}