#include<stdio.h>
#define MAX 100000

int partition(int a[],int n,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 a[MAX],n,i,q;

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%d",&a[i]);
  }

  q = partition(a,n,0,n - 1);

  for(i = 0;i < n;i++){
    if(i > 0) printf(" ");
    if(i == q) printf("[");
    printf("%d",a[i]);
    if(i == q) printf("]");
  }

  printf("\n");
  
  return 0;
}

