#include<stdio.h>
#define MAX 100000
int main(){
  int i,j,p=0,r,n,t,x;
  int A[MAX];
  scanf("%d",&n);
  for(r=0;r<n;r++){
    scanf("%d",&A[r]);
  }
  x=A[r];//A[r]
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i+=1;
      t=A[i];
      A[i]=A[j];
      A[j]=t;
    }
  }
  t=A[i+1];
  A[i+1]=A[r];
  A[r]=t;

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