#include<stdio.h>
#define MAX 100000
int hairetu[MAX],a;
int partition(int,int);
int main(){
    int i,q;
    scanf("%d",&a);
    for(i=0;i<a;i++){
      scanf("%d",&hairetu[i]);
    }
    q=partition(0,a-1);
    for(i=0;i<a;i++){
      if(i==q)printf("[");
      if(i)printf(" ");
      printf("%d",hairetu[i]);
      if(i==q)printf("]");
    }
    printf("\n");
    return 0;
  }
int partition(int p,int r){
  int b,i,j,c;
  b=hairetu[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(hairetu[j]<=b){
      i++;
      c=hairetu[i];
      hairetu[i]=hairetu[j];
      hairetu[j]=c;
    }
  }
  c=hairetu[i+1];
  hairetu[i+1]=hairetu[r];
  hairetu[r]=c;
  return i+1;
}