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

  return 0;
}

