#include<stdio.h>

#define N 100000

int n ;
int a[N];

int pt(int a[],int b, int c){

  int x=0,j,i,d;

  x = a[c];
  i = b-1;

  for(j=b; j<c; j++){
    if(a[j] <= x){
      i++;
      d = a[i];
      a[i] = a[j];
      a[j] = d;
    }
  }
  d = a[i+1];
  a[i+1] = a[c];
  a[c] = d;

  return i+1;
}

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

  e =  pt(a,0,n-1);

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

  printf("\n");

  return 0;
}