#include<stdio.h>
#define MAX 100000

int A[MAX+1];

int main(){

int n,i,j,x,p,swap,k;

  scanf("%d",&n);

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

  x=A[n];
  i=0;

  for(j=1;j<n;j++){
    if(A[j]<=x){
      i++;
      swap=A[i];
      A[i]=A[j];
      A[j]=swap;
    }
}
      swap=A[i+1];
      A[i+1]=A[n];
      A[n]=swap;

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

  return 0;
}


   

  