#include<stdio.h>

int n;

void partition(int *,int ,int);

int main(){

  int i,a[100000];


  scanf("%d",&n);

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

  partition(a,0,n-1);

  return 0;
}



void partition(int a[],int p,int r){

  int x,y,i,b;

  x = a[r];
  y = p-1;

  for(i = 0; i < r; i++){
    if(a[i] <= x){
      y += 1;
      b = a[y];
      a[y] = a[i];
      a[i] = b;
    }
  }


  for(i = 0; i < y+1; i++){
    printf("%d ",a[i]);
  }

  b = a[y+1];
  a[y+1] = a[r];
  a[r] = b;

  printf("[%d] ",a[y+1]);

  for(i = y+2 ; i < n; i++){
    if(i == n-1){
      printf("%d\n",a[i]);
      break;
    }
	     
    printf("%d ",a[i]);
  }
    
}

