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

#define N 10000

int n;

void Partiton(unsigned short* ,int ,int);

int main(){

  unsigned short *A, *B;

  int k=0;
  int i;

  scanf("%d",&n);

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

  for(i=0;i<n;i++)
    scanf("%hu",&A[i+1]);

  Partition(A,1,n);

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

  printf("\n");

  return 0;

}

void Partition(unsigned short *A, int p, int r){

  int x,i,tmp;
  
  x = A[r];
  i = p-1;

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

    tmp = A[i+1];
    A[i+1] =  A[r];
    A[r] = tmp;

    return i+1;

}