#include<stdio.h>
#define MAX 100000
int A[MAX];

int main(){
  int n,i,j,r,p,x,tmp;

  scanf("%d",&n);
  for(r=0;r<n;r++) scanf("%d",&A[r]);

  x=A[--r];
  i=-1;
  for(j=0;j<n-1;j++){
    if(A[j]<=x){
      tmp=A[++i];
      A[i]=A[j];
      A[j]=tmp;
    }
  }
  tmp=A[i+1];
  A[i+1]=A[r];
  A[r]=tmp;

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

