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

int partition(int A,int p,int r){
  int x;
  
  