#include <stdio.h>
#include <stdlib.h>
int partititon(int [],int,int);
int main() {

  int i,j;
  int *A;
  int b;
  int p,r;
  int n;

  scanf("%d",&n);

  A=malloc(sizeof(int)*n+1);

  for(i=0;i<n;i++){
    scanf("%d",&A[i+1]);
  }
  p=1;
  r=n;
  b=partition(A,p,r);

  for(i=0;i<n;i++){
    if((i+1)==b){
      printf("[%d]",A[i+1]);
      continue;
    }
    printf("%d",A[i+1]);
    if(i==n) break;
    printf(" ");
  }


  printf("\n");

  return 0;
}
int partition(int A[],int p, int r) {

  int x;
  int i,j,a;
  int b;

  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x) {
      i++;
      a=A[i];
      A[i]=A[j];
      A[j]=a;
    }
  }
  b=A[i+1];
  A[i+1]=A[r];
  A[r]=b;
  return i+1;
}
  
 