#include<stdio.h>
#define M 100000

int f[M];

int partition_s(int f[],int g,int h){
  int x,y,z,s;
  x=f[h];
  y=g-1;
  for(z=g;z<h;z++){
    if(f[z]<=x){
      y++;
      s=f[y];
      f[y]=f[z];
      f[z]=s;
    }
  }
  s=f[y+1];
  f[y+1]=f[h];
  f[h]=s;
  return y+1;
}


int main()
{
  int i,lo,re;

  scanf("%d",&lo);

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

  re=partition_s(f,0,lo-1);
  for(i=0;i<lo;i++){
    if(i>0) printf(" ");
    if(i==re) printf("[");
    printf("%d",f[i]);
    if(i==re) printf("]");
  }
  printf("\n");

  return 0;
}

  

