#include <stdio.h>

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

int main(){
  int n,A[100000],i,ans;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
      scanf("%d",&A[i]);
    }
    ans=partition(A,1,n);
    for(i=1;i<=n;i++){
      if(i==ans){
	printf("[%d] ",A[i]);
      }
      else if(i==n){
	printf("%d\n",A[i]);
      }
      else {
	printf("%d ",A[i]);
      }
    }
    return 0;
}

