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

