#include <stdio.h>
#define MAX 100005

int n,A[MAX];
int  partition(void){
  int i,j,x,c,b;
  x=A[n-1];
  i=-1;
  for(j=0;j<n-1;j++){
    if(A[j]<=x){
      i=i+1;
      c=A[i];
      A[i]=A[j];
      A[j]=c;
    }
  }
    b=A[i+1];
    A[i+1]=A[n-1];
    A[n-1]=b;
    return i+1;
}
int main(){
  int i,z;

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



