#include <stdio.h>

#define A 100000

int p(int,int);

int S[A],n;

int main(){
  int i,m;

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

  m = p(0,n-1);

  for(i=0;i<n;i++){
    if(i)printf(" ");
    
    if(i == m)printf("[");
    
    printf("%d",S[i]);

    if(i == m)printf("]");
  }
  printf("\n");
  return 0;
}

int p(int x,int y){
  int a,b,c,i;

  a = S[y];
  b = x-1;

  for(i=x;i<y;i++){
    if(S[i]<=a){
      b++;
      c = S[b];
      S[b] = S[i];
      S[i] = c;
    }
  }

    c = S[b+1];
    S[b+1] = S[y];
    S[y] = c;

    return b+1;
}

