#include<stdio.h>

#define MAX 1000000

int main(){
  int n,A[MAX];
  int i,j;
  int x,a,b,c;

  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  
  x=A[n-1];
  i=-1;
  for(j=0;j<=n-1;j++){
    if(A[j]<=x){
      i=i+1;
      a=A[i];
      A[i]=A[j];
      A[j]=a;
    }
  }
  for(j=0;j<n-1;j++){
    if(j==i)printf("[",A[j]);
    printf("%d",A[j]);
    if(j==i)printf("]",A[j]);
    printf(" ");
  }
  printf("%d",A[j]);
  printf("\n");
  return 0;
}

