#include<stdio.h>

int N;
int num;
int a[100000];


int partition(int *A,int p,int r){
    int i,j,tmp,x;
    
    x=A[r];
    i=p-1;
    
    for(j=p;j<r;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;
    
}

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