#include <stdio.h>
#define N 100000
int main()
{
  int n,m,r,i,j,k,count=0,A[N];
  scanf("%d",&n);
  m=n-1;
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);
  for(i=0;i<n;i++)
    {
      if(A[i]>A[m])
        {
          if(i==m)
            k=count;
          count++;
          continue;
        }
      else if(A[i]<=A[m]&&count!=0)
        {
          if(i==m)
            k=i-count;
          r=A[i];
          A[i]=A[i-count];
          A[i-count]=r;
        }
    }
  for(i=0;i<n;i++)
    {
      if(i==k)
        {
        printf("[%d]",A[i]);
        if(i!=m)
          printf(" ");
                  continue;
        }
      printf("%d",A[i]);
      if(i!=m)
        printf(" ");
    }
  printf("\n");
  return 0;
}
