#include <stdio.h>

int prtition(int *,int,int);

int main(){
  int i,n,A[100000],B[100000],j;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[n]);

  for(i=0;i<n;i++){
    j = partition(A,i,n);
    B[i] = A[j];
  }
  for(i=0;i<n;i++){
    printf("%d",B[i]);
    if(i<n-1) printf(" ");
    else printf("\n");
  }

  return 0;
}

int partition(int *A,int p, int r){
  int x,y,z,i,j,q;
  x = A[r];
  i = p-1;
  for(j=p;j<r;j++){
    if(A[j] <= x){
      i++;
      y = A[i];
      A[i] = A[j];
      A[j] = y;
    }
    z = A[i+1];
    A[i+1] = A[r];
    A[r] = z;
  }
  return i+1;
}
