#include<stdio.h>
#include<stdlib.h>


#define MAX 100000

int X[MAX],x;


int par(int s,int t){
  int i,j,u,y;
  y = X[t];
  i = s-1;
  for(j = s;j<t;j++){
    if(X[j]<=y){
      i++;
      u = X[i];
      X[i] = X[j];
      X[j] = u;
    }
  }
  u = X[i+1];
  X[i+1] = X[t];
  X[t] = u;
  return i+1;
}






int main(){
  int i,p;

  scanf("%d",&x);
  for(i = 0;i<x;i++) scanf("%d",&X[i]);

  p = par(0,x-1);

  for(i = 0;i<x;i++){
    if(i)
      printf(" ");
    if( i==p)
      printf("[");
    printf("%d",X[i]);
    if(i == p)
      printf("]");
  }
  printf("\n");
  

  return 0;
}

